Skip to content

Commit 7533439

Browse files
h-filalivogelpi
authored andcommitted
[sw,cryptolib] Remove AES todos for using hardened memcpy
This PR removes TODOs in aes.c that have to do with using hardened mem copy for byte aligned buffers. This is not necessary and we can remove the TODOs. Signed-off-by: Hakim Filali <[email protected]>
1 parent c5cb21f commit 7533439

File tree

1 file changed

+9
-3
lines changed
  • sw/device/lib/crypto/impl

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ static status_t get_block(otcrypto_const_byte_buf_t input,
247247
HARDENED_CHECK_LT(index, num_full_blocks);
248248
// No need to worry about padding, just copy the data into the output
249249
// block.
250-
// TODO(#17711) Change to `hardened_memcpy`.
250+
// Byte buffers passed as input may not be word-aligned, so we cannot
251+
// use `hardened_memcpy`.
252+
// This is acceptable because the data is non-sensitive.
251253
memcpy(block->data, &input.data[index * kAesBlockNumBytes],
252254
kAesBlockNumBytes);
253255
return OTCRYPTO_OK;
@@ -414,7 +416,9 @@ static otcrypto_status_t otcrypto_aes_impl(
414416
HARDENED_TRY(get_block(cipher_input, aes_padding, i, &block_in));
415417
HARDENED_TRY(hardened_memshred(block_out.data, ARRAYSIZE(block_out.data)));
416418
HARDENED_TRY(aes_update(&block_out, &block_in));
417-
// TODO(#17711) Change to `hardened_memcpy`.
419+
// Byte buffers passed as input may not be word-aligned, so we cannot
420+
// use `hardened_memcpy`.
421+
// This is acceptable because the data is non-sensitive.
418422
memcpy(&cipher_output.data[(i - block_offset) * kAesBlockNumBytes],
419423
block_out.data, kAesBlockNumBytes);
420424
}
@@ -425,7 +429,9 @@ static otcrypto_status_t otcrypto_aes_impl(
425429
// input).
426430
for (i = block_offset; i > 0; --i) {
427431
HARDENED_TRY(aes_update(&block_out, /*src=*/NULL));
428-
// TODO(#17711) Change to `hardened_memcpy`.
432+
// Byte buffers passed as input may not be word-aligned, so we cannot
433+
// use `hardened_memcpy`.
434+
// This is acceptable because the data is non-sensitive.
429435
memcpy(&cipher_output.data[(input_nblocks - i) * kAesBlockNumBytes],
430436
block_out.data, kAesBlockNumBytes);
431437
}

0 commit comments

Comments
 (0)