Skip to content

Commit 15b1045

Browse files
authored
Merge pull request #10340 from JeremiahM37/fenrir-3
harden falcon key handling
2 parents c3cd71e + 9352fad commit 15b1045

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9815,8 +9815,8 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
98159815
return MEMORY_E;
98169816

98179817
if (wc_falcon_init(falcon) == 0) {
9818-
tmpIdx = 0;
9819-
if (wc_falcon_set_level(falcon, 1) == 0) {
9818+
if ((*algoID == 0) && (wc_falcon_set_level(falcon, 1) == 0)) {
9819+
tmpIdx = 0;
98209820
if (wc_Falcon_PrivateKeyDecode(key, &tmpIdx, falcon, keySz)
98219821
== 0) {
98229822
*algoID = FALCON_LEVEL1k;
@@ -9825,7 +9825,8 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
98259825
WOLFSSL_MSG("Not Falcon Level 1 DER key");
98269826
}
98279827
}
9828-
else if (wc_falcon_set_level(falcon, 5) == 0) {
9828+
if ((*algoID == 0) && (wc_falcon_set_level(falcon, 5) == 0)) {
9829+
tmpIdx = 0;
98299830
if (wc_Falcon_PrivateKeyDecode(key, &tmpIdx, falcon, keySz)
98309831
== 0) {
98319832
*algoID = FALCON_LEVEL5k;
@@ -9834,8 +9835,8 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
98349835
WOLFSSL_MSG("Not Falcon Level 5 DER key");
98359836
}
98369837
}
9837-
else {
9838-
WOLFSSL_MSG("GetKeyOID falcon initialization failed");
9838+
if (*algoID == 0) {
9839+
WOLFSSL_MSG("GetKeyOID could not match Falcon DER key");
98399840
}
98409841
wc_falcon_free(falcon);
98419842
}

wolfcrypt/src/falcon.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,14 @@ int wc_falcon_check_key(falcon_key* key)
662662
return BAD_FUNC_ARG;
663663
}
664664

665+
if ((key->level != 1) && (key->level != 5)) {
666+
return BAD_FUNC_ARG;
667+
}
668+
669+
if (!key->pubKeySet || !key->prvKeySet) {
670+
return PUBLIC_KEY_E;
671+
}
672+
665673
/* The public key is also decoded and stored within the private key buffer
666674
* behind the private key. Hence, we can compare both stored public keys. */
667675
if (key->level == 1) {

0 commit comments

Comments
 (0)