mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-23 05:51:11 +01:00
opencrypto: Respect alignment constraints in xor_and_encrypt()
Copy operands to an aligned buffer before performing operations which require alignment. Otherwise it's possible for this code to trigger an alignment fault on armv7. Reviewed by: jhb MFC after: 2 weeks Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D41211
This commit is contained in:
parent
1be56e0bb1
commit
96c2538121
@ -40,19 +40,16 @@ static void
|
|||||||
xor_and_encrypt(struct aes_cbc_mac_ctx *ctx,
|
xor_and_encrypt(struct aes_cbc_mac_ctx *ctx,
|
||||||
const uint8_t *src, uint8_t *dst)
|
const uint8_t *src, uint8_t *dst)
|
||||||
{
|
{
|
||||||
const uint64_t *b1;
|
#define NWORDS (CCM_CBC_BLOCK_LEN / sizeof(uint64_t))
|
||||||
uint64_t *b2;
|
uint64_t b1[NWORDS], b2[NWORDS], temp[NWORDS];
|
||||||
uint64_t temp_block[CCM_CBC_BLOCK_LEN/sizeof(uint64_t)];
|
|
||||||
|
|
||||||
b1 = (const uint64_t*)src;
|
memcpy(b1, src, CCM_CBC_BLOCK_LEN);
|
||||||
b2 = (uint64_t*)dst;
|
memcpy(b2, dst, CCM_CBC_BLOCK_LEN);
|
||||||
|
|
||||||
for (size_t count = 0;
|
for (size_t count = 0; count < NWORDS; count++)
|
||||||
count < CCM_CBC_BLOCK_LEN/sizeof(uint64_t);
|
temp[count] = b1[count] ^ b2[count];
|
||||||
count++) {
|
rijndaelEncrypt(ctx->keysched, ctx->rounds, (void *)temp, dst);
|
||||||
temp_block[count] = b1[count] ^ b2[count];
|
#undef NWORDS
|
||||||
}
|
|
||||||
rijndaelEncrypt(ctx->keysched, ctx->rounds, (void*)temp_block, dst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user