@@ -24338,7 +24338,7 @@ static int test_wc_MakeCRL_max_crlnum(void)
2433824338 }
2433924339 if (EXPECT_SUCCESS()) {
2434024340 crlSz = wc_SignCRL_ex(tbsBuf, tbsSz, CTC_SHA256wRSA,
24341- crlBuf, (word32)bufSz, &rsaKey, NULL, NULL , NULL, &rng );
24341+ crlBuf, (word32)bufSz, &rsaKey, NULL, &rng , NULL, NULL );
2434224342 ExpectIntGT(crlSz, 0);
2434324343 }
2434424344
@@ -24347,7 +24347,7 @@ static int test_wc_MakeCRL_max_crlnum(void)
2434724347 * paired with an ECDSA OID must return ALGO_ID_E. --- */
2434824348 if (EXPECT_SUCCESS()) {
2434924349 ExpectIntEQ(wc_SignCRL_ex(tbsBuf, tbsSz, CTC_SHA256wECDSA,
24350- crlBuf, (word32)bufSz, &rsaKey, NULL, NULL , NULL, &rng ),
24350+ crlBuf, (word32)bufSz, &rsaKey, NULL, &rng , NULL, NULL ),
2435124351 WC_NO_ERR_TRACE(ALGO_ID_E));
2435224352 }
2435324353
@@ -24430,13 +24430,14 @@ static int pqc_crl_sign_verify(const byte* caCertDer, word32 caCertDerSz,
2443024430 int caCertInit = 0;
2443124431 WC_RNG rng;
2443224432 int rngInit = 0;
24433- byte issuerDer[1024] ;
24433+ byte* issuerDer = NULL ;
2443424434 word32 issuerDerSz = 0;
2443524435 byte* tbsBuf = NULL;
2443624436 byte* crlBuf = NULL;
2443724437 int tbsSz = 0;
2443824438 int crlSz = 0;
2443924439 int bufSz = 0;
24440+ int sigSz = 0;
2444024441
2444124442 /* thisUpdate in the past, nextUpdate far in the future so the CRL is
2444224443 * current whenever the test runs. */
@@ -24451,15 +24452,16 @@ static int pqc_crl_sign_verify(const byte* caCertDer, word32 caCertDerSz,
2445124452 wc_InitDecodedCert(&caCert, caCertDer, caCertDerSz, NULL);
2445224453 caCertInit = 1;
2445324454 ExpectIntEQ(wc_ParseCert(&caCert, CERT_TYPE, 0, NULL), 0);
24455+ if (EXPECT_SUCCESS()) {
24456+ ExpectNotNull(issuerDer = (byte*)XMALLOC(
24457+ (size_t)caCert.subjectRawLen + MAX_SEQ_SZ, NULL,
24458+ DYNAMIC_TYPE_TMP_BUFFER));
24459+ }
2445424460 if (EXPECT_SUCCESS()) {
2445524461 word32 seqHdrSz = SetSequence((word32)caCert.subjectRawLen, issuerDer);
24456- ExpectIntLE((int)(seqHdrSz + (word32)caCert.subjectRawLen),
24457- (int)sizeof(issuerDer));
24458- if (EXPECT_SUCCESS()) {
24459- XMEMCPY(issuerDer + seqHdrSz, caCert.subjectRaw,
24460- (size_t)caCert.subjectRawLen);
24461- issuerDerSz = seqHdrSz + (word32)caCert.subjectRawLen;
24462- }
24462+ XMEMCPY(issuerDer + seqHdrSz, caCert.subjectRaw,
24463+ (size_t)caCert.subjectRawLen);
24464+ issuerDerSz = seqHdrSz + (word32)caCert.subjectRawLen;
2446324465 }
2446424466
2446524467 ExpectIntEQ(wc_InitRng(&rng), 0);
@@ -24473,10 +24475,25 @@ static int pqc_crl_sign_verify(const byte* caCertDer, word32 caCertDerSz,
2447324475 NULL, crlNum, (word32)sizeof(crlNum), sigType, 2, NULL, 0);
2447424476 ExpectIntGT(tbsSz, 0);
2447524477 }
24478+ /* Size the output from the key's actual signature length (PQC signatures
24479+ * range from a few KB for ML-DSA to tens of KB for large SLH-DSA sets)
24480+ * plus headroom for the AlgorithmIdentifier, BIT STRING and SEQUENCE
24481+ * wrappers, rather than a fixed magic number. */
24482+ #ifdef WOLFSSL_HAVE_MLDSA
24483+ if (mldsaKey != NULL) {
24484+ int l = 0;
24485+ ExpectIntEQ(wc_MlDsaKey_GetSigLen(mldsaKey, &l), 0);
24486+ sigSz = l;
24487+ }
24488+ #endif
24489+ #ifdef WOLFSSL_HAVE_SLHDSA
24490+ if (slhDsaKey != NULL) {
24491+ sigSz = wc_SlhDsaKey_SigSize(slhDsaKey);
24492+ }
24493+ #endif
24494+ ExpectIntGT(sigSz, 0);
2447624495 if (EXPECT_SUCCESS()) {
24477- /* Generous room for the (large) PQC signature and ASN.1 wrappers;
24478- * SLH-DSA signatures alone are several KB. */
24479- bufSz = tbsSz + 32768;
24496+ bufSz = tbsSz + sigSz + 512;
2448024497 ExpectNotNull(tbsBuf = (byte*)XMALLOC(bufSz, NULL,
2448124498 DYNAMIC_TYPE_TMP_BUFFER));
2448224499 ExpectNotNull(crlBuf = (byte*)XMALLOC(bufSz, NULL,
@@ -24493,10 +24510,19 @@ static int pqc_crl_sign_verify(const byte* caCertDer, word32 caCertDerSz,
2449324510 /* Sign the CRL with the post-quantum key. */
2449424511 if (EXPECT_SUCCESS()) {
2449524512 crlSz = wc_SignCRL_ex(tbsBuf, tbsSz, sigType, crlBuf, (word32)bufSz,
24496- NULL, NULL, mldsaKey, slhDsaKey, &rng );
24513+ NULL, NULL, &rng, mldsaKey, slhDsaKey );
2449724514 ExpectIntGT(crlSz, 0);
2449824515 }
2449924516
24517+ /* Negative: a classic signatureAlgorithm OID must be rejected for a PQC
24518+ * key before any signature is produced. CheckSigTypeForKey runs before the
24519+ * TBS is copied into the output, so crlBuf still holds the valid CRL. */
24520+ if (EXPECT_SUCCESS()) {
24521+ ExpectIntEQ(wc_SignCRL_ex(tbsBuf, tbsSz, CTC_SHA256wRSA, crlBuf,
24522+ (word32)bufSz, NULL, NULL, &rng, mldsaKey, slhDsaKey),
24523+ WC_NO_ERR_TRACE(ALGO_ID_E));
24524+ }
24525+
2450024526 /* Load the issuing CA and verify the freshly signed CRL. */
2450124527 ExpectNotNull(cm = wolfSSL_CertManagerNew());
2450224528 ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, caCertDer, caCertDerSz,
@@ -24506,7 +24532,9 @@ static int pqc_crl_sign_verify(const byte* caCertDer, word32 caCertDerSz,
2450624532 ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crlBuf, crlSz,
2450724533 WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
2450824534
24509- /* Negative: corrupt the last signature byte; verification must now fail. */
24535+ /* Negative: flip a byte of the signature *value*. The DER lengths are
24536+ * unchanged so the CRL still parses; only the signature check can reject
24537+ * it, which must surface as ASN_CRL_CONFIRM_E. */
2451024538 if (EXPECT_SUCCESS()) {
2451124539 WOLFSSL_CERT_MANAGER* cm2 = NULL;
2451224540 crlBuf[crlSz - 1] ^= 0xFF;
@@ -24515,12 +24543,13 @@ static int pqc_crl_sign_verify(const byte* caCertDer, word32 caCertDerSz,
2451524543 caCertDerSz, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
2451624544 ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm2, WOLFSSL_CRL_CHECKALL),
2451724545 WOLFSSL_SUCCESS);
24518- ExpectIntNE (wolfSSL_CertManagerLoadCRLBuffer(cm2, crlBuf, crlSz,
24519- WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS );
24546+ ExpectIntEQ (wolfSSL_CertManagerLoadCRLBuffer(cm2, crlBuf, crlSz,
24547+ WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_CRL_CONFIRM_E) );
2452024548 wolfSSL_CertManagerFree(cm2);
2452124549 }
2452224550
2452324551 wolfSSL_CertManagerFree(cm);
24552+ XFREE(issuerDer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2452424553 XFREE(crlBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2452524554 XFREE(tbsBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
2452624555 if (rngInit)
0 commit comments