Skip to content

Commit 885c13f

Browse files
committed
[cryptolib] Check loop counter in KMAC driver
To mitigate fault attacks, check if we have executed the number of expected loop rounds. Signed-off-by: Pascal Nasahl <[email protected]>
1 parent 97b690f commit 885c13f

File tree

1 file changed

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

1 file changed

+4
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,16 @@ static status_t kmac_process_msg_blocks(kmac_operation_t operation,
650650
uint32_t next_word = read_32(&message[i]);
651651
abs_mmio_write32(kBase + KMAC_MSG_FIFO_REG_OFFSET, next_word);
652652
}
653+
// Check that the loops ran for the correct number of iterations.
654+
HARDENED_CHECK_LT(message_len, i + sizeof(uint32_t));
653655

654656
// For the last few bytes, we need to write one byte at a time again.
655657
for (; i < message_len; i++) {
656658
HARDENED_TRY(wait_status_bit(KMAC_STATUS_FIFO_FULL_BIT, 0));
657659
abs_mmio_write8(kmac_base() + KMAC_MSG_FIFO_REG_OFFSET, message[i]);
658660
}
661+
// Check that the loops ran for the correct number of iterations.
662+
HARDENED_CHECK_EQ(i, message_len);
659663

660664
// If operation=KMAC, then we need to write `right_encode(digest->len)`
661665
if (operation == kKmacOperationKmac) {

0 commit comments

Comments
 (0)