diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 2451b8624e0..58f61aef153 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -9582,8 +9582,8 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz, return MEMORY_E; if (wc_falcon_init(falcon) == 0) { - tmpIdx = 0; - if (wc_falcon_set_level(falcon, 1) == 0) { + if ((*algoID == 0) && (wc_falcon_set_level(falcon, 1) == 0)) { + tmpIdx = 0; if (wc_Falcon_PrivateKeyDecode(key, &tmpIdx, falcon, keySz) == 0) { *algoID = FALCON_LEVEL1k; @@ -9592,7 +9592,8 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz, WOLFSSL_MSG("Not Falcon Level 1 DER key"); } } - else if (wc_falcon_set_level(falcon, 5) == 0) { + if ((*algoID == 0) && (wc_falcon_set_level(falcon, 5) == 0)) { + tmpIdx = 0; if (wc_Falcon_PrivateKeyDecode(key, &tmpIdx, falcon, keySz) == 0) { *algoID = FALCON_LEVEL5k; @@ -9601,7 +9602,7 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz, WOLFSSL_MSG("Not Falcon Level 5 DER key"); } } - else { + if (*algoID == 0) { WOLFSSL_MSG("GetKeyOID falcon initialization failed"); } wc_falcon_free(falcon);