From 37c8f2db79aca75a1b5fcae933adae550b54e0bd Mon Sep 17 00:00:00 2001 From: Christophe Diederichs Date: Fri, 18 Nov 2022 08:57:55 +0000 Subject: [PATCH] fix scalarmult exports --- crypto_scalarmult_ed25519.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crypto_scalarmult_ed25519.js b/crypto_scalarmult_ed25519.js index 6bad368..9d8ae85 100644 --- a/crypto_scalarmult_ed25519.js +++ b/crypto_scalarmult_ed25519.js @@ -1,14 +1,20 @@ const assert = require('nanoassert') const ec = require('./fe25519_25') +const crypto_scalarmult_ed25519_BYTES = 32 +const crypto_scalarmult_ed25519_SCALARBYTES = 32 + module.exports = { crypto_scalarmult_ed25519, crypto_scalarmult_ed25519_base, + crypto_scalarmult_ed25519_base_noclamp, crypto_scalarmult_curve25519, crypto_scalarmult_curve25519_1, crypto_scalarmult_curve25519_base, crypto_scalarmult_ristretto255, - crypto_scalarmult_ristretto255_base + crypto_scalarmult_ristretto255_base, + crypto_scalarmult_ed25519_BYTES, + crypto_scalarmult_ed25519_SCALARBYTES } const _121666buf = Buffer.alloc(32) @@ -42,22 +48,27 @@ function _crypto_scalarmult_ed25519 (q, n, p, clamp) { var i // if (ec.ge25519_is_canonical(p) == 0 || ec.ge25519_has_small_order(p) != 0 || - if ( ec.ge25519_frombytes(P, p) != 0 || ec.ge25519_is_on_main_subgroup(P) == 0) { - return -1 + if (ec.ge25519_frombytes(P, p) != 0 || ec.ge25519_is_on_main_subgroup(P) == 0) { + throw new Error('Invalid base point') } + for (i = 0; i < 32; ++i) { t[i] = n[i] } + if (clamp !== 0) { _crypto_scalarmult_ed25519_clamp(t) } + t[31] &= 127 ec.ge25519_scalarmult(Q, t, P) ec.ge25519_p3_tobytes(q, Q) + if (_crypto_scalarmult_ed25519_is_inf(q) != 0 || sodium_is_zero(n, 32)) { - return -1 + throw new Error('Point multiplication failed') } + return 0 }