Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions crypto/fipsmodule/aes/mode_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,47 @@
#include "../modes/internal.h"
#include "../cipher/internal.h"

// The following wrappers ensure that the delocator can handle the
// function pointer calculation in AES_ctr128_encrypt. Without it,
// on AArch64 there is risk of the calculations requiring a PC-relative
// offset outside of the range (-1MB,1MB) addressable using `ADR`.
static inline void aes_hw_ctr32_encrypt_blocks_wrapper(const uint8_t *in,
uint8_t *out, size_t len,
const AES_KEY *key,
const uint8_t ivec[16])
{
aes_hw_ctr32_encrypt_blocks(in, out, len, key, ivec);
}

#if defined(VPAES_CTR32)
static inline void vpaes_ctr32_encrypt_blocks_wrapper(const uint8_t *in,
uint8_t *out, size_t len,
const AES_KEY *key,
const uint8_t ivec[16]) {
vpaes_ctr32_encrypt_blocks(in, out, len, key, ivec);
}
#else // VPAES_CTR32
static inline void vpaes_encrypt_wrapper(const uint8_t *in, uint8_t *out,
const AES_KEY *key) {
vpaes_encrypt(in, out, key);
}
#endif // !VPAES_CTR32

void AES_ctr128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
const AES_KEY *key, uint8_t ivec[AES_BLOCK_SIZE],
uint8_t ecount_buf[AES_BLOCK_SIZE], unsigned int *num) {
if (hwaes_capable()) {
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, ivec, ecount_buf, num,
aes_hw_ctr32_encrypt_blocks);
aes_hw_ctr32_encrypt_blocks_wrapper);
} else if (vpaes_capable()) {
#if defined(VPAES_CTR32)
// TODO(davidben): On ARM, where |BSAES| is additionally defined, this could
// use |vpaes_ctr32_encrypt_blocks_with_bsaes|.
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, ivec, ecount_buf, num,
vpaes_ctr32_encrypt_blocks);
vpaes_ctr32_encrypt_blocks_wrapper);
#else
CRYPTO_ctr128_encrypt(in, out, len, key, ivec, ecount_buf, num,
vpaes_encrypt);
vpaes_encrypt_wrapper);
#endif
} else {
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, ivec, ecount_buf, num,
Expand Down