Skip to content

Commit ff4ff51

Browse files
committed
fix unreachable sphincs variant detection
1 parent 75b1532 commit ff4ff51

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9618,9 +9618,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96189618
return MEMORY_E;
96199619

96209620
if (wc_sphincs_init(sphincs) == 0) {
9621-
tmpIdx = 0;
9622-
if (wc_sphincs_set_level_and_optim(sphincs, 1, FAST_VARIANT)
9623-
== 0) {
9621+
if ((*algoID == 0) &&
9622+
(wc_sphincs_set_level_and_optim(sphincs, 1, FAST_VARIANT)
9623+
== 0)) {
9624+
tmpIdx = 0;
96249625
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96259626
keySz) == 0) {
96269627
*algoID = SPHINCS_FAST_LEVEL1k;
@@ -9629,8 +9630,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96299630
WOLFSSL_MSG("Not Sphincs-fast Level 1 DER key");
96309631
}
96319632
}
9632-
else if (wc_sphincs_set_level_and_optim(sphincs, 3, FAST_VARIANT)
9633-
== 0) {
9633+
if ((*algoID == 0) &&
9634+
(wc_sphincs_set_level_and_optim(sphincs, 3, FAST_VARIANT)
9635+
== 0)) {
9636+
tmpIdx = 0;
96349637
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96359638
keySz) == 0) {
96369639
*algoID = SPHINCS_FAST_LEVEL3k;
@@ -9639,8 +9642,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96399642
WOLFSSL_MSG("Not Sphincs-fast Level 3 DER key");
96409643
}
96419644
}
9642-
else if (wc_sphincs_set_level_and_optim(sphincs, 5, FAST_VARIANT)
9643-
== 0) {
9645+
if ((*algoID == 0) &&
9646+
(wc_sphincs_set_level_and_optim(sphincs, 5, FAST_VARIANT)
9647+
== 0)) {
9648+
tmpIdx = 0;
96449649
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96459650
keySz) == 0) {
96469651
*algoID = SPHINCS_FAST_LEVEL5k;
@@ -9649,8 +9654,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96499654
WOLFSSL_MSG("Not Sphincs-fast Level 5 DER key");
96509655
}
96519656
}
9652-
else if (wc_sphincs_set_level_and_optim(sphincs, 1, SMALL_VARIANT)
9653-
== 0) {
9657+
if ((*algoID == 0) &&
9658+
(wc_sphincs_set_level_and_optim(sphincs, 1, SMALL_VARIANT)
9659+
== 0)) {
9660+
tmpIdx = 0;
96549661
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96559662
keySz) == 0) {
96569663
*algoID = SPHINCS_SMALL_LEVEL1k;
@@ -9659,8 +9666,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96599666
WOLFSSL_MSG("Not Sphincs-small Level 1 DER key");
96609667
}
96619668
}
9662-
else if (wc_sphincs_set_level_and_optim(sphincs, 3, SMALL_VARIANT)
9663-
== 0) {
9669+
if ((*algoID == 0) &&
9670+
(wc_sphincs_set_level_and_optim(sphincs, 3, SMALL_VARIANT)
9671+
== 0)) {
9672+
tmpIdx = 0;
96649673
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96659674
keySz) == 0) {
96669675
*algoID = SPHINCS_SMALL_LEVEL3k;
@@ -9669,8 +9678,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96699678
WOLFSSL_MSG("Not Sphincs-small Level 3 DER key");
96709679
}
96719680
}
9672-
else if (wc_sphincs_set_level_and_optim(sphincs, 5, SMALL_VARIANT)
9673-
== 0) {
9681+
if ((*algoID == 0) &&
9682+
(wc_sphincs_set_level_and_optim(sphincs, 5, SMALL_VARIANT)
9683+
== 0)) {
9684+
tmpIdx = 0;
96749685
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96759686
keySz) == 0) {
96769687
*algoID = SPHINCS_SMALL_LEVEL5k;
@@ -9679,7 +9690,7 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96799690
WOLFSSL_MSG("Not Sphincs-small Level 5 DER key");
96809691
}
96819692
}
9682-
else {
9693+
if (*algoID == 0) {
96839694
WOLFSSL_MSG("GetKeyOID sphincs initialization failed");
96849695
}
96859696
wc_sphincs_free(sphincs);

0 commit comments

Comments
 (0)