From cae888d942f1042473e2713a2ef77834b11b12ea Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Wed, 28 Dec 2022 05:30:13 +0000 Subject: [PATCH] P224: fix sha224 tests --- curve-definitions/src/p224.ts | 4 ++-- curve-definitions/test/nist.test.js | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/curve-definitions/src/p224.ts b/curve-definitions/src/p224.ts index 072ec38..4eebcc1 100644 --- a/curve-definitions/src/p224.ts +++ b/curve-definitions/src/p224.ts @@ -1,6 +1,6 @@ /*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { createCurve } from './_shortw_utils.js'; -import { sha256 } from '@noble/hashes/sha256'; +import { sha224 } from '@noble/hashes/sha256'; import { Fp } from '@noble/curves/modular'; // NIST secp224r1 aka P224 @@ -20,6 +20,6 @@ export const P224 = createCurve( h: BigInt(1), lowS: false, } as const, - sha256 // TODO: replace with sha224 when new @noble/hashes released + sha224 ); export const secp224r1 = P224; diff --git a/curve-definitions/test/nist.test.js b/curve-definitions/test/nist.test.js index 95e5ef9..88dc2ed 100644 --- a/curve-definitions/test/nist.test.js +++ b/curve-definitions/test/nist.test.js @@ -41,10 +41,11 @@ should('wychenproof ECDSA vectors', () => { for (const group of ecdsa.testGroups) { // Tested in secp256k1.test.js if (group.key.curve === 'secp256k1') continue; - // We don't have SHA-224 - if (group.key.curve === 'secp224r1' && group.sha === 'SHA-224') continue; - const CURVE = NIST[group.key.curve]; + let CURVE = NIST[group.key.curve]; if (!CURVE) continue; + if (group.key.curve === 'secp224r1' && group.sha !== 'SHA-224') { + if (group.sha === 'SHA-256') CURVE = CURVE.create(sha256); + } const pubKey = CURVE.Point.fromHex(group.key.uncompressed); deepStrictEqual(pubKey.x, BigInt(`0x${group.key.wx}`)); deepStrictEqual(pubKey.y, BigInt(`0x${group.key.wy}`)); @@ -196,17 +197,16 @@ import { default as secp521r1_sha512_test } from './wycheproof/ecdsa_secp521r1_s import { sha3_224, sha3_256, sha3_384, sha3_512 } from '@noble/hashes/sha3'; import { sha512, sha384 } from '@noble/hashes/sha512'; -import { sha256 } from '@noble/hashes/sha256'; +import { sha224, sha256 } from '@noble/hashes/sha256'; const WYCHEPROOF_ECDSA = { P224: { curve: P224, hashes: { - // sha224 not released yet - // sha224: { - // hash: sha224, - // tests: [secp224r1_sha224_test], - // }, + sha224: { + hash: sha224, + tests: [secp224r1_sha224_test], + }, sha256: { hash: sha256, tests: [secp224r1_sha256_test],