Commit b3dbb10
committed
cryptocb: always run software cleanup in key Free functions
The WOLF_CRYPTO_CB_FREE path in wc_MlKemKey_Free, wc_dilithium_free,
and wc_ecc_free returned early when the crypto callback succeeded,
skipping local cleanup: ForceZero on private key material, PRF/hash
object frees (ML-KEM), SHAKE free and cached vector frees (ML-DSA),
and mp_forcezero on the private scalar and all hardware port frees
(ECC).
Any non-PKCS#11 callback returning 0 would silently leave key material
in memory. The PKCS#11 backend worked around this by returning
CRYPTOCB_UNAVAILABLE on success to force the fallthrough — a fragile
contract that is not part of the documented callback interface.
Fix by always continuing to software cleanup after invoking the
callback:
- ML-KEM / ECC (int-returning): translate CRYPTOCB_UNAVAILABLE to 0,
surface real HSM errors to the caller via the return value.
- ML-DSA (void): discard the callback return with (void) cast since
there is no way to propagate it.
Remove the CRYPTOCB_UNAVAILABLE workaround from the three PKCS#11 free
dispatchers (ECC, ML-DSA, ML-KEM); they now return the real result of
C_DestroyObject.1 parent f3dbeee commit b3dbb10
4 files changed
+15
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10905 | 10905 | | |
10906 | 10906 | | |
10907 | 10907 | | |
10908 | | - | |
10909 | | - | |
10910 | | - | |
10911 | | - | |
10912 | 10908 | | |
10913 | 10909 | | |
10914 | 10910 | | |
10915 | | - | |
| 10911 | + | |
10916 | 10912 | | |
10917 | 10913 | | |
10918 | 10914 | | |
10919 | | - | |
10920 | | - | |
10921 | | - | |
| 10915 | + | |
10922 | 10916 | | |
10923 | | - | |
10924 | 10917 | | |
10925 | 10918 | | |
10926 | 10919 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7945 | 7945 | | |
7946 | 7946 | | |
7947 | 7947 | | |
7948 | | - | |
7949 | 7948 | | |
7950 | | - | |
7951 | 7949 | | |
7952 | 7950 | | |
7953 | 7951 | | |
| |||
7957 | 7955 | | |
7958 | 7956 | | |
7959 | 7957 | | |
7960 | | - | |
7961 | | - | |
7962 | | - | |
| 7958 | + | |
| 7959 | + | |
| 7960 | + | |
| 7961 | + | |
7963 | 7962 | | |
7964 | | - | |
7965 | 7963 | | |
7966 | 7964 | | |
7967 | 7965 | | |
| |||
7975 | 7973 | | |
7976 | 7974 | | |
7977 | 7975 | | |
| 7976 | + | |
7978 | 7977 | | |
7979 | 7978 | | |
7980 | 7979 | | |
| |||
8040 | 8039 | | |
8041 | 8040 | | |
8042 | 8041 | | |
8043 | | - | |
| 8042 | + | |
8044 | 8043 | | |
| 8044 | + | |
| 8045 | + | |
8045 | 8046 | | |
8046 | 8047 | | |
8047 | 8048 | | |
8048 | 8049 | | |
8049 | 8050 | | |
8050 | 8051 | | |
8051 | | - | |
| 8052 | + | |
8052 | 8053 | | |
8053 | 8054 | | |
8054 | 8055 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
395 | 394 | | |
396 | | - | |
397 | 395 | | |
398 | 396 | | |
399 | 397 | | |
400 | 398 | | |
401 | 399 | | |
402 | 400 | | |
403 | | - | |
404 | | - | |
| 401 | + | |
| 402 | + | |
405 | 403 | | |
406 | | - | |
| 404 | + | |
407 | 405 | | |
408 | | - | |
409 | 406 | | |
410 | 407 | | |
411 | 408 | | |
| |||
418 | 415 | | |
419 | 416 | | |
420 | 417 | | |
421 | | - | |
| 418 | + | |
422 | 419 | | |
423 | 420 | | |
424 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6570 | 6570 | | |
6571 | 6571 | | |
6572 | 6572 | | |
6573 | | - | |
6574 | | - | |
6575 | | - | |
6576 | | - | |
6577 | | - | |
6578 | | - | |
6579 | 6573 | | |
6580 | 6574 | | |
6581 | 6575 | | |
| |||
6589 | 6583 | | |
6590 | 6584 | | |
6591 | 6585 | | |
6592 | | - | |
6593 | | - | |
6594 | | - | |
6595 | | - | |
6596 | | - | |
6597 | 6586 | | |
6598 | 6587 | | |
6599 | 6588 | | |
| |||
6607 | 6596 | | |
6608 | 6597 | | |
6609 | 6598 | | |
6610 | | - | |
6611 | | - | |
6612 | | - | |
6613 | | - | |
6614 | | - | |
6615 | | - | |
6616 | | - | |
6617 | | - | |
6618 | 6599 | | |
6619 | 6600 | | |
6620 | 6601 | | |
| |||
0 commit comments