summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/aes/aes_core.c
diff options
context:
space:
mode:
authorjsing <>2024-03-29 04:39:54 +0000
committerjsing <>2024-03-29 04:39:54 +0000
commitf47c0b4977fbc17c426255c46c48c4c9f9df6470 (patch)
treea1b39a22ffa6878e5d55842b2b8dd27f8d732dd6 /src/lib/libcrypto/aes/aes_core.c
parent4fee8d380d60b85aa25e9d1380e28c0dc63fe5b0 (diff)
downloadopenbsd-f47c0b4977fbc17c426255c46c48c4c9f9df6470.tar.gz
openbsd-f47c0b4977fbc17c426255c46c48c4c9f9df6470.tar.bz2
openbsd-f47c0b4977fbc17c426255c46c48c4c9f9df6470.zip
Always use C functions for AES_set_{encrypt,decrypt}_key().
Always include aes_core.c and provide AES_set_{encrypt,decrypt}_key() via C functions, which then either use a C implementation or call the assembly implementation. ok tb@
Diffstat (limited to 'src/lib/libcrypto/aes/aes_core.c')
-rw-r--r--src/lib/libcrypto/aes/aes_core.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c
index bb1006acf1..ee0bbb9f40 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.19 2024/03/27 11:15:44 jsing Exp $ */ 1/* $OpenBSD: aes_core.c,v 1.20 2024/03/29 04:39:54 jsing Exp $ */
2/** 2/**
3 * rijndael-alg-fst.c 3 * rijndael-alg-fst.c
4 * 4 *
@@ -37,6 +37,9 @@
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) && \
41 !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL)
42
40/* 43/*
41Te0[x] = S [x].[02, 01, 01, 03]; 44Te0[x] = S [x].[02, 01, 01, 03];
42Te1[x] = S [x].[03, 02, 01, 01]; 45Te1[x] = S [x].[03, 02, 01, 01];
@@ -618,12 +621,20 @@ static const u32 rcon[] = {
618 0x10000000, 0x20000000, 0x40000000, 0x80000000, 621 0x10000000, 0x20000000, 0x40000000, 0x80000000,
619 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ 622 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
620}; 623};
624#endif
621 625
622/** 626#ifdef HAVE_AES_SET_ENCRYPT_KEY_INTERNAL
627int aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits,
628 AES_KEY *key);
629
630#else
631
632/*
623 * Expand the cipher key into the encryption key schedule. 633 * Expand the cipher key into the encryption key schedule.
624 */ 634 */
625int 635static inline int
626AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) 636aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits,
637 AES_KEY *key)
627{ 638{
628 u32 *rk; 639 u32 *rk;
629 int i = 0; 640 int i = 0;
@@ -719,12 +730,25 @@ AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
719 } 730 }
720 return 0; 731 return 0;
721} 732}
733#endif
722 734
723/** 735int
736AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
737{
738 return aes_set_encrypt_key_internal(userKey, bits, key);
739}
740
741#ifdef HAVE_AES_SET_DECRYPT_KEY_INTERNAL
742int aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits,
743 AES_KEY *key);
744
745#else
746/*
724 * Expand the cipher key into the decryption key schedule. 747 * Expand the cipher key into the decryption key schedule.
725 */ 748 */
726int 749static inline int
727AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) 750aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits,
751 AES_KEY *key)
728{ 752{
729 u32 *rk; 753 u32 *rk;
730 int i, j, status; 754 int i, j, status;
@@ -778,6 +802,13 @@ AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
778 } 802 }
779 return 0; 803 return 0;
780} 804}
805#endif
806
807int
808AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
809{
810 return aes_set_decrypt_key_internal(userKey, bits, key);
811}
781 812
782#ifndef AES_ASM 813#ifndef AES_ASM
783/* 814/*