Skip to content

Commit cef3187

Browse files
authored
Merge pull request #10456 from padelsbach/lms-xmss-sw-fallback-fix
Fix LMS and XMSS cryptocb software fallback
2 parents 9e739c6 + d56831c commit cef3187

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

wolfcrypt/src/wc_lms.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,15 +1555,16 @@ int wc_LmsKey_SigsLeft(LmsKey* key)
15551555
if (cbRet == 0) {
15561556
return (sigsLeft != 0) ? 1 : 0;
15571557
}
1558-
/* The device owns the private state; no safe software fallback
1559-
* exists because key->priv_raw does not reflect HSM state. */
15601558
if (cbRet != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
1559+
/* Device returned an actual error; the device owns the
1560+
* private state so no safe software fallback exists. */
15611561
WOLFSSL_MSG("PqcStatefulSigSigsLeft returned an error");
1562+
return 0;
15621563
}
1563-
else {
1564-
WOLFSSL_MSG("LMS SigsLeft not supported by device");
1565-
}
1566-
return 0;
1564+
/* Cryptocb declined. priv_raw reflects software state from the
1565+
* CRYPTOCB_UNAVAILABLE fall-through in MakeKey/Reload, so the
1566+
* software check below is valid. */
1567+
WOLFSSL_MSG("LMS SigsLeft not supported by device, using software");
15671568
}
15681569
#endif
15691570
ret = wc_hss_sigsleft(key->params, key->priv_raw);

wolfcrypt/src/wc_xmss.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,15 +1521,16 @@ int wc_XmssKey_SigsLeft(XmssKey* key)
15211521
if (cbRet == 0) {
15221522
return (sigsLeft != 0) ? 1 : 0;
15231523
}
1524-
/* The device owns the private state; no safe software fallback
1525-
* exists because key->sk does not reflect HSM state. */
15261524
if (cbRet != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
1525+
/* Device returned an actual error; the device owns the
1526+
* private state so no safe software fallback exists. */
15271527
WOLFSSL_MSG("PqcStatefulSigSigsLeft returned an error");
1528+
return 0;
15281529
}
1529-
else {
1530-
WOLFSSL_MSG("XMSS SigsLeft not supported by device");
1531-
}
1532-
return 0;
1530+
/* Cryptocb declined. Fall through to the software path: state
1531+
* reflects the CRYPTOCB_UNAVAILABLE fall-through in MakeKey/Reload,
1532+
* and read_private_key can repopulate sk from NV storage. */
1533+
WOLFSSL_MSG("XMSS SigsLeft not supported by device, using software");
15331534
}
15341535
#endif
15351536

0 commit comments

Comments
 (0)