summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/aes/aes_core.c
diff options
context:
space:
mode:
authorjsing <>2024-03-29 11:00:57 +0000
committerjsing <>2024-03-29 11:00:57 +0000
commit75b82074adb4b78df59f9391f6cb70b6bb285522 (patch)
treef7c84b00ed5b9c6990e905b6d3cb91b87a46eab7 /src/lib/libcrypto/aes/aes_core.c
parentddc94e581bd0cb9a0de0d9dbc0091d0b640dacd8 (diff)
downloadopenbsd-75b82074adb4b78df59f9391f6cb70b6bb285522.tar.gz
openbsd-75b82074adb4b78df59f9391f6cb70b6bb285522.tar.bz2
openbsd-75b82074adb4b78df59f9391f6cb70b6bb285522.zip
Always use C functions for AES_{encrypt,decrypt}().
Always provide AES_{encrypt,decrypt}() 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.c54
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/*
44Te0[x] = S [x].[02, 01, 01, 03]; 46Te0[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)
619static const u32 rcon[] = { 625static 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
820void 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 */
818void 827static inline void
819AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) 828aes_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
1015void
1016AES_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
1022void 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 */
1008void 1029static inline void
1009AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) 1030aes_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
1217void
1218AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
1219{
1220 return aes_decrypt_internal(in, out, key);
1221}