From 52d5899c547b119afe4b3b1d1e0a6d48ce4dd556 Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Fri, 18 Nov 2022 12:21:38 +0000 Subject: [PATCH] crypto_core fixes --- crypto_core.js | 14 ++++++-------- index.js | 9 +-------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/crypto_core.js b/crypto_core.js index db65b59..d69911c 100644 --- a/crypto_core.js +++ b/crypto_core.js @@ -39,9 +39,9 @@ function crypto_core_ed25519_is_valid_point (p) { ge25519_frombytes(p_p3, p) != 0 || ge25519_is_on_curve(p_p3) == 0 || ge25519_is_on_main_subgroup(p_p3) == 0) { - return 0; + return false; } - return 1; + return true; } function crypto_core_ed25519_add (r, p, q) { @@ -151,9 +151,7 @@ function crypto_core_ed25519_scalar_random (r) { } function crypto_core_ed25519_scalar_invert (recip, s) { - console.log(s) sc25519_invert(recip, s) - console.log(recip) if (sodium_is_zero(s, crypto_core_ed25519_SCALARBYTES)) { throw new Error('Zero point') @@ -177,10 +175,10 @@ function crypto_core_ed25519_scalar_negate (neg, s) { t_.fill(0) s_.fill(0) - t_.set(L.subarray(crypto_core_ed25519_SCALARBYTES, crypto_core_ed25519_SCALARBYTES)) + t_.set(L.subarray(0, crypto_core_ed25519_SCALARBYTES), crypto_core_ed25519_SCALARBYTES) s_.set(s.subarray(0, crypto_core_ed25519_SCALARBYTES)) - sodium_sub(t_, s_, crypto_core_ed25519_SCALARBYTES) + sodium_sub(t_, s_, crypto_core_ed25519_NONREDUCEDSCALARBYTES) sc25519_reduce(t_) neg.set(t_.subarray(0 , crypto_core_ed25519_SCALARBYTES)) @@ -197,10 +195,10 @@ function crypto_core_ed25519_scalar_complement (comp, s) { s_.fill(0) t_[0]++; - t_.set(L.subarray(crypto_core_ed25519_SCALARBYTES, crypto_core_ed25519_SCALARBYTES)) + t_.set(L.subarray(0, crypto_core_ed25519_SCALARBYTES), crypto_core_ed25519_SCALARBYTES) s_.set(s.subarray(0, crypto_core_ed25519_SCALARBYTES)) - sodium_sub(t_, s_, crypto_core_ed25519_SCALARBYTES) + sodium_sub(t_, s_, crypto_core_ed25519_NONREDUCEDSCALARBYTES) sc25519_reduce(t_) comp.set(t_.subarray(0, crypto_core_ed25519_SCALARBYTES)) diff --git a/index.js b/index.js index e0c7684..32be955 100644 --- a/index.js +++ b/index.js @@ -12,15 +12,8 @@ var sodium = module.exports // also forwarded at the bottom but randombytes is non-enumerable -sodium.sodium_memzero = function (arr) { - arr.fill(0) -} - -sodium.sodium_malloc = function (n) { - return new Uint8Array(n) -} - forward(require('./crypto_box')) +forward(require('./crypto_core')) forward(require('./crypto_generichash')) forward(require('./crypto_hash')) forward(require('./crypto_hash_sha256'))