Skip to content

Commit c023447

Browse files
committed
[crypto] Check if byte-copy was successful
After a byte-wise copy using randomized_bytecopy() use the function consttime_memeq_byte() to check if copying the data was successful. This is a FI mitigation. Closes #28753. Signed-off-by: Pascal Nasahl <[email protected]>
1 parent b827245 commit c023447

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

sw/device/lib/base/hardened_memory.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,17 @@ status_t randomized_bytecopy(void *restrict dest, const void *restrict src,
257257
barrierw(byte_idx);
258258

259259
uint8_t *src_byte_idx = (uint8_t *)launderw(src_addr + byte_idx);
260-
// TODO(#8815) byte writes vs. word-wise integrity.
261260
uint8_t *dest_byte_idx = (uint8_t *)launderw(dest_addr + byte_idx);
262261

263262
*(dest_byte_idx) = *(src_byte_idx);
264263
}
265264
RANDOM_ORDER_HARDENED_CHECK_DONE(order);
266265
HARDENED_CHECK_EQ(count, byte_len);
267266

267+
// Check if copying the data was successful.
268+
HARDENED_CHECK_EQ(consttime_memeq_byte(dest, src, byte_len),
269+
kHardenedBoolTrue);
270+
268271
return OTCRYPTO_OK;
269272
}
270273

sw/device/lib/base/hardened_memory.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ status_t hardened_xor_in_place(uint32_t *OT_RESTRICT x,
146146
* Copy memory between non-overlapping regions with a randomized byte traversal.
147147
*
148148
* CAUTION! This function is not considered as secure as `hardened_memcpy` due
149-
* to the byte-sized memory accesses vs. 32b word accesses.
149+
* to the byte-sized memory accesses vs. 32b word accesses. After copying the
150+
* data, this function uses `consttime_memeq_byte()` to check if the data was
151+
* copied correctly.
150152
*
151153
* @param dest the region to copy to.
152154
* @param src the region to copy from.

0 commit comments

Comments
 (0)