@@ -448,16 +448,16 @@ const verify = (sig: Bytes | Signature, msgh: Bytes, pub: Bytes, opts: OptV = op
448
448
if ( lowS == null ) lowS = true ; // Default lowS=true
449
449
if ( sig instanceof Signature ) sig = new Signature ( sig . r , sig . s ) . toBytes ( ) ;
450
450
abytes ( sig , L2 ) ; abytes ( msgh ) ; abytes ( pub ) ; // Validate options, throw
451
- try { // Actual verification code begins here
452
- const sigg = Signature . fromBytes ( sig ) ; // throw error when DER is suspected now.
453
- const h = bits2int_modN ( msgh ) ; // Truncate hash
454
- const P = Point . fromBytes ( pub ) ; // Validate public key
451
+ try {
452
+ const sigg = Signature . fromBytes ( sig ) ; // throw error when DER is suspected now.
453
+ const h = bits2int_modN ( msgh ) ; // Truncate hash
454
+ const P = Point . fromBytes ( pub ) ; // Validate public key
455
455
const { r, s } = sigg ;
456
456
if ( lowS && highS ( s ) ) return false ; // lowS bans sig.s >= CURVE.n/2
457
457
const is = invert ( s , N ) ; // s^-1
458
458
const u1 = modN ( h * is ) ; // u1 = hs^-1 mod n
459
459
const u2 = modN ( r * is ) ; // u2 = rs^-1 mod n
460
- const R = mulG2uns ( P , u1 , u2 ) . aff ( ) ; // R = u1⋅G + u2⋅P
460
+ const R = mulG2uns ( P , u1 , u2 ) . aff ( ) ; // R = u1⋅G + u2⋅P
461
461
if ( ! R ) return false ; // stop if R is identity / zero point
462
462
const v = modN ( R . x ) ; // R.x must be in N's field, not P's
463
463
return v === r ; // mod(R.x, n) == r
@@ -513,17 +513,16 @@ const etc2 = {
513
513
invert : invert as ( num : bigint , md ?: bigint ) => bigint , // math utilities
514
514
randomBytes : randomBytes as ( len ?: number ) => Bytes ,
515
515
}
516
- const randomPrivateKey = ( ) : Bytes => {
517
- const num = M ( bytesToNum ( randomBytes ( L + L / 2 ) ) , N - _1 ) ; // takes n+8 bytes
518
- return numTo32b ( num + _1 ) ; // returns (hash mod n-1)+1
519
- } ; // FIPS 186 B.4.1.
516
+ const randomPrivateKey = ( ) : Bytes => { // FIPS 186 B.4.1.
517
+ const num = M ( bytesToNum ( randomBytes ( L + L / 2 ) ) , N - _1 ) ; // takes 48 bytes
518
+ return numTo32b ( num + _1 ) ; // returns (hash mod n-1)+1
519
+ } ;
520
520
/** Curve-specific utilities for private keys. */
521
521
const utils = { // utilities
522
522
isValidPrivateKey : ( key : Bytes ) : boolean => {
523
523
try { return ! ! toPrivScalar ( key ) ; } catch ( e ) { return false ; }
524
524
} ,
525
525
randomPrivateKey : randomPrivateKey as ( ) => Bytes ,
526
- // precompute: (w=8, p: Point = G): Point => { p.multiply(3n); w; return p; }, // no-op
527
526
} ;
528
527
const W = 8 ; // Precomputes-related code. W = window size
529
528
const scalarBits = 256 ;
0 commit comments