Avoid leaving secrets in memory on error paths
What changed, and why it matters
This commit fixes a security issue where a secret cryptographic key could be left behind in memory if an error occurred during a key-tweaking operation. The patch now wipes the output buffer on failure paths, reducing the risk that leftover secret material could be extracted later.
Review other crypto functions for similar missing cleanup on error paths; ensure the patch is included in the next firmware/app release; consider whether any prior released version is affected and if a security advisory is warranted.
Security signals we found
explicit_bzero used to clear secret material on error path
secret key / key-derived data potentially left in memory before patch
defensive cleanup of sensitive output buffer
Evidence from the diff
In crypto_tr_tweak_seckey() in src/crypto.c, the function previously cleared an intermediate point P with explicit_bzero() before returning, but on error paths the 32-byte output buffer out could still contain partial or derived data related to the input secret key. The patch adds an explicit_bzero(out, 32) whenever ret != 0, ensuring no secret-derived material remains in the output buffer on failure.
Changed components
src/crypto.ccrypto_tr_tweak_seckeyInspect captured patch +5 / −0
diff --git a/src/crypto.c b/src/crypto.c
index 41b5a55..a6a8619 100644
--- a/src/crypto.c
+++ b/src/crypto.c
@@ -638,6 +638,11 @@ int crypto_tr_tweak_seckey(const uint8_t seckey[static 32],
ret = 0;
} while (0);
+ if (ret != 0) {
+ // In case of error, make sure that the output buffer doesn't contain data related to seckey
+ explicit_bzero(out, 32);
+ }
+
explicit_bzero(&P, sizeof(P));
return ret;
Why this scored 59/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.