Zeroize raw-byte private-key parameters on destroy - #201
Merged
Merged
Conversation
Private-key parameter classes that hold their secret as raw bytes did not wipe it when destroyed, so the scalar lingered in freed memory until overwritten. These objects are interface-refcounted, so Destroy runs deterministically when the last reference releases, making the wipe reliable rather than best-effort. Add a wiping destructor to the byte-scalar private keys (X25519, X448, Ed25519, Ed448, Bip340 Schnorr), which already own a private copy of the scalar. For the ML-KEM, ML-DSA and SLH-DSA private keys, whose constructors previously stored their arrays by reference, take private copies of the secret fields on construction so the destructor can wipe them without touching a public value that may be shared with the corresponding public key; the public fields are left as-is. Add PrivateKeyWipeTests, which builds an ML-KEM and an ML-DSA key, captures the secret buffer by reference, drops the key, and asserts the buffer is zeroed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Private-key parameter classes that hold their secret as raw bytes did not wipe it
when destroyed, so the scalar lingered in freed memory until overwritten by chance.
These objects are interface-refcounted, so
Destroyruns deterministically when thelast reference releases, which makes the wipe reliable rather than best-effort. This
closes an inconsistency: symmetric key material (
TKeyParameter) and transientHPKE/DHKEM buffers are already wiped, but the long-lived asymmetric private keys were
not.
Secret-hygiene hardening only: no public behaviour change, no wire-output change.
What changed
Byte-scalar private keys (already own a private copy of the scalar): add a wiping
destructor.
TX25519PrivateKeyParametersTX448PrivateKeyParametersTEd25519PrivateKeyParametersTEd448PrivateKeyParametersTBip340SchnorrPrivateKeyParametersPQC private keys (constructors previously stored their arrays by reference): take
private copies of the secret fields on construction so the destructor can wipe them
without touching a public value that may be shared with the corresponding public key.
Public fields are left untouched.
TMlKemPrivateKeyParameters- wipeFSeed,FEncoding.TMlDsaPrivateKeyParameters- wipeFK,FTr,FS1,FS2,FT0,FSeed;public
FRho/FT1untouched.TSlhDsaPrivateKeyParameters- wipeFSk.Seed,FSk.Prf; publicFPkuntouched.Tests: new
PrivateKeyWipeTestsbuilds an ML-KEM and an ML-DSA key, captures thesecret buffer by reference, drops the key, and asserts the buffer is zeroed. (A nested
helper is used so the compiler's hidden interface temporaries are released and the
destructor actually runs before the assertion.) The byte-scalar and SLH-DSA keys expose
no by-reference seam, so their identical wipe is covered by the existing key-agreement,
signature and KEM suites.