fix: zeroize stack buffer containing private key in deterministic ECDSA#798
Open
ChakshuGupta13 wants to merge 1 commit into
Open
fix: zeroize stack buffer containing private key in deterministic ECDSA#798ChakshuGupta13 wants to merge 1 commit into
ChakshuGupta13 wants to merge 1 commit into
Conversation
In mbedtls_ecdsa_sign_det_restartable(), the local buffer data[] holds the raw private key d (via mbedtls_mpi_write_binary) for HMAC-DRBG seeding per RFC 6979. After use, the buffer was not cleared, leaving up to 66 bytes of key material on the stack. Add mbedtls_platform_zeroize(data, sizeof(data)) in the cleanup path, consistent with the practice in hmac_drbg.c and rsa.c which zeroize their sensitive local buffers. Signed-off-by: Chakshu Gupta <chakshugupta2000@gmail.com>
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
In
mbedtls_ecdsa_sign_det_restartable(), the local stack bufferdata[2 * MBEDTLS_ECP_MAX_BYTES]holds the raw ECDSA private keyd(written viambedtls_mpi_write_binary()) for HMAC-DRBG seeding per RFC 6979. After use, the buffer is not cleared in the cleanup path, leaving up to 66 bytes of key material on the stack until overwritten by subsequent calls.Fix
Add
mbedtls_platform_zeroize(data, sizeof(data))to the cleanup path, beforembedtls_hmac_drbg_free().Rationale
This brings
ecdsa.cto parity with peer modules:hmac_drbg.c: zeroesK[],seed[],buf[]at cleanup (5 call sites)rsa.c: zeroesbuf[],mask[],lhash[]at cleanup (4 call sites)ecdsa.c: currently has zero uses ofmbedtls_platform_zeroizein the entire fileScope
Defense-in-depth hardening. The threat model (SECURITY.md) excludes direct local memory access, so this is not classified as a vulnerability fix — it is a missing cleanup consistent with existing project conventions.
Checklist
ChangeLog.d/zeroize-ecdsa-stack.txtdevelopmentbranch