From e93caf9567fd5275463878d044f182d52c630109 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Tue, 27 Feb 2024 22:24:56 +0000 Subject: [PATCH] weierstrass: improve Entropy type. Use new utility. --- src/abstract/weierstrass.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/abstract/weierstrass.ts b/src/abstract/weierstrass.ts index ecf5d97..28e99b3 100644 --- a/src/abstract/weierstrass.ts +++ b/src/abstract/weierstrass.ts @@ -27,7 +27,7 @@ export type BasicWCurve = BasicCurve & { clearCofactor?: (c: ProjConstructor, point: ProjPointType) => ProjPointType; }; -type Entropy = Hex | true; +type Entropy = Hex | boolean; export type SignOpts = { lowS?: boolean; extraEntropy?: Entropy; prehash?: boolean }; export type VerOpts = { lowS?: boolean; prehash?: boolean }; @@ -158,7 +158,7 @@ export const DER = { // parse DER signature const { Err: E } = DER; const data = typeof hex === 'string' ? h2b(hex) : hex; - if (!ut.isBytes(data)) throw new Error('ui8a expected'); + ut.abytes(data); let l = data.length; if (l < 2 || data[0] != 0x30) throw new E('Invalid signature tag'); if (data[1] !== l - 2) throw new E('Invalid signature: incorrect length'); @@ -977,7 +977,7 @@ export function weierstrass(curveDef: CurveType): CurveFn { const d = normPrivateKeyToScalar(privateKey); // validate private key, convert to bigint const seedArgs = [int2octets(d), int2octets(h1int)]; // extraEntropy. RFC6979 3.6: additional k' (optional). - if (ent != null) { + if (ent != null && ent !== false) { // K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1) || k') const e = ent === true ? randomBytes(Fp.BYTES) : ent; // generate random bytes OR pass as-is seedArgs.push(ensureBytes('extraEntropy', e)); // check for being bytes