Skip to content

Commit 1250168

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 1250168

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

sw/device/lib/base/hardened_memory.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ status_t randomized_bytecopy(void *restrict dest, const void *restrict src,
265265
RANDOM_ORDER_HARDENED_CHECK_DONE(order);
266266
HARDENED_CHECK_EQ(count, byte_len);
267267

268+
// Check if copying the data was successful.
269+
HARDENED_CHECK_EQ(consttime_memeq_byte(dest, src, byte_len),
270+
kHardenedBoolTrue);
271+
268272
return OTCRYPTO_OK;
269273
}
270274

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)