Skip to content

Commit e383c23

Browse files
andrea-caforioandreaskurth
authored andcommitted
[crypto/rsa] Resolve outstanding TODOs with respect to key sharing
The Boolean-masked key is now accounted for everywhere in the cryptolib. Signed-off-by: Andrea Caforio <[email protected]>
1 parent cb622e0 commit e383c23

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

sw/device/lib/crypto/impl/keyblob.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ static size_t keyblob_share_num_bytes(const otcrypto_key_config_t config) {
3535
return config.key_length + (64 / 8);
3636
case kOtcryptoKeyTypeRsa:
3737
// RSA key shares are the same size as the unmasked key.
38-
// TODO: update once masking is implemented for RSA keys.
3938
HARDENED_CHECK_EQ(config.key_mode >> 16, kOtcryptoKeyTypeRsa);
4039
return config.key_length;
4140
default:

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,7 @@ otcrypto_status_t otcrypto_rsa_private_key_from_exponents(
212212
(rsa_2048_private_key_t *)private_key->keyblob;
213213
HARDENED_TRY(hardened_memcpy(sk->n.data, modulus.data, modulus.len));
214214
HARDENED_TRY(hardened_memcpy(sk->d0.data, d_share0.data, d_share0.len));
215-
// TODO: RSA keys are currently unblinded, so combine the shares.
216-
for (size_t i = 0; i < d_share1.len; i++) {
217-
sk->d0.data[i] ^= d_share1.data[i];
218-
sk->d1.data[i] = 0x0;
219-
}
215+
HARDENED_TRY(hardened_memcpy(sk->d1.data, d_share1.data, d_share1.len));
220216
break;
221217
}
222218
case kOtcryptoRsaSize3072: {
@@ -228,11 +224,7 @@ otcrypto_status_t otcrypto_rsa_private_key_from_exponents(
228224
(rsa_3072_private_key_t *)private_key->keyblob;
229225
HARDENED_TRY(hardened_memcpy(sk->n.data, modulus.data, modulus.len));
230226
HARDENED_TRY(hardened_memcpy(sk->d0.data, d_share0.data, d_share0.len));
231-
// TODO: RSA keys are currently unblinded, so combine the shares.
232-
for (size_t i = 0; i < d_share1.len; i++) {
233-
sk->d0.data[i] ^= d_share1.data[i];
234-
sk->d1.data[i] = 0x0;
235-
}
227+
HARDENED_TRY(hardened_memcpy(sk->d1.data, d_share1.data, d_share1.len));
236228
break;
237229
}
238230
case kOtcryptoRsaSize4096: {
@@ -244,11 +236,7 @@ otcrypto_status_t otcrypto_rsa_private_key_from_exponents(
244236
(rsa_4096_private_key_t *)private_key->keyblob;
245237
HARDENED_TRY(hardened_memcpy(sk->n.data, modulus.data, modulus.len));
246238
HARDENED_TRY(hardened_memcpy(sk->d0.data, d_share0.data, d_share0.len));
247-
// TODO: RSA keys are currently unblinded, so combine the shares.
248-
for (size_t i = 0; i < d_share1.len; i++) {
249-
sk->d0.data[i] ^= d_share1.data[i];
250-
sk->d1.data[i] = 0x0;
251-
}
239+
HARDENED_TRY(hardened_memcpy(sk->d1.data, d_share1.data, d_share1.len));
252240
break;
253241
}
254242
default:

0 commit comments

Comments
 (0)