From fe0c28d1fe43b39707db82b1f9ec07668b40528f Mon Sep 17 00:00:00 2001 From: yhql Date: Mon, 23 Jan 2023 16:39:38 +0100 Subject: [PATCH] [fix] Clear memory even on errors --- src/signMessage.c | 1 + src/signOffchainMessage.c | 1 + src/utils.c | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/signMessage.c b/src/signMessage.c index caa44224..2bc3d380 100644 --- a/src/signMessage.c +++ b/src/signMessage.c @@ -33,6 +33,7 @@ static uint8_t set_result_sign_message() { memcpy(G_io_apdu_buffer, signature, SIGNATURE_LENGTH); } CATCH_OTHER(e) { + MEMCLEAR(privateKey); THROW(e); } FINALLY { diff --git a/src/signOffchainMessage.c b/src/signOffchainMessage.c index 38aaf995..286930dd 100644 --- a/src/signOffchainMessage.c +++ b/src/signOffchainMessage.c @@ -97,6 +97,7 @@ static uint8_t set_result_sign_message() { memcpy(G_io_apdu_buffer, signature, SIGNATURE_LENGTH); } CATCH_OTHER(e) { + MEMCLEAR(privateKey); THROW(e); } FINALLY { diff --git a/src/utils.c b/src/utils.c index 258a1fcc..7ea9b056 100644 --- a/src/utils.c +++ b/src/utils.c @@ -15,6 +15,7 @@ void get_public_key(uint8_t *publicKeyArray, const uint32_t *derivationPath, siz cx_ecfp_generate_pair(CX_CURVE_Ed25519, &publicKey, &privateKey, 1); } CATCH_OTHER(e) { + MEMCLEAR(privateKey); THROW(e); } FINALLY { @@ -55,6 +56,7 @@ void get_private_key(cx_ecfp_private_key_t *privateKey, privateKey); } CATCH_OTHER(e) { + MEMCLEAR(privateKeyData); THROW(e); } FINALLY { @@ -84,6 +86,7 @@ void get_private_key_with_seed(cx_ecfp_private_key_t *privateKey, privateKey); } CATCH_OTHER(e) { + MEMCLEAR(privateKeyData); THROW(e); } FINALLY {