Skip to content

Commit d56831c

Browse files
committed
Fix LMS and XMSS cryptocb software fallback
1 parent 01ba609 commit d56831c

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
@@ -1422,15 +1422,16 @@ int wc_LmsKey_SigsLeft(LmsKey* key)
14221422
if (cbRet == 0) {
14231423
return (sigsLeft != 0) ? 1 : 0;
14241424
}
1425-
/* The device owns the private state; no safe software fallback
1426-
* exists because key->priv_raw does not reflect HSM state. */
14271425
if (cbRet != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
1426+
/* Device returned an actual error; the device owns the
1427+
* private state so no safe software fallback exists. */
14281428
WOLFSSL_MSG("PqcStatefulSigSigsLeft returned an error");
1429+
return 0;
14291430
}
1430-
else {
1431-
WOLFSSL_MSG("LMS SigsLeft not supported by device");
1432-
}
1433-
return 0;
1431+
/* Cryptocb declined. priv_raw reflects software state from the
1432+
* CRYPTOCB_UNAVAILABLE fall-through in MakeKey/Reload, so the
1433+
* software check below is valid. */
1434+
WOLFSSL_MSG("LMS SigsLeft not supported by device, using software");
14341435
}
14351436
#endif
14361437
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)