Skip to content

Commit 2626f97

Browse files
committed
Update the PKCS11 ECC and dilithium free handlers so they will now return CRYPTOCB_UNAVAILABLE after attempting the context free so the caller still does software cleanup on the rest of the context that the callback does not handle.
1 parent 5ff2b55 commit 2626f97

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

wolfcrypt/src/wc_pkcs11.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,6 +5794,12 @@ int wc_Pkcs11_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx)
57945794
(ecc_key*)info->free.obj);
57955795
Pkcs11CloseSession(token, &session);
57965796
}
5797+
/* Return CRYPTOCB_UNAVAILABLE so wc_ecc_free() still
5798+
* performs software cleanup. This callback only releases
5799+
* the HSM object. Conditional because wc_ecc_free returns
5800+
* int and can propagate an HSM error to the caller. */
5801+
if (ret == 0)
5802+
ret = CRYPTOCB_UNAVAILABLE;
57975803
}
57985804
else
57995805
#endif
@@ -5807,6 +5813,11 @@ int wc_Pkcs11_CryptoDevCb(int devId, wc_CryptoInfo* info, void* ctx)
58075813
(MlDsaKey*)info->free.obj);
58085814
Pkcs11CloseSession(token, &session);
58095815
}
5816+
/* Always return CRYPTOCB_UNAVAILABLE so wc_dilithium_free()
5817+
* performs software cleanup. This callback only releases
5818+
* the HSM object. Unconditional because wc_dilithium_free
5819+
* returns void and cannot propagate an error. */
5820+
ret = CRYPTOCB_UNAVAILABLE;
58105821
}
58115822
else
58125823
#endif

0 commit comments

Comments
 (0)