Skip to content

Commit aa54b60

Browse files
committed
[crypto] Add OTBN DMEM wipes to RSA code
Always wipe the DMEM once the OTBN execution has been finished. Signed-off-by: Pascal Nasahl <nasahlpa@lowrisc.org>
1 parent 0cfe3d9 commit aa54b60

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

sw/device/lib/crypto/impl/rsa/rsa_3072_verify.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ status_t rsa_3072_compute_constants(const rsa_3072_public_key_t *public_key,
146146
HARDENED_TRY(
147147
otbn_dmem_read(kOtbnWideWordNumWords, kOtbnVarRsaM0Inv, result->m0_inv));
148148

149-
return OTCRYPTO_OK;
149+
// Wipe DMEM.
150+
return otbn_dmem_sec_wipe();
150151
}
151152

152153
status_t rsa_3072_verify_start(const rsa_3072_int_t *signature,
@@ -212,7 +213,8 @@ status_t rsa_3072_verify_finalize(const rsa_3072_int_t *message,
212213
}
213214
}
214215

215-
return OTCRYPTO_OK;
216+
// Wipe DMEM.
217+
return otbn_dmem_sec_wipe();
216218
}
217219

218220
status_t rsa_3072_verify(const rsa_3072_int_t *signature,

sw/device/lib/crypto/impl/rsa/rsa_keygen.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ static status_t keygen_finalize(uint32_t exp_mode, size_t num_words,
9999
HARDENED_TRY(otbn_dmem_read(num_words, kOtbnVarRsaD, d));
100100

101101
// Wipe DMEM.
102-
HARDENED_TRY(otbn_dmem_sec_wipe());
103-
104-
return OTCRYPTO_OK;
102+
return otbn_dmem_sec_wipe();
105103
}
106104

107105
status_t rsa_keygen_2048_start(void) {

sw/device/lib/crypto/impl/rsa/rsa_modexp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ status_t rsa_modexp_wait(size_t *num_words) {
7272
} else if (mode == kMode4096Modexp || mode == kMode4096ModexpF4) {
7373
*num_words = kRsa4096NumWords;
7474
} else {
75+
// Wipe DMEM.
76+
HARDENED_TRY(otbn_dmem_sec_wipe());
7577
// Unrecognized mode.
7678
return OTCRYPTO_FATAL_ERR;
7779
}
@@ -96,6 +98,8 @@ static status_t rsa_modexp_finalize(const size_t num_words, uint32_t *result) {
9698

9799
// Check that the inferred result size matches expectations.
98100
if (num_words != num_words_inferred) {
101+
// Wipe DMEM.
102+
HARDENED_TRY(otbn_dmem_sec_wipe());
99103
return OTCRYPTO_FATAL_ERR;
100104
}
101105

0 commit comments

Comments
 (0)