Skip to content

Commit 2939ab7

Browse files
committed
Fixes SPHINCS else-if chain key detection
F-751
1 parent f8dda21 commit 2939ab7

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

96719671
if (wc_sphincs_init(sphincs) == 0) {
9672-
tmpIdx = 0;
9673-
if (wc_sphincs_set_level_and_optim(sphincs, 1, FAST_VARIANT)
9674-
== 0) {
9672+
if ((*algoID == 0) &&
9673+
(wc_sphincs_set_level_and_optim(sphincs, 1, FAST_VARIANT)
9674+
== 0)) {
9675+
tmpIdx = 0;
96759676
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96769677
keySz) == 0) {
96779678
*algoID = SPHINCS_FAST_LEVEL1k;
@@ -9680,8 +9681,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96809681
WOLFSSL_MSG("Not Sphincs-fast Level 1 DER key");
96819682
}
96829683
}
9683-
else if (wc_sphincs_set_level_and_optim(sphincs, 3, FAST_VARIANT)
9684-
== 0) {
9684+
if ((*algoID == 0) &&
9685+
(wc_sphincs_set_level_and_optim(sphincs, 3, FAST_VARIANT)
9686+
== 0)) {
9687+
tmpIdx = 0;
96859688
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96869689
keySz) == 0) {
96879690
*algoID = SPHINCS_FAST_LEVEL3k;
@@ -9690,8 +9693,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
96909693
WOLFSSL_MSG("Not Sphincs-fast Level 3 DER key");
96919694
}
96929695
}
9693-
else if (wc_sphincs_set_level_and_optim(sphincs, 5, FAST_VARIANT)
9694-
== 0) {
9696+
if ((*algoID == 0) &&
9697+
(wc_sphincs_set_level_and_optim(sphincs, 5, FAST_VARIANT)
9698+
== 0)) {
9699+
tmpIdx = 0;
96959700
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
96969701
keySz) == 0) {
96979702
*algoID = SPHINCS_FAST_LEVEL5k;
@@ -9700,8 +9705,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97009705
WOLFSSL_MSG("Not Sphincs-fast Level 5 DER key");
97019706
}
97029707
}
9703-
else if (wc_sphincs_set_level_and_optim(sphincs, 1, SMALL_VARIANT)
9704-
== 0) {
9708+
if ((*algoID == 0) &&
9709+
(wc_sphincs_set_level_and_optim(sphincs, 1, SMALL_VARIANT)
9710+
== 0)) {
9711+
tmpIdx = 0;
97059712
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
97069713
keySz) == 0) {
97079714
*algoID = SPHINCS_SMALL_LEVEL1k;
@@ -9710,8 +9717,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97109717
WOLFSSL_MSG("Not Sphincs-small Level 1 DER key");
97119718
}
97129719
}
9713-
else if (wc_sphincs_set_level_and_optim(sphincs, 3, SMALL_VARIANT)
9714-
== 0) {
9720+
if ((*algoID == 0) &&
9721+
(wc_sphincs_set_level_and_optim(sphincs, 3, SMALL_VARIANT)
9722+
== 0)) {
9723+
tmpIdx = 0;
97159724
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
97169725
keySz) == 0) {
97179726
*algoID = SPHINCS_SMALL_LEVEL3k;
@@ -9720,8 +9729,10 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97209729
WOLFSSL_MSG("Not Sphincs-small Level 3 DER key");
97219730
}
97229731
}
9723-
else if (wc_sphincs_set_level_and_optim(sphincs, 5, SMALL_VARIANT)
9724-
== 0) {
9732+
if ((*algoID == 0) &&
9733+
(wc_sphincs_set_level_and_optim(sphincs, 5, SMALL_VARIANT)
9734+
== 0)) {
9735+
tmpIdx = 0;
97259736
if (wc_Sphincs_PrivateKeyDecode(key, &tmpIdx, sphincs,
97269737
keySz) == 0) {
97279738
*algoID = SPHINCS_SMALL_LEVEL5k;
@@ -9730,7 +9741,7 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
97309741
WOLFSSL_MSG("Not Sphincs-small Level 5 DER key");
97319742
}
97329743
}
9733-
else {
9744+
if (*algoID == 0) {
97349745
WOLFSSL_MSG("GetKeyOID sphincs initialization failed");
97359746
}
97369747
wc_sphincs_free(sphincs);

0 commit comments

Comments
 (0)