-/* $OpenBSD: aes_core.c,v 1.20 2024/03/29 04:39:54 jsing Exp $ */
+/* $OpenBSD: aes_core.c,v 1.21 2024/03/29 11:00:57 jsing Exp $ */
/**
* rijndael-alg-fst.c
*
#include "aes_local.h"
#include "crypto_internal.h"
-#if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) && \
- !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL)
+#if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) || \
+ !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL) || \
+ !defined(HAVE_AES_ENCRYPT_INTERNAL) || \
+ !defined(HAVE_AES_DECRYPT_INTERNAL)
/*
Te0[x] = S [x].[02, 01, 01, 03];
0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U,
0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU,
};
+#endif
+
+#if !defined(HAVE_AES_SET_ENCRYPT_KEY_INTERNAL) || \
+ !defined(HAVE_AES_SET_DECRYPT_KEY_INTERNAL)
static const u32 rcon[] = {
0x01000000, 0x02000000, 0x04000000, 0x08000000,
0x10000000, 0x20000000, 0x40000000, 0x80000000,
return aes_set_decrypt_key_internal(userKey, bits, key);
}
-#ifndef AES_ASM
+#ifdef HAVE_AES_ENCRYPT_INTERNAL
+void aes_encrypt_internal(const unsigned char *in, unsigned char *out,
+ const AES_KEY *key);
+
+#else
/*
- * Encrypt a single block
- * in and out can overlap
+ * Encrypt a single block - in and out can overlap.
*/
-void
-AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
+static inline void
+aes_encrypt_internal(const unsigned char *in, unsigned char *out,
+ const AES_KEY *key)
{
const u32 *rk;
u32 s0, s1, s2, s3, t0, t1, t2, t3;
rk[3];
crypto_store_htobe32(&out[3 * 4], s3);
}
+#endif
+
+void
+AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
+{
+ return aes_encrypt_internal(in, out, key);
+}
+
+#ifdef HAVE_AES_DECRYPT_INTERNAL
+void aes_decrypt_internal(const unsigned char *in, unsigned char *out,
+ const AES_KEY *key);
+#else
/*
- * Decrypt a single block
- * in and out can overlap
+ * Decrypt a single block - in and out can overlap.
*/
-void
-AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
+static inline void
+aes_decrypt_internal(const unsigned char *in, unsigned char *out,
+ const AES_KEY *key)
{
const u32 *rk;
u32 s0, s1, s2, s3, t0, t1, t2, t3;
rk[3];
crypto_store_htobe32(&out[3 * 4], s3);
}
-#endif /* AES_ASM */
+#endif
+
+void
+AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
+{
+ return aes_decrypt_internal(in, out, key);
+}
&data_word(0x00000000, 0x00000000, 0x00000000, 0x00000000);
&previous();
-# void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
-&function_begin("AES_encrypt");
+# void aes_encrypt_internal(const void *inp, void *out, const AES_KEY *key);
+&function_begin("aes_encrypt_internal");
&mov ($acc,&wparam(0)); # load inp
&mov ($key,&wparam(2)); # load key
&mov (&DWP(4,$acc),$s1);
&mov (&DWP(8,$acc),$s2);
&mov (&DWP(12,$acc),$s3);
-&function_end("AES_encrypt");
+&function_end("aes_encrypt_internal");
#--------------------------------------------------------------------#
&data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
&previous();
-# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
-&function_begin("AES_decrypt");
+# void aes_decrypt_internal(const void *inp, void *out, const AES_KEY *key);
+&function_begin("aes_decrypt_internal");
&mov ($acc,&wparam(0)); # load inp
&mov ($key,&wparam(2)); # load key
&mov (&DWP(4,$acc),$s1);
&mov (&DWP(8,$acc),$s2);
&mov (&DWP(12,$acc),$s3);
-&function_end("AES_decrypt");
+&function_end("aes_decrypt_internal");
# void aes_cbc_encrypt_internal(const void char *inp, unsigned char *out,
# size_t length, const AES_KEY *key, unsigned char *ivp,const int enc);
.word 0x1B000000, 0x36000000, 0, 0, 0, 0, 0, 0
.size AES_Te,.-AES_Te
-@ void AES_encrypt(const unsigned char *in, unsigned char *out,
-@ const AES_KEY *key) {
-.global AES_encrypt
-.type AES_encrypt,%function
+@ void aes_encrypt_internal(const unsigned char *in, unsigned char *out,
+@ const AES_KEY *key) {
+.global aes_encrypt_internal
+.type aes_encrypt_internal,%function
.align 5
-AES_encrypt:
- sub r3,pc,#8 @ AES_encrypt
+aes_encrypt_internal:
+ sub r3,pc,#8 @ aes_encrypt_internal
stmdb sp!,{r1,r4-r12,lr}
mov $rounds,r0 @ inp
mov $key,r2
- sub $tbl,r3,#AES_encrypt-AES_Te @ Te
+ sub $tbl,r3,#aes_encrypt_internal-AES_Te @ Te
#if __ARM_ARCH__<7 || defined(__STRICT_ALIGNMENT)
ldrb $s0,[$rounds,#3] @ load input data in endian-neutral
ldrb $t1,[$rounds,#2] @ manner...
moveq pc,lr @ be binary compatible with V4, yet
bx lr @ interoperable with Thumb ISA:-)
#endif
-.size AES_encrypt,.-AES_encrypt
+.size aes_encrypt_internal,.-aes_encrypt_internal
.type _armv4_AES_encrypt,%function
.align 2
.byte 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
.size AES_Td,.-AES_Td
-@ void AES_decrypt(const unsigned char *in, unsigned char *out,
-@ const AES_KEY *key) {
-.global AES_decrypt
-.type AES_decrypt,%function
+@ void aes_decrypt_internal(const unsigned char *in, unsigned char *out,
+@ const AES_KEY *key) {
+.global aes_decrypt_internal
+.type aes_decrypt_internal,%function
.align 5
-AES_decrypt:
- sub r3,pc,#8 @ AES_decrypt
+aes_decrypt_internal:
+ sub r3,pc,#8 @ aes_decrypt_internal
stmdb sp!,{r1,r4-r12,lr}
mov $rounds,r0 @ inp
mov $key,r2
- sub $tbl,r3,#AES_decrypt-AES_Td @ Td
+ sub $tbl,r3,#aes_decrypt_internal-AES_Td @ Td
#if __ARM_ARCH__<7 || defined(__STRICT_ALIGNMENT)
ldrb $s0,[$rounds,#3] @ load input data in endian-neutral
ldrb $t1,[$rounds,#2] @ manner...
moveq pc,lr @ be binary compatible with V4, yet
bx lr @ interoperable with Thumb ISA:-)
#endif
-.size AES_decrypt,.-AES_decrypt
+.size aes_decrypt_internal,.-aes_decrypt_internal
.type _armv4_AES_decrypt,%function
.align 2
.end _mips_AES_encrypt
.align 5
-.globl AES_encrypt
-.ent AES_encrypt
-AES_encrypt:
+.globl aes_encrypt_internal
+.ent aes_encrypt_internal
+aes_encrypt_internal:
.frame $sp,$FRAMESIZE,$ra
.mask $SAVED_REGS_MASK,-$SZREG
.set noreorder
___
$code.=<<___ if ($flavour !~ /o32/i); # non-o32 PIC-ification
.cplocal $Tbl
- .cpsetup $pf,$zero,AES_encrypt
+ .cpsetup $pf,$zero,aes_encrypt_internal
___
$code.=<<___;
.set reorder
$code.=<<___;
jr $ra
$PTR_ADD $sp,$FRAMESIZE
-.end AES_encrypt
+.end aes_encrypt_internal
___
\f
$code.=<<___;
.end _mips_AES_decrypt
.align 5
-.globl AES_decrypt
-.ent AES_decrypt
-AES_decrypt:
+.globl aes_decrypt_internal
+.ent aes_decrypt_internal
+aes_decrypt_internal:
.frame $sp,$FRAMESIZE,$ra
.mask $SAVED_REGS_MASK,-$SZREG
.set noreorder
___
$code.=<<___ if ($flavour !~ /o32/i); # non-o32 PIC-ification
.cplocal $Tbl
- .cpsetup $pf,$zero,AES_decrypt
+ .cpsetup $pf,$zero,aes_decrypt_internal
___
$code.=<<___;
.set reorder
$code.=<<___;
jr $ra
$PTR_ADD $sp,$FRAMESIZE
-.end AES_decrypt
+.end aes_decrypt_internal
___
}}}
\f
.LEVEL $LEVEL
.text
- .EXPORT AES_encrypt,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR
+ .EXPORT aes_encrypt_internal,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR
.ALIGN 64
-AES_encrypt
+aes_encrypt_internal
.PROC
.CALLINFO FRAME=`$FRAME-16*$SIZE_T`,NO_CALLS,SAVE_RP,ENTRY_GR=18
.ENTRY
___
$code.=<<___;
- .EXPORT AES_decrypt,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR
+ .EXPORT aes_decrypt_internal,ENTRY,ARGW0=GR,ARGW1=GR,ARGW2=GR
.ALIGN 16
-AES_decrypt
+aes_decrypt_internal
.PROC
.CALLINFO FRAME=`$FRAME-16*$SIZE_T`,NO_CALLS,SAVE_RP,ENTRY_GR=18
.ENTRY
.byte 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
-.globl .AES_encrypt
+.globl .aes_encrypt_internal
.align 7
-.AES_encrypt:
+.aes_encrypt_internal:
$STU $sp,-$FRAME($sp)
mflr r0
xor $s3,$s3,$t3
blr
-.globl .AES_decrypt
+.globl .aes_decrypt_internal
.align 7
-.AES_decrypt:
+.aes_decrypt_internal:
$STU $sp,-$FRAME($sp)
mflr r0
.size _sparcv9_AES_encrypt,(.-_sparcv9_AES_encrypt)
.align 32
-.globl AES_encrypt
-AES_encrypt:
+.globl aes_encrypt_internal
+aes_encrypt_internal:
save %sp,-$frame,%sp
#ifdef __PIC__
sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %o5
ret
restore
-.type AES_encrypt,#function
-.size AES_encrypt,(.-AES_encrypt)
+.type aes_encrypt_internal,#function
+.size aes_encrypt_internal,(.-aes_encrypt_internal)
___
.size _sparcv9_AES_decrypt,(.-_sparcv9_AES_decrypt)
.align 32
-.globl AES_decrypt
-AES_decrypt:
+.globl aes_decrypt_internal
+aes_decrypt_internal:
save %sp,-$frame,%sp
#ifdef __PIC__
sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %o5
ret
restore
-.type AES_decrypt,#function
-.size AES_decrypt,(.-AES_decrypt)
+.type aes_decrypt_internal,#function
+.size aes_decrypt_internal,(.-aes_decrypt_internal)
___
# fmovs instructions substituting for FP nops were originally added
.size _x86_64_AES_encrypt_compact,.-_x86_64_AES_encrypt_compact
___
-# void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
+# void aes_encrypt_internal(const void *inp, void *out, const AES_KEY *key);
$code.=<<___;
-.globl AES_encrypt
-.type AES_encrypt,\@function,3
+.globl aes_encrypt_internal
+.type aes_encrypt_internal,\@function,3
.align 16
.globl asm_AES_encrypt
.hidden asm_AES_encrypt
asm_AES_encrypt:
-AES_encrypt:
+aes_encrypt_internal:
_CET_ENDBR
push %rbx
push %rbp
lea 48(%rsi),%rsp
.Lenc_epilogue:
ret
-.size AES_encrypt,.-AES_encrypt
+.size aes_encrypt_internal,.-aes_encrypt_internal
___
#------------------------------------------------------------------#
.size _x86_64_AES_decrypt_compact,.-_x86_64_AES_decrypt_compact
___
-# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
+# void aes_decrypt_internal(const void *inp, void *out, const AES_KEY *key);
$code.=<<___;
-.globl AES_decrypt
-.type AES_decrypt,\@function,3
+.globl aes_decrypt_internal
+.type aes_decrypt_internal,\@function,3
.align 16
.globl asm_AES_decrypt
.hidden asm_AES_decrypt
asm_AES_decrypt:
-AES_decrypt:
+aes_decrypt_internal:
_CET_ENDBR
push %rbx
push %rbp
lea 48(%rsi),%rsp
.Ldec_epilogue:
ret
-.size AES_decrypt,.-AES_decrypt
+.size aes_decrypt_internal,.-aes_decrypt_internal
___
#------------------------------------------------------------------#
.section .pdata
.align 4
- .rva .LSEH_begin_AES_encrypt
- .rva .LSEH_end_AES_encrypt
- .rva .LSEH_info_AES_encrypt
+ .rva .LSEH_begin_aes_encrypt_internal
+ .rva .LSEH_end_aes_encrypt_internal
+ .rva .LSEH_info_aes_encrypt_internal
- .rva .LSEH_begin_AES_decrypt
- .rva .LSEH_end_AES_decrypt
- .rva .LSEH_info_AES_decrypt
+ .rva .LSEH_begin_aes_decrypt_internal
+ .rva .LSEH_end_aes_decrypt_internal
+ .rva .LSEH_info_aes_decrypt_internal
.rva .LSEH_begin_aes_set_encrypt_key_internal
.rva .LSEH_end_aes_set_encrypt_key_internal
.section .xdata
.align 8
-.LSEH_info_AES_encrypt:
+.LSEH_info_aes_encrypt_internal:
.byte 9,0,0,0
.rva block_se_handler
.rva .Lenc_prologue,.Lenc_epilogue # HandlerData[]
-.LSEH_info_AES_decrypt:
+.LSEH_info_aes_decrypt_internal:
.byte 9,0,0,0
.rva block_se_handler
.rva .Ldec_prologue,.Ldec_epilogue # HandlerData[]
-# $OpenBSD: Makefile.inc,v 1.26 2024/03/29 07:24:09 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.27 2024/03/29 11:00:57 jsing Exp $
# amd64-specific libcrypto build rules
CFLAGS+= -DHAVE_AES_CBC_ENCRYPT_INTERNAL
CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_DECRYPT_INTERNAL
# bn
CFLAGS+= -DOPENSSL_IA32_SSE2
CFLAGS+= -DRSA_ASM
SSLASM+= aes aes-armv4
CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_DECRYPT_INTERNAL
# bn
CFLAGS+= -DOPENSSL_BN_ASM_MONT
SSLASM+= bn armv4-mont
-# $OpenBSD: Makefile.inc,v 1.23 2024/03/29 07:24:09 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.24 2024/03/29 11:00:57 jsing Exp $
# hppa-specific libcrypto build rules
# aes
CFLAGS+= -DAES_ASM
SSLASM+= aes aes-parisc aes-parisc
+CFLAGS+= -DHAVE_AES_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_DECRYPT_INTERNAL
# bn
SSLASM+= bn parisc-mont parisc-mont
CFLAGS+= -DOPENSSL_BN_ASM_MONT -DBN_DIV2W
-# $OpenBSD: Makefile.inc,v 1.23 2024/03/29 07:24:09 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.24 2024/03/29 11:00:57 jsing Exp $
# i386-specific libcrypto build rules
CFLAGS+= -DHAVE_AES_CBC_ENCRYPT_INTERNAL
CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_DECRYPT_INTERNAL
# bn
CFLAGS+= -DOPENSSL_IA32_SSE2
SSLASM+= bn bn-586
-# $OpenBSD: Makefile.inc,v 1.16 2024/03/29 07:24:09 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.17 2024/03/29 11:00:57 jsing Exp $
# mips64-specific libcrypto build rules
SSLASM+= aes aes-mips aes-mips
CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_DECRYPT_INTERNAL
# bn
SSLASM+= bn mips bn-mips
SSLASM+= bn mips-mont mips-mont
-# $OpenBSD: Makefile.inc,v 1.17 2024/03/29 07:24:09 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.18 2024/03/29 11:00:57 jsing Exp $
# sparc64-specific libcrypto build rules
# aes
CFLAGS+= -DAES_ASM
SSLASM+= aes aes-sparcv9 aes-sparcv9
+CFLAGS+= -DHAVE_AES_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_DECRYPT_INTERNAL
# bn
# modes
CFLAGS+= -DGHASH_ASM