@@ -354,11 +354,6 @@ CMP_VEC_AND_PTR(vec, pkey->pkey.pqdsa_key->public_key, len)
354
354
#define CMP_VEC_AND_PKEY_SECRET (vec, pkey, len ) \
355
355
CMP_VEC_AND_PTR (vec, pkey->pkey.pqdsa_key->private_key, len)
356
356
357
- // The PQDSAParameterTest performs testing on each of the named algorithms
358
- // in the list PQDSA_types. This name must exactly match the name provided in
359
- // PQDSATestVector.name for the test vector to run.
360
- std::vector<std::string> PQDSA_types{" MLDSA65" };
361
-
362
357
static const struct PQDSATestVector parameterSet[] = {
363
358
{" MLDSA65" , NID_MLDSA65, 1952 , 4032 , 3309 , " dilithium/kat/MLDSA_65_hedged_pure.txt" , mldsa65kPublicKey, mldsa65kPublicKeySPKI, 1974 },
364
359
};
@@ -369,81 +364,75 @@ INSTANTIATE_TEST_SUITE_P(All, PQDSAParameterTest, testing::ValuesIn(parameterSet
369
364
[](const testing::TestParamInfo<PQDSATestVector> ¶ms)
370
365
-> std::string { return params.param .name ; });
371
366
372
-
373
367
TEST_P (PQDSAParameterTest, KAT) {
374
368
std::string kat_filepath = " crypto/" ;
375
369
kat_filepath += GetParam ().kat_filename ;
376
370
377
- // Only peform the KAT if the parameter name matches one in PQDSA_types
378
- std::string name = GetParam ().name ;
379
- if (std::find (std::begin (PQDSA_types), std::end (PQDSA_types), name)
380
- != std::end (PQDSA_types)) {
381
-
382
- FileTestGTest (kat_filepath.c_str (), [&](FileTest *t) {
383
- std::string count, mlen, smlen;
384
- std::vector<uint8_t > xi, rng, seed, msg, pk, sk, sm, ctxstr;
385
-
386
- ASSERT_TRUE (t->GetAttribute (&count, " count" ));
387
- ASSERT_TRUE (t->GetBytes (&xi, " xi" ));
388
- ASSERT_TRUE (t->GetBytes (&rng, " rng" ));
389
- ASSERT_TRUE (t->GetBytes (&seed, " seed" ));
390
- ASSERT_TRUE (t->GetBytes (&pk, " pk" ));
391
- ASSERT_TRUE (t->GetBytes (&sk, " sk" ));
392
- ASSERT_TRUE (t->GetBytes (&msg, " msg" ));
393
- ASSERT_TRUE (t->GetAttribute (&mlen, " mlen" ));
394
- ASSERT_TRUE (t->GetBytes (&sm, " sm" ));
395
- ASSERT_TRUE (t->GetAttribute (&smlen, " smlen" ));
396
- ASSERT_TRUE (t->GetBytes (&ctxstr, " ctx" ));
397
-
398
- size_t pk_len = GetParam ().public_key_len ;
399
- size_t sk_len = GetParam ().private_key_len ;
400
- size_t sig_len = GetParam ().signature_len ;
401
-
402
- std::vector<uint8_t > pub (pk_len);
403
- std::vector<uint8_t > priv (sk_len);
404
- std::vector<uint8_t > signature (sig_len);
405
-
406
- size_t mlen_int = std::stoi (mlen);
407
-
408
- // The KATs provide the signed message, which is the signature appended with
409
- // the message that was signed. We use the ML-DSA APIs for sign_signature
410
- // and not sign_message, which return the signature without the appended
411
- // message, so we truncate the signed messaged to |sig_len|.
412
- sm.resize (sig_len);
413
-
414
- // Generate key pair from seed xi and assert that public and private keys
415
- // are equal to expected values from KAT
416
- if (name == " MLDSA65" ) {
417
- ASSERT_TRUE (ml_dsa_65_keypair_internal (pub.data (), priv.data (), xi.data ()));
418
- }
419
- EXPECT_EQ (Bytes (pub), Bytes (pk));
420
- EXPECT_EQ (Bytes (priv), Bytes (sk));
421
-
422
- // Prepare m_prime = (0 || ctxlen || ctx)
423
- // See both FIPS 204: Algorithm 2 line 10 and FIPS 205: Algorithm 22 line 8
424
- uint8_t m_prime[257 ];
425
- size_t m_prime_len = ctxstr.size () + 2 ;
426
- m_prime[0 ] = 0 ;
427
- m_prime[1 ] = ctxstr.size ();
428
- ASSERT_TRUE (ctxstr.size () <= 255 );
429
- OPENSSL_memcpy (m_prime + 2 , ctxstr.data (), ctxstr.size ());
430
-
431
- // Generate signature by signing |msg|, assert that signature is equal
432
- // to expected value from KAT, then verify signature.
433
- if (name == " MLDSA65" ) {
434
- ASSERT_TRUE (ml_dsa_65_sign_internal (priv.data (),
435
- signature.data (), &sig_len,
371
+ FileTestGTest (kat_filepath.c_str (), [&](FileTest *t) {
372
+ std::string count, mlen, smlen;
373
+ std::vector<uint8_t > xi, rng, seed, msg, pk, sk, sm, ctxstr;
374
+
375
+ ASSERT_TRUE (t->GetAttribute (&count, " count" ));
376
+ ASSERT_TRUE (t->GetBytes (&xi, " xi" ));
377
+ ASSERT_TRUE (t->GetBytes (&rng, " rng" ));
378
+ ASSERT_TRUE (t->GetBytes (&seed, " seed" ));
379
+ ASSERT_TRUE (t->GetBytes (&pk, " pk" ));
380
+ ASSERT_TRUE (t->GetBytes (&sk, " sk" ));
381
+ ASSERT_TRUE (t->GetBytes (&msg, " msg" ));
382
+ ASSERT_TRUE (t->GetAttribute (&mlen, " mlen" ));
383
+ ASSERT_TRUE (t->GetBytes (&sm, " sm" ));
384
+ ASSERT_TRUE (t->GetAttribute (&smlen, " smlen" ));
385
+ ASSERT_TRUE (t->GetBytes (&ctxstr, " ctx" ));
386
+
387
+ size_t pk_len = GetParam ().public_key_len ;
388
+ size_t sk_len = GetParam ().private_key_len ;
389
+ size_t sig_len = GetParam ().signature_len ;
390
+
391
+ std::vector<uint8_t > pub (pk_len);
392
+ std::vector<uint8_t > priv (sk_len);
393
+ std::vector<uint8_t > signature (sig_len);
394
+
395
+ std::string name = GetParam ().name ;
396
+ size_t mlen_int = std::stoi (mlen);
397
+
398
+ // The KATs provide the signed message, which is the signature appended with
399
+ // the message that was signed. We use the ML-DSA APIs for sign_signature
400
+ // and not sign_message, which return the signature without the appended
401
+ // message, so we truncate the signed messaged to |sig_len|.
402
+ sm.resize (sig_len);
403
+
404
+ // Generate key pair from seed xi and assert that public and private keys
405
+ // are equal to expected values from KAT
406
+ if (name == " MLDSA65" ) {
407
+ ASSERT_TRUE (ml_dsa_65_keypair_internal (pub.data (), priv.data (), xi.data ()));
408
+ }
409
+ EXPECT_EQ (Bytes (pub), Bytes (pk));
410
+ EXPECT_EQ (Bytes (priv), Bytes (sk));
411
+
412
+ // Prepare m_prime = (0 || ctxlen || ctx)
413
+ // See both FIPS 204: Algorithm 2 line 10 and FIPS 205: Algorithm 22 line 8
414
+ uint8_t m_prime[257 ];
415
+ size_t m_prime_len = ctxstr.size () + 2 ;
416
+ m_prime[0 ] = 0 ;
417
+ m_prime[1 ] = ctxstr.size ();
418
+ ASSERT_TRUE (ctxstr.size () <= 255 );
419
+ OPENSSL_memcpy (m_prime + 2 , ctxstr.data (), ctxstr.size ());
420
+
421
+ // Generate signature by signing |msg|, assert that signature is equal
422
+ // to expected value from KAT, then verify signature.
423
+ if (name == " MLDSA65" ) {
424
+ ASSERT_TRUE (ml_dsa_65_sign_internal (priv.data (),
425
+ signature.data (), &sig_len,
426
+ msg.data (), mlen_int,
427
+ m_prime, m_prime_len,
428
+ rng.data ()));
429
+ ASSERT_EQ (Bytes (signature), Bytes (sm));
430
+ ASSERT_TRUE (ml_dsa_65_verify_internal (pub.data (),
431
+ signature.data (), sig_len,
436
432
msg.data (), mlen_int,
437
- m_prime, m_prime_len,
438
- rng.data ()));
439
- ASSERT_EQ (Bytes (signature), Bytes (sm));
440
- ASSERT_TRUE (ml_dsa_65_verify_internal (pub.data (),
441
- signature.data (), sig_len,
442
- msg.data (), mlen_int,
443
- m_prime, m_prime_len));
444
- }
445
- });
446
- }
433
+ m_prime, m_prime_len));
434
+ }
435
+ });
447
436
}
448
437
449
438
TEST_P (PQDSAParameterTest, KeyGen) {
0 commit comments