Skip to content

Commit da635c9

Browse files
authored
Merge pull request #9980 from anhu/sphincs_no_elseif
Fixes SPHINCS else-if chain key detection
2 parents 90377e1 + 2939ab7 commit da635c9

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
@@ -9670,9 +9670,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96709670
return MEMORY_E;
96719671

96729672
if (wc_sphincs_init(sphincs) == 0) {
9673-
tmpIdx = 0;
9674-
if (wc_sphincs_set_level_and_optim(sphincs, 1, FAST_VARIANT)
9675-
== 0) {
9673+
if ((*algoID == 0) &&
9674+
(wc_sphincs_set_level_and_optim(sphincs, 1, FAST_VARIANT)
9675+
== 0)) {
9676+
tmpIdx = 0;
96769677
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96779678
keySz) == 0) {
96789679
*algoID = SPHINCS_FAST_LEVEL1k;
@@ -9681,8 +9682,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96819682
WOLFSSL_MSG("Not Sphincs-fast Level 1 DER key");
96829683
}
96839684
}
9684-
else if (wc_sphincs_set_level_and_optim(sphincs, 3, FAST_VARIANT)
9685-
== 0) {
9685+
if ((*algoID == 0) &&
9686+
(wc_sphincs_set_level_and_optim(sphincs, 3, FAST_VARIANT)
9687+
== 0)) {
9688+
tmpIdx = 0;
96869689
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96879690
keySz) == 0) {
96889691
*algoID = SPHINCS_FAST_LEVEL3k;
@@ -9691,8 +9694,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96919694
WOLFSSL_MSG("Not Sphincs-fast Level 3 DER key");
96929695
}
96939696
}
9694-
else if (wc_sphincs_set_level_and_optim(sphincs, 5, FAST_VARIANT)
9695-
== 0) {
9697+
if ((*algoID == 0) &&
9698+
(wc_sphincs_set_level_and_optim(sphincs, 5, FAST_VARIANT)
9699+
== 0)) {
9700+
tmpIdx = 0;
96969701
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96979702
keySz) == 0) {
96989703
*algoID = SPHINCS_FAST_LEVEL5k;
@@ -9701,8 +9706,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97019706
WOLFSSL_MSG("Not Sphincs-fast Level 5 DER key");
97029707
}
97039708
}
9704-
else if (wc_sphincs_set_level_and_optim(sphincs, 1, SMALL_VARIANT)
9705-
== 0) {
9709+
if ((*algoID == 0) &&
9710+
(wc_sphincs_set_level_and_optim(sphincs, 1, SMALL_VARIANT)
9711+
== 0)) {
9712+
tmpIdx = 0;
97069713
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
97079714
keySz) == 0) {
97089715
*algoID = SPHINCS_SMALL_LEVEL1k;
@@ -9711,8 +9718,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97119718
WOLFSSL_MSG("Not Sphincs-small Level 1 DER key");
97129719
}
97139720
}
9714-
else if (wc_sphincs_set_level_and_optim(sphincs, 3, SMALL_VARIANT)
9715-
== 0) {
9721+
if ((*algoID == 0) &&
9722+
(wc_sphincs_set_level_and_optim(sphincs, 3, SMALL_VARIANT)
9723+
== 0)) {
9724+
tmpIdx = 0;
97169725
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
97179726
keySz) == 0) {
97189727
*algoID = SPHINCS_SMALL_LEVEL3k;
@@ -9721,8 +9730,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97219730
WOLFSSL_MSG("Not Sphincs-small Level 3 DER key");
97229731
}
97239732
}
9724-
else if (wc_sphincs_set_level_and_optim(sphincs, 5, SMALL_VARIANT)
9725-
== 0) {
9733+
if ((*algoID == 0) &&
9734+
(wc_sphincs_set_level_and_optim(sphincs, 5, SMALL_VARIANT)
9735+
== 0)) {
9736+
tmpIdx = 0;
97269737
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
97279738
keySz) == 0) {
97289739
*algoID = SPHINCS_SMALL_LEVEL5k;
@@ -9731,7 +9742,7 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97319742
WOLFSSL_MSG("Not Sphincs-small Level 5 DER key");
97329743
}
97339744
}
9734-
else {
9745+
if (*algoID == 0) {
97359746
WOLFSSL_MSG("GetKeyOID sphincs initialization failed");
97369747
}
97379748
wc_sphincs_free(sphincs);

0 commit comments

Comments
 (0)