Skip to content

Commit cceeb77

Browse files
committed
gate dilithium OID autodetection on FIPS 204 draft mode
1 parent 30f372c commit cceeb77

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

tests/api.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35003,10 +35003,20 @@ static int test_wc_dilithium_der(void)
3500335003
* the supplied DER is invalid, this should fail with ASN parsing error */
3500435004
idx = 0;
3500535005
ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, pubDerLen),
35006-
WC_NO_ERR_TRACE(ASN_PARSE_E));
35006+
#ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
35007+
WC_NO_ERR_TRACE(BAD_FUNC_ARG)
35008+
#else
35009+
WC_NO_ERR_TRACE(ASN_PARSE_E)
35010+
#endif
35011+
);
3500735012
idx = 0;
3500835013
ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, privDerLen),
35009-
WC_NO_ERR_TRACE(ASN_PARSE_E));
35014+
#ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
35015+
WC_NO_ERR_TRACE(BAD_FUNC_ARG)
35016+
#else
35017+
WC_NO_ERR_TRACE(ASN_PARSE_E)
35018+
#endif
35019+
);
3501035020

3501135021
#ifndef WOLFSSL_NO_ML_DSA_44
3501235022
ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);

wolfcrypt/src/dilithium.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9532,14 +9532,15 @@ static int mapOidToSecLevel(word32 oid)
95329532
* @param [in, out] inOutIdx On in, index into array of start of DER encoding.
95339533
* On out, index into array after DER encoding.
95349534
* @param [in, out] key Dilithium key structure to hold the decoded key.
9535-
* If the security level is set in the key structure on
9536-
* input, the DER key will be decoded as such and will
9537-
* fail if there is a mismatch. If the level and
9538-
* parameters are not set in the key structure on
9535+
* If the security level is set in the key structure
9536+
* on input, the DER key will be decoded as such and
9537+
* will fail if there is a mismatch. If the level
9538+
* and parameters are not set in the key structure on
95399539
* input, the level will be detected from the DER
95409540
* file based on the algorithm OID, appropriately
95419541
* decoded, then updated in the key structure on
9542-
* output.
9542+
* output. Auto-detection of the security level is
9543+
* not supported if compiled for FIPS 204 draft mode.
95439544
* @param [in] inSz Total size of the input DER buffer array.
95449545
* @return 0 on success.
95459546
* @return BAD_FUNC_ARG when input, inOutIdx or key is NULL or inSz is 0.
@@ -9803,10 +9804,12 @@ static int dilithium_check_type(const byte* input, word32* inOutIdx, byte type,
98039804
* on input, the DER key will be decoded as such
98049805
* and will fail if there is a mismatch. If the level
98059806
* and parameters are not set in the key structure on
9806-
* input, the level will be detected from the DER file
9807-
* based on the algorithm OID, appropriately decoded,
9808-
* then updated in the key structure on output.
9809-
* updated in the key structure on output.
9807+
* input, the level will be detected from the DER
9808+
* file based on the algorithm OID, appropriately
9809+
* decoded, then updated in the key structure on
9810+
* output. Auto-detection of the security level is
9811+
* not supported if compiled for FIPS 204
9812+
* draft mode.
98109813
* @param [in] inSz Total size of data in array.
98119814
* @return 0 on success.
98129815
* @return BAD_FUNC_ARG when input, inOutIdx or key is NULL or inSz is 0.

wolfcrypt/test/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45952,6 +45952,7 @@ static wc_test_ret_t test_dilithium_decode_level(const byte* rawKey,
4595245952
ret = wc_dilithium_init(&key);
4595345953
}
4595445954

45955+
#ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
4595545956
/* Test decoding without setting security level - should auto-detect */
4595645957
if (ret == 0) {
4595745958
idx = 0;
@@ -45974,6 +45975,7 @@ static wc_test_ret_t test_dilithium_decode_level(const byte* rawKey,
4597445975
expectedLevel, key.level);
4597545976
ret = WC_TEST_RET_ENC_NC;
4597645977
}
45978+
#endif /* !WOLFSSL_DILITHIUM_FIPS204_DRAFT */
4597745979

4597845980
/* Cleanup */
4597945981
XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);

0 commit comments

Comments
 (0)