diff options
Diffstat (limited to 'src/lib/libcrypto/aes/aes_core.c')
-rw-r--r-- | src/lib/libcrypto/aes/aes_core.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c index ee0bbb9f40..bf5149d833 100644 --- a/src/lib/libcrypto/aes/aes_core.c +++ b/src/lib/libcrypto/aes/aes_core.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: aes_core.c,v 1.20 2024/03/29 04:39:54 jsing Exp $ */ | 1 | /* $OpenBSD: aes_core.c,v 1.21 2024/03/29 11:00:57 jsing Exp $ */ |
2 | /** | 2 | /** |
3 | * rijndael-alg-fst.c | 3 | * rijndael-alg-fst.c |
4 | * | 4 | * |
@@ -37,8 +37,10 @@ | |||
37 | #include "aes_local.h" | 37 | #include "aes_local.h" |
38 | #include "crypto_internal.h" | 38 | #include "crypto_internal.h" |
39 | 39 | ||
40 | #if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) && \ | 40 | #if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) || \ |
41 | !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL) | 41 | !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL) || \ |
42 | !defined(HAVE_AES_ENCRYPT_INTERNAL) || \ | ||
43 | !defined(HAVE_AES_DECRYPT_INTERNAL) | ||
42 | 44 | ||
43 | /* | 45 | /* |
44 | Te0[x] = S [x].[02, 01, 01, 03]; | 46 | Te0[x] = S [x].[02, 01, 01, 03]; |
@@ -616,6 +618,10 @@ static const u8 Td4[256] = { | |||
616 | 0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U, | 618 | 0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U, |
617 | 0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU, | 619 | 0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU, |
618 | }; | 620 | }; |
621 | #endif | ||
622 | |||
623 | #if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) || \ | ||
624 | !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL) | ||
619 | static const u32 rcon[] = { | 625 | static const u32 rcon[] = { |
620 | 0x01000000, 0x02000000, 0x04000000, 0x08000000, | 626 | 0x01000000, 0x02000000, 0x04000000, 0x08000000, |
621 | 0x10000000, 0x20000000, 0x40000000, 0x80000000, | 627 | 0x10000000, 0x20000000, 0x40000000, 0x80000000, |
@@ -810,13 +816,17 @@ AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) | |||
810 | return aes_set_decrypt_key_internal(userKey, bits, key); | 816 | return aes_set_decrypt_key_internal(userKey, bits, key); |
811 | } | 817 | } |
812 | 818 | ||
813 | #ifndef AES_ASM | 819 | #ifdef HAVE_AES_ENCRYPT_INTERNAL |
820 | void aes_encrypt_internal(const unsigned char *in, unsigned char *out, | ||
821 | const AES_KEY *key); | ||
822 | |||
823 | #else | ||
814 | /* | 824 | /* |
815 | * Encrypt a single block | 825 | * Encrypt a single block - in and out can overlap. |
816 | * in and out can overlap | ||
817 | */ | 826 | */ |
818 | void | 827 | static inline void |
819 | AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) | 828 | aes_encrypt_internal(const unsigned char *in, unsigned char *out, |
829 | const AES_KEY *key) | ||
820 | { | 830 | { |
821 | const u32 *rk; | 831 | const u32 *rk; |
822 | u32 s0, s1, s2, s3, t0, t1, t2, t3; | 832 | u32 s0, s1, s2, s3, t0, t1, t2, t3; |
@@ -1000,13 +1010,25 @@ AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) | |||
1000 | rk[3]; | 1010 | rk[3]; |
1001 | crypto_store_htobe32(&out[3 * 4], s3); | 1011 | crypto_store_htobe32(&out[3 * 4], s3); |
1002 | } | 1012 | } |
1013 | #endif | ||
1014 | |||
1015 | void | ||
1016 | AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) | ||
1017 | { | ||
1018 | return aes_encrypt_internal(in, out, key); | ||
1019 | } | ||
1020 | |||
1021 | #ifdef HAVE_AES_DECRYPT_INTERNAL | ||
1022 | void aes_decrypt_internal(const unsigned char *in, unsigned char *out, | ||
1023 | const AES_KEY *key); | ||
1003 | 1024 | ||
1025 | #else | ||
1004 | /* | 1026 | /* |
1005 | * Decrypt a single block | 1027 | * Decrypt a single block - in and out can overlap. |
1006 | * in and out can overlap | ||
1007 | */ | 1028 | */ |
1008 | void | 1029 | static inline void |
1009 | AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) | 1030 | aes_decrypt_internal(const unsigned char *in, unsigned char *out, |
1031 | const AES_KEY *key) | ||
1010 | { | 1032 | { |
1011 | const u32 *rk; | 1033 | const u32 *rk; |
1012 | u32 s0, s1, s2, s3, t0, t1, t2, t3; | 1034 | u32 s0, s1, s2, s3, t0, t1, t2, t3; |
@@ -1190,4 +1212,10 @@ AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) | |||
1190 | rk[3]; | 1212 | rk[3]; |
1191 | crypto_store_htobe32(&out[3 * 4], s3); | 1213 | crypto_store_htobe32(&out[3 * 4], s3); |
1192 | } | 1214 | } |
1193 | #endif /* AES_ASM */ | 1215 | #endif |
1216 | |||
1217 | void | ||
1218 | AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) | ||
1219 | { | ||
1220 | return aes_decrypt_internal(in, out, key); | ||
1221 | } | ||