From b038b1254c7bb7e56dd2772c7c789755e1a07ddd Mon Sep 17 00:00:00 2001 From: Siemen Dhooghe Date: Mon, 14 Sep 2026 10:15:49 +0200 Subject: [PATCH] [crypto] Shred ss after use Signed-off-by: Siemen Dhooghe (cherry picked from commit 48d304064221b6d5e38536634bb5fbd6c9c81d57) --- sw/device/lib/crypto/impl/ecc_p256.c | 8 ++++++++ sw/device/lib/crypto/impl/ecc_p384.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/sw/device/lib/crypto/impl/ecc_p256.c b/sw/device/lib/crypto/impl/ecc_p256.c index 6af1aa411d785..ee56cf568d6c2 100644 --- a/sw/device/lib/crypto/impl/ecc_p256.c +++ b/sw/device/lib/crypto/impl/ecc_p256.c @@ -839,6 +839,14 @@ otcrypto_status_t otcrypto_ecdh_p256_async_finalize( // Set the checksum. shared_secret->checksum = otcrypto_integrity_blinded_checksum(shared_secret); + // Shred ss. + HARDENED_TRY(hardened_memshred(ss.x_share0, ARRAYSIZE(ss.x_share0))); + HARDENED_TRY(hardened_memshred(ss.x_share1, ARRAYSIZE(ss.x_share1))); + HARDENED_TRY(hardened_memshred(ss.y_share0, ARRAYSIZE(ss.y_share0))); + HARDENED_TRY(hardened_memshred(ss.y_share1, ARRAYSIZE(ss.y_share1))); + HARDENED_TRY(hardened_memshred(share0, ARRAYSIZE(share0))); + HARDENED_TRY(hardened_memshred(share1, ARRAYSIZE(share1))); + // Clear the OTBN sideload slot (in case the seed was sideloaded). return otcrypto_eval_exit(keymgr_dpe_sideload_clear_otbn()); } diff --git a/sw/device/lib/crypto/impl/ecc_p384.c b/sw/device/lib/crypto/impl/ecc_p384.c index 61d2b55e26d6e..047f8976d0252 100644 --- a/sw/device/lib/crypto/impl/ecc_p384.c +++ b/sw/device/lib/crypto/impl/ecc_p384.c @@ -702,6 +702,10 @@ otcrypto_status_t otcrypto_ecdh_p384_async_finalize( // Set the checksum. shared_secret->checksum = otcrypto_integrity_blinded_checksum(shared_secret); + // Shred ss. + HARDENED_TRY(hardened_memshred(ss.share0, ARRAYSIZE(ss.share0))); + HARDENED_TRY(hardened_memshred(ss.share1, ARRAYSIZE(ss.share1))); + // Clear the OTBN sideload slot (in case the seed was sideloaded). return otcrypto_eval_exit(keymgr_dpe_sideload_clear_otbn()); }