diff options
| author | jsing <> | 2025-09-08 12:56:17 +0000 |
|---|---|---|
| committer | jsing <> | 2025-09-08 12:56:17 +0000 |
| commit | edb41402990165c33fbbe4972a505d2b907f57b5 (patch) | |
| tree | daa72754af93ced1ffe1d8665b2a3c371ea95b64 /src/lib | |
| parent | 0b23e36dfa750e5a98824fc469f69a27c5f25d3b (diff) | |
| download | openbsd-edb41402990165c33fbbe4972a505d2b907f57b5.tar.gz openbsd-edb41402990165c33fbbe4972a505d2b907f57b5.tar.bz2 openbsd-edb41402990165c33fbbe4972a505d2b907f57b5.zip | |
Allow generic AES implementation to be used as a fallback.
Rename the C based AES implementation to *_generic() and provide
*_internal() wrappers for these. This allows for architectures to provide
accelerated versions without having to also provide a fallback
implementation.
ok tb@
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/libcrypto/aes/aes_core.c | 70 | ||||
| -rw-r--r-- | src/lib/libcrypto/arch/amd64/crypto_arch.h | 7 | ||||
| -rw-r--r-- | src/lib/libcrypto/arch/i386/crypto_arch.h | 7 |
3 files changed, 65 insertions, 19 deletions
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c index 2311547100..d892ae771a 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.28 2025/09/08 12:46:38 jsing Exp $ */ | 1 | /* $OpenBSD: aes_core.c,v 1.29 2025/09/08 12:56:17 jsing Exp $ */ |
| 2 | /** | 2 | /** |
| 3 | * rijndael-alg-fst.c | 3 | * rijndael-alg-fst.c |
| 4 | * | 4 | * |
| @@ -51,10 +51,10 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e]; | |||
| 51 | Td4[x] = Si[x].[01]; | 51 | Td4[x] = Si[x].[01]; |
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | #if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) || \ | 54 | #if !defined(HAVE_AES_SET_ENCRYPT_KEY_GENERIC) || \ |
| 55 | !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL) || \ | 55 | !defined(HAVE_AES_SET_DECRYPT_KEY_GENERIC) || \ |
| 56 | !defined(HAVE_AES_ENCRYPT_INTERNAL) || \ | 56 | !defined(HAVE_AES_ENCRYPT_GENERIC) || \ |
| 57 | !defined(HAVE_AES_DECRYPT_INTERNAL) | 57 | !defined(HAVE_AES_DECRYPT_GENERIC) |
| 58 | static const uint32_t Te0[256] = { | 58 | static const uint32_t Te0[256] = { |
| 59 | 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, | 59 | 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, |
| 60 | 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, | 60 | 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, |
| @@ -586,8 +586,8 @@ static const uint32_t Td3[256] = { | |||
| 586 | }; | 586 | }; |
| 587 | #endif | 587 | #endif |
| 588 | 588 | ||
| 589 | #if !defined(HAVE_AES_ENCRYPT_INTERNAL) || \ | 589 | #if !defined(HAVE_AES_ENCRYPT_GENERIC) || \ |
| 590 | !defined(HAVE_AES_DECRYPT_INTERNAL) | 590 | !defined(HAVE_AES_DECRYPT_GENERIC) |
| 591 | static const uint8_t Td4[256] = { | 591 | static const uint8_t Td4[256] = { |
| 592 | 0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U, | 592 | 0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U, |
| 593 | 0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU, | 593 | 0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU, |
| @@ -624,8 +624,8 @@ static const uint8_t Td4[256] = { | |||
| 624 | }; | 624 | }; |
| 625 | #endif | 625 | #endif |
| 626 | 626 | ||
| 627 | #if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) || \ | 627 | #if !defined(HAVE_AES_SET_ENCRYPT_KEY_GENERIC) || \ |
| 628 | !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL) | 628 | !defined(HAVE_AES_SET_DECRYPT_KEY_GENERIC) |
| 629 | static const uint32_t rcon[] = { | 629 | static const uint32_t rcon[] = { |
| 630 | 0x01000000, 0x02000000, 0x04000000, 0x08000000, | 630 | 0x01000000, 0x02000000, 0x04000000, 0x08000000, |
| 631 | 0x10000000, 0x20000000, 0x40000000, 0x80000000, | 631 | 0x10000000, 0x20000000, 0x40000000, 0x80000000, |
| @@ -633,12 +633,12 @@ static const uint32_t rcon[] = { | |||
| 633 | }; | 633 | }; |
| 634 | #endif | 634 | #endif |
| 635 | 635 | ||
| 636 | #ifndef HAVE_AES_SET_ENCRYPT_KEY_INTERNAL | 636 | #ifndef HAVE_AES_SET_ENCRYPT_KEY_GENERIC |
| 637 | /* | 637 | /* |
| 638 | * Expand the cipher key into the encryption key schedule. | 638 | * Expand the cipher key into the encryption key schedule. |
| 639 | */ | 639 | */ |
| 640 | int | 640 | int |
| 641 | aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits, | 641 | aes_set_encrypt_key_generic(const unsigned char *userKey, const int bits, |
| 642 | AES_KEY *key) | 642 | AES_KEY *key) |
| 643 | { | 643 | { |
| 644 | uint32_t *rk; | 644 | uint32_t *rk; |
| @@ -725,12 +725,21 @@ aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits, | |||
| 725 | } | 725 | } |
| 726 | #endif | 726 | #endif |
| 727 | 727 | ||
| 728 | #ifndef HAVE_AES_SET_DECRYPT_KEY_INTERNAL | 728 | #ifndef HAVE_AES_SET_ENCRYPT_KEY_INTERNAL |
| 729 | int | ||
| 730 | aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits, | ||
| 731 | AES_KEY *key) | ||
| 732 | { | ||
| 733 | return aes_set_encrypt_key_generic(userKey, bits, key); | ||
| 734 | } | ||
| 735 | #endif | ||
| 736 | |||
| 737 | #ifndef HAVE_AES_SET_DECRYPT_KEY_GENERIC | ||
| 729 | /* | 738 | /* |
| 730 | * Expand the cipher key into the decryption key schedule. | 739 | * Expand the cipher key into the decryption key schedule. |
| 731 | */ | 740 | */ |
| 732 | int | 741 | int |
| 733 | aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits, | 742 | aes_set_decrypt_key_generic(const unsigned char *userKey, const int bits, |
| 734 | AES_KEY *key) | 743 | AES_KEY *key) |
| 735 | { | 744 | { |
| 736 | uint32_t *rk; | 745 | uint32_t *rk; |
| @@ -786,12 +795,21 @@ aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits, | |||
| 786 | } | 795 | } |
| 787 | #endif | 796 | #endif |
| 788 | 797 | ||
| 789 | #ifndef HAVE_AES_ENCRYPT_INTERNAL | 798 | #ifndef HAVE_AES_SET_DECRYPT_KEY_INTERNAL |
| 799 | int | ||
| 800 | aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits, | ||
| 801 | AES_KEY *key) | ||
| 802 | { | ||
| 803 | return aes_set_decrypt_key_generic(userKey, bits, key); | ||
| 804 | } | ||
| 805 | #endif | ||
| 806 | |||
| 807 | #ifndef HAVE_AES_ENCRYPT_GENERIC | ||
| 790 | /* | 808 | /* |
| 791 | * Encrypt a single block - in and out can overlap. | 809 | * Encrypt a single block - in and out can overlap. |
| 792 | */ | 810 | */ |
| 793 | void | 811 | void |
| 794 | aes_encrypt_internal(const unsigned char *in, unsigned char *out, | 812 | aes_encrypt_generic(const unsigned char *in, unsigned char *out, |
| 795 | const AES_KEY *key) | 813 | const AES_KEY *key) |
| 796 | { | 814 | { |
| 797 | const uint32_t *rk; | 815 | const uint32_t *rk; |
| @@ -978,12 +996,21 @@ aes_encrypt_internal(const unsigned char *in, unsigned char *out, | |||
| 978 | } | 996 | } |
| 979 | #endif | 997 | #endif |
| 980 | 998 | ||
| 981 | #ifndef HAVE_AES_DECRYPT_INTERNAL | 999 | #ifndef HAVE_AES_ENCRYPT_INTERNAL |
| 1000 | void | ||
| 1001 | aes_encrypt_internal(const unsigned char *in, unsigned char *out, | ||
| 1002 | const AES_KEY *key) | ||
| 1003 | { | ||
| 1004 | aes_encrypt_generic(in, out, key); | ||
| 1005 | } | ||
| 1006 | #endif | ||
| 1007 | |||
| 1008 | #ifndef HAVE_AES_DECRYPT_GENERIC | ||
| 982 | /* | 1009 | /* |
| 983 | * Decrypt a single block - in and out can overlap. | 1010 | * Decrypt a single block - in and out can overlap. |
| 984 | */ | 1011 | */ |
| 985 | void | 1012 | void |
| 986 | aes_decrypt_internal(const unsigned char *in, unsigned char *out, | 1013 | aes_decrypt_generic(const unsigned char *in, unsigned char *out, |
| 987 | const AES_KEY *key) | 1014 | const AES_KEY *key) |
| 988 | { | 1015 | { |
| 989 | const uint32_t *rk; | 1016 | const uint32_t *rk; |
| @@ -1169,3 +1196,12 @@ aes_decrypt_internal(const unsigned char *in, unsigned char *out, | |||
| 1169 | crypto_store_htobe32(&out[3 * 4], s3); | 1196 | crypto_store_htobe32(&out[3 * 4], s3); |
| 1170 | } | 1197 | } |
| 1171 | #endif | 1198 | #endif |
| 1199 | |||
| 1200 | #ifndef HAVE_AES_DECRYPT_INTERNAL | ||
| 1201 | void | ||
| 1202 | aes_decrypt_internal(const unsigned char *in, unsigned char *out, | ||
| 1203 | const AES_KEY *key) | ||
| 1204 | { | ||
| 1205 | aes_decrypt_generic(in, out, key); | ||
| 1206 | } | ||
| 1207 | #endif | ||
diff --git a/src/lib/libcrypto/arch/amd64/crypto_arch.h b/src/lib/libcrypto/arch/amd64/crypto_arch.h index a8f64cf235..9a179a571e 100644 --- a/src/lib/libcrypto/arch/amd64/crypto_arch.h +++ b/src/lib/libcrypto/arch/amd64/crypto_arch.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: crypto_arch.h,v 1.14 2025/08/14 15:11:01 jsing Exp $ */ | 1 | /* $OpenBSD: crypto_arch.h,v 1.15 2025/09/08 12:56:17 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -33,6 +33,11 @@ extern uint64_t crypto_cpu_caps_amd64; | |||
| 33 | 33 | ||
| 34 | #ifndef OPENSSL_NO_ASM | 34 | #ifndef OPENSSL_NO_ASM |
| 35 | 35 | ||
| 36 | #define HAVE_AES_SET_ENCRYPT_KEY_GENERIC | ||
| 37 | #define HAVE_AES_SET_DECRYPT_KEY_GENERIC | ||
| 38 | #define HAVE_AES_ENCRYPT_GENERIC | ||
| 39 | #define HAVE_AES_DECRYPT_GENERIC | ||
| 40 | |||
| 36 | #define HAVE_AES_SET_ENCRYPT_KEY_INTERNAL | 41 | #define HAVE_AES_SET_ENCRYPT_KEY_INTERNAL |
| 37 | #define HAVE_AES_SET_DECRYPT_KEY_INTERNAL | 42 | #define HAVE_AES_SET_DECRYPT_KEY_INTERNAL |
| 38 | #define HAVE_AES_ENCRYPT_INTERNAL | 43 | #define HAVE_AES_ENCRYPT_INTERNAL |
diff --git a/src/lib/libcrypto/arch/i386/crypto_arch.h b/src/lib/libcrypto/arch/i386/crypto_arch.h index d2faa36e2e..522ed2788b 100644 --- a/src/lib/libcrypto/arch/i386/crypto_arch.h +++ b/src/lib/libcrypto/arch/i386/crypto_arch.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: crypto_arch.h,v 1.12 2025/07/22 09:18:02 jsing Exp $ */ | 1 | /* $OpenBSD: crypto_arch.h,v 1.13 2025/09/08 12:56:17 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2024 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -32,6 +32,11 @@ extern uint64_t crypto_cpu_caps_i386; | |||
| 32 | 32 | ||
| 33 | #ifndef OPENSSL_NO_ASM | 33 | #ifndef OPENSSL_NO_ASM |
| 34 | 34 | ||
| 35 | #define HAVE_AES_SET_ENCRYPT_KEY_GENERIC | ||
| 36 | #define HAVE_AES_SET_DECRYPT_KEY_GENERIC | ||
| 37 | #define HAVE_AES_ENCRYPT_GENERIC | ||
| 38 | #define HAVE_AES_DECRYPT_GENERIC | ||
| 39 | |||
| 35 | #define HAVE_AES_SET_ENCRYPT_KEY_INTERNAL | 40 | #define HAVE_AES_SET_ENCRYPT_KEY_INTERNAL |
| 36 | #define HAVE_AES_SET_DECRYPT_KEY_INTERNAL | 41 | #define HAVE_AES_SET_DECRYPT_KEY_INTERNAL |
| 37 | #define HAVE_AES_ENCRYPT_INTERNAL | 42 | #define HAVE_AES_ENCRYPT_INTERNAL |
