Skip to content

Commit db6f08c

Browse files
nasahlpatimothytrippel
authored andcommitted
[crypto] eg100 specific fixes
Signed-off-by: Pascal Nasahl <[email protected]> (commit is original to earlgrey_1.0.0)
1 parent f51f449 commit db6f08c

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

sw/device/lib/crypto/drivers/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ opentitan_test(
5353
),
5454
deps = [
5555
":aes",
56+
":rv_core_ibex",
5657
"//sw/device/lib/base:macros",
5758
"//sw/device/lib/base:memory",
5859
"//sw/device/lib/crypto/impl:status",
@@ -228,6 +229,8 @@ dual_cc_library(
228229
"//hw/ip/rv_core_ibex/data:rv_core_ibex_c_regs",
229230
"//sw/device/lib/base:abs_mmio",
230231
"//sw/device/lib/base:csr",
232+
],
233+
shared = [
231234
"//sw/device/lib/base:hardened",
232235
"//sw/device/lib/crypto/impl:status",
233236
],

sw/device/lib/crypto/drivers/hmac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ status_t hmac_hash_sha512(const uint8_t *msg, size_t msg_len,
515515
}
516516

517517
status_t hmac_hmac_sha256_cl(const hmac_key_t *key, const uint8_t *msg,
518-
size_t msg_len, uint32_t *tag) {
518+
size_t msg_len, uint32_t *tag) {
519519
// Always configure the key length as the underlying message block size.
520520
uint32_t cfg = cfg_get(/*hmac_en=*/true, kDigestLengthSha256, kKeyLength512);
521521
return oneshot(cfg, key, msg, msg_len, kHmacSha256DigestWords, tag);

sw/device/lib/crypto/drivers/hmac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ status_t hmac_hash_sha512(const uint8_t *msg, size_t msg_len, uint32_t *digest);
137137
*/
138138
OT_WARN_UNUSED_RESULT
139139
status_t hmac_hmac_sha256_cl(const hmac_key_t *key, const uint8_t *msg,
140-
size_t msg_len, uint32_t *tag);
140+
size_t msg_len, uint32_t *tag);
141141

142142
/**
143143
* Redundant implementation for a one-shot HMAC-SHA256 hash computation.

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ otcrypto_status_t otcrypto_hmac(const otcrypto_blinded_key_t *key,
168168
HARDENED_CHECK_EQ(key->config.security_level,
169169
kOtcryptoKeySecurityLevelLow);
170170
return hmac_hmac_sha256_cl(&hmac_key, input_message.data,
171-
input_message.len, tag.data);
171+
input_message.len, tag.data);
172172
} else if (launder32(key->config.security_level) ==
173173
kOtcryptoKeySecurityLevelMedium) {
174174
// Call the HMAC core twice and compare both tags. This serves as a FI
@@ -177,14 +177,15 @@ otcrypto_status_t otcrypto_hmac(const otcrypto_blinded_key_t *key,
177177
HARDENED_CHECK_EQ(key->config.security_level,
178178
kOtcryptoKeySecurityLevelMedium);
179179
HARDENED_TRY(hmac_hmac_sha256_cl(&hmac_key, input_message.data,
180-
input_message.len, tag.data));
180+
input_message.len, tag.data));
181181
// Second HMAC computation using the HMAC core.
182182
uint32_t tag_redundant[tag.len];
183183
hmac_key_t hmac_key_redundant;
184184
HARDENED_TRY(hmac_key_construct(key, kHmacSha256BlockWords,
185185
&hmac_key_redundant));
186-
HARDENED_TRY(hmac_hmac_sha256_cl(&hmac_key_redundant, input_message.data,
187-
input_message.len, tag_redundant));
186+
HARDENED_TRY(hmac_hmac_sha256_cl(&hmac_key_redundant,
187+
input_message.data, input_message.len,
188+
tag_redundant));
188189
// Comparison of both tags.
189190
HARDENED_CHECK_EQ(
190191
hardened_memeq(&tag.data[0], &tag_redundant[0], tag.len),
@@ -198,7 +199,7 @@ otcrypto_status_t otcrypto_hmac(const otcrypto_blinded_key_t *key,
198199
kOtcryptoKeySecurityLevelHigh);
199200
// First HMAC computation using the HMAC core.
200201
HARDENED_TRY(hmac_hmac_sha256_cl(&hmac_key, input_message.data,
201-
input_message.len, tag.data));
202+
input_message.len, tag.data));
202203
// Second HMAC computation without using the HMAC core.
203204
uint32_t tag_redundant[tag.len];
204205
hmac_key_t hmac_key_redundant;

0 commit comments

Comments
 (0)