Skip to content

Commit 4187383

Browse files
committed
[crypto] Check LOAD_CHECKSUM when writing into DMEM
OTBN offers the feature to read back the checksum when writing data into memory. This commit extends the `otbn_dmem_write` function such that we compare the checksum computed by OTBN after writing to its memory to an expected checksum we compute on the fly. Signed-off-by: Pascal Nasahl <[email protected]> (cherry picked from commit 98c92ec)
1 parent 5965d75 commit 4187383

File tree

1 file changed

+4
-3
lines changed
  • sw/device/lib/crypto/drivers

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ status_t otbn_dmem_write(size_t num_words, const uint32_t *src,
130130
random_order_init(&order, num_words);
131131

132132
size_t count = 0;
133-
size_t expected_count = random_order_len(&order);
134133

135134
for (; launderw(count) < num_words; count = launderw(count) + 1) {
136135
// The value obtained from `advance()` is laundered, to prevent
@@ -143,7 +142,8 @@ status_t otbn_dmem_write(size_t num_words, const uint32_t *src,
143142
barrierw(idx);
144143

145144
// Perform the write.
146-
abs_mmio_write32(kBase + OTBN_DMEM_REG_OFFSET + dest + idx_word, src[idx]);
145+
abs_mmio_write32(kBase + OTBN_DMEM_REG_OFFSET + dest + idx_word,
146+
src[idx]);
147147

148148
// Update the CRC. According to the OTBN documentation, each CRC update
149149
// consists of 48-bit: {imem, idx, wdata}
@@ -163,7 +163,8 @@ status_t otbn_dmem_write(size_t num_words, const uint32_t *src,
163163
// Get the computed (expected) checksum, fetch the checksum from the OTBN
164164
// LOAD_CHECKSUM register, and compare both registers.
165165
uint32_t checksum_expected = crc32_finish(&ctx);
166-
uint32_t checksum = abs_mmio_read32(kBase + OTBN_LOAD_CHECKSUM_REG_OFFSET);
166+
uint32_t checksum =
167+
abs_mmio_read32(kBase + OTBN_LOAD_CHECKSUM_REG_OFFSET);
167168
HARDENED_CHECK_EQ(checksum, checksum_expected);
168169

169170
return OTCRYPTO_OK;

0 commit comments

Comments
 (0)