diff --git a/src/abstract/montgomery.ts b/src/abstract/montgomery.ts index 69a6c8e..e8abc00 100644 --- a/src/abstract/montgomery.ts +++ b/src/abstract/montgomery.ts @@ -150,7 +150,8 @@ export function montgomery(curveDef: CurveType): CurveFn { // This is very ugly way, but it works because fieldLen-1 is outside of bounds for X448, so this becomes NOOP // fieldLen - scalaryBytes = 1 for X448 and = 0 for X25519 const u = ensureBytes(uEnc, montgomeryBytes); - u[fieldLen - 1] &= 127; // 0b0111_1111 + // u[fieldLen-1] crashes QuickJS (TypeError: out-of-bound numeric index) + if (fieldLen === montgomeryBytes) u[fieldLen - 1] &= 127; // 0b0111_1111 return bytesToNumberLE(u); } function decodeScalar(n: Hex): bigint {