| 1 |
// Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#include <openssl/aes.h> |
| 5 |
|
| 6 |
#include <assert.h> |
| 7 |
|
| 8 |
#include "internal.h" |
| 9 |
#include "../modes/internal.h" |
| 10 |
|
| 11 |
|
| 12 |
// Be aware that different sets of AES functions use incompatible key |
| 13 |
// representations, varying in format of the key schedule, the |AES_KEY.rounds| |
| 14 |
// value, or both. Therefore they cannot mix. Also, on AArch64, the plain-C |
| 15 |
// code, above, is incompatible with the |aes_hw_*| functions. |
| 16 |
|
| 17 |
void AES_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) { |
| 18 |
SET_DIT_AUTO_RESET; |
| 19 |
if (hwaes_capable()) { |
| 20 |
aes_hw_encrypt(in, out, key); |
| 21 |
} else if (vpaes_capable()) { |
| 22 |
vpaes_encrypt(in, out, key); |
| 23 |
} else { |
| 24 |
aes_nohw_encrypt(in, out, key); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
void AES_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) { |
| 29 |
SET_DIT_AUTO_RESET; |
| 30 |
if (hwaes_capable()) { |
| 31 |
aes_hw_decrypt(in, out, key); |
| 32 |
} else if (vpaes_capable()) { |
| 33 |
vpaes_decrypt(in, out, key); |
| 34 |
} else { |
| 35 |
aes_nohw_decrypt(in, out, key); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
int AES_set_encrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) { |
| 40 |
SET_DIT_AUTO_RESET; |
| 41 |
if (bits != 128 && bits != 192 && bits != 256) { |
| 42 |
return -2; |
| 43 |
} |
| 44 |
if (hwaes_capable()) { |
| 45 |
return aes_hw_set_encrypt_key(key, bits, aeskey); |
| 46 |
} else if (vpaes_capable()) { |
| 47 |
return vpaes_set_encrypt_key(key, bits, aeskey); |
| 48 |
} else { |
| 49 |
return aes_nohw_set_encrypt_key(key, bits, aeskey); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
int AES_set_decrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) { |
| 54 |
SET_DIT_AUTO_RESET; |
| 55 |
if (bits != 128 && bits != 192 && bits != 256) { |
| 56 |
return -2; |
| 57 |
} |
| 58 |
if (hwaes_capable()) { |
| 59 |
return aes_hw_set_decrypt_key(key, bits, aeskey); |
| 60 |
} else if (vpaes_capable()) { |
| 61 |
return vpaes_set_decrypt_key(key, bits, aeskey); |
| 62 |
} else { |
| 63 |
return aes_nohw_set_decrypt_key(key, bits, aeskey); |
| 64 |
} |
| 65 |
} |