forked from tornado-packages/noble-curves
montgomery: fix fieldLen
This commit is contained in:
parent
3374a70f47
commit
4780850748
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user