Skip to content

Commit 958aae3

Browse files
committed
Formatting
1 parent 437a581 commit 958aae3

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,9 @@ const etc2 = {
560560
randomBytes: randomBytes,
561561
};
562562
const randomPrivateKey = () => {
563-
const num = M(bytesToNum(randomBytes(L + L / 2)), N - _1); // takes n+8 bytes
563+
const num = M(bytesToNum(randomBytes(L + L / 2)), N - _1); // takes n+16 bytes
564564
return numTo32b(num + _1); // returns (hash mod n-1)+1
565-
}; // FIPS 186 B.4.1.
565+
};
566566
/** Curve-specific utilities for private keys. */
567567
const utils = {
568568
isValidPrivateKey: (key) => {
@@ -574,7 +574,6 @@ const utils = {
574574
}
575575
},
576576
randomPrivateKey: randomPrivateKey,
577-
// precompute: (w=8, p: Point = G): Point => { p.multiply(3n); w; return p; }, // no-op
578577
};
579578
const W = 8; // Precomputes-related code. W = window size
580579
const scalarBits = 256;

index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,16 @@ const verify = (sig: Bytes | Signature, msgh: Bytes, pub: Bytes, opts: OptV = op
448448
if (lowS == null) lowS = true; // Default lowS=true
449449
if (sig instanceof Signature) sig = new Signature(sig.r, sig.s).toBytes();
450450
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
455455
const { r, s } = sigg;
456456
if (lowS && highS(s)) return false; // lowS bans sig.s >= CURVE.n/2
457457
const is = invert(s, N); // s^-1
458458
const u1 = modN(h * is); // u1 = hs^-1 mod n
459459
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
461461
if (!R) return false; // stop if R is identity / zero point
462462
const v = modN(R.x); // R.x must be in N's field, not P's
463463
return v === r; // mod(R.x, n) == r
@@ -513,17 +513,16 @@ const etc2 = {
513513
invert: invert as (num: bigint, md?: bigint) => bigint, // math utilities
514514
randomBytes: randomBytes as (len?: number) => Bytes,
515515
}
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+
};
520520
/** Curve-specific utilities for private keys. */
521521
const utils = { // utilities
522522
isValidPrivateKey: (key: Bytes): boolean => {
523523
try { return !!toPrivScalar(key); } catch (e) { return false; }
524524
},
525525
randomPrivateKey: randomPrivateKey as () => Bytes,
526-
// precompute: (w=8, p: Point = G): Point => { p.multiply(3n); w; return p; }, // no-op
527526
};
528527
const W = 8; // Precomputes-related code. W = window size
529528
const scalarBits = 256;

0 commit comments

Comments
 (0)