-/* $OpenBSD: aes_core.c,v 1.19 2024/03/27 11:15:44 jsing Exp $ */
+/* $OpenBSD: aes_core.c,v 1.20 2024/03/29 04:39:54 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)
+
/*
Te0[x] = S [x].[02, 01, 01, 03];
Te1[x] = S [x].[03, 02, 01, 01];
0x10000000, 0x20000000, 0x40000000, 0x80000000,
0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
};
+#endif
-/**
+#ifdef HAVE_AES_SET_ENCRYPT_KEY_INTERNAL
+int aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits,
+ AES_KEY *key);
+
+#else
+
+/*
* Expand the cipher key into the encryption key schedule.
*/
-int
-AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
+static inline int
+aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits,
+ AES_KEY *key)
{
u32 *rk;
int i = 0;
}
return 0;
}
+#endif
-/**
+int
+AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
+{
+ return aes_set_encrypt_key_internal(userKey, bits, key);
+}
+
+#ifdef HAVE_AES_SET_DECRYPT_KEY_INTERNAL
+int aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits,
+ AES_KEY *key);
+
+#else
+/*
* Expand the cipher key into the decryption key schedule.
*/
-int
-AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
+static inline int
+aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits,
+ AES_KEY *key)
{
u32 *rk;
int i, j, status;
}
return 0;
}
+#endif
+
+int
+AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key)
+{
+ return aes_set_decrypt_key_internal(userKey, bits, key);
+}
#ifndef AES_ASM
/*
&set_label("exit");
&function_end("_x86_AES_set_encrypt_key");
-# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
-# AES_KEY *key)
-&function_begin_B("AES_set_encrypt_key");
+# int aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits,
+# AES_KEY *key)
+&function_begin_B("aes_set_encrypt_key_internal");
&call ("_x86_AES_set_encrypt_key");
&ret ();
-&function_end_B("AES_set_encrypt_key");
+&function_end_B("aes_set_encrypt_key_internal");
sub deckey()
{ my ($i,$key,$tp1,$tp2,$tp4,$tp8) = @_;
&mov (&DWP(4*$i,$key),$tp1);
}
-# int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
-# AES_KEY *key)
-&function_begin_B("AES_set_decrypt_key");
+# int aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits,
+# AES_KEY *key)
+&function_begin_B("aes_set_decrypt_key_internal");
&call ("_x86_AES_set_encrypt_key");
&cmp ("eax",0);
&je (&label("proceed"));
&jb (&label("permute"));
&xor ("eax","eax"); # return success
-&function_end("AES_set_decrypt_key");
+&function_end("aes_set_decrypt_key_internal");
&asm_finish();
ldr pc,[sp],#4 @ pop and return
.size _armv4_AES_encrypt,.-_armv4_AES_encrypt
-.global AES_set_encrypt_key
-.type AES_set_encrypt_key,%function
+.global aes_set_encrypt_key_internal
+.type aes_set_encrypt_key_internal,%function
.align 5
-AES_set_encrypt_key:
+aes_set_encrypt_key_internal:
_armv4_AES_set_encrypt_key:
- sub r3,pc,#8 @ AES_set_encrypt_key
+ sub r3,pc,#8 @ aes_set_encrypt_key_internal
teq r0,#0
moveq r0,#-1
beq .Labrt
.Labrt: tst lr,#1
moveq pc,lr @ be binary compatible with V4, yet
bx lr @ interoperable with Thumb ISA:-)
-.size AES_set_encrypt_key,.-AES_set_encrypt_key
+.size aes_set_encrypt_key_internal,.-aes_set_encrypt_key_internal
-.global AES_set_decrypt_key
-.type AES_set_decrypt_key,%function
+.global aes_set_decrypt_key_internal
+.type aes_set_decrypt_key_internal,%function
.align 5
-AES_set_decrypt_key:
+aes_set_decrypt_key_internal:
str lr,[sp,#-4]! @ push lr
bl _armv4_AES_set_encrypt_key
teq r0,#0
moveq pc,lr @ be binary compatible with V4, yet
bx lr @ interoperable with Thumb ISA:-)
#endif
-.size AES_set_decrypt_key,.-AES_set_decrypt_key
+.size aes_set_decrypt_key_internal,.-aes_set_decrypt_key_internal
.type AES_Td,%object
.align 5
nop
.end _mips_AES_set_encrypt_key
-.globl AES_set_encrypt_key
-.ent AES_set_encrypt_key
-AES_set_encrypt_key:
+.globl aes_set_encrypt_key_internal
+.ent aes_set_encrypt_key_internal
+aes_set_encrypt_key_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_set_encrypt_key
+ .cpsetup $pf,$zero,aes_set_encrypt_key_internal
___
$code.=<<___;
.set reorder
$code.=<<___;
jr $ra
$PTR_ADD $sp,$FRAMESIZE
-.end AES_set_encrypt_key
+.end aes_set_encrypt_key_internal
___
\f
my ($head,$tail)=($inp,$bits);
my ($m,$x80808080,$x7f7f7f7f,$x1b1b1b1b)=($at,$t0,$t1,$t2);
$code.=<<___;
.align 5
-.globl AES_set_decrypt_key
-.ent AES_set_decrypt_key
-AES_set_decrypt_key:
+.globl aes_set_decrypt_key_internal
+.ent aes_set_decrypt_key_internal
+aes_set_decrypt_key_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_set_decrypt_key
+ .cpsetup $pf,$zero,aes_set_decrypt_key_internal
___
$code.=<<___;
.set reorder
$code.=<<___;
jr $ra
$PTR_ADD $sp,$FRAMESIZE
-.end AES_set_decrypt_key
+.end aes_set_decrypt_key_internal
___
}}}
___
}
-# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
-# AES_KEY *key)
+# int aes_set_encrypt_key_internal(const unsigned char *userKey, const int bits,
+# AES_KEY *key)
$code.=<<___;
-.globl AES_set_encrypt_key
-.type AES_set_encrypt_key,\@function,3
+.globl aes_set_encrypt_key_internal
+.type aes_set_encrypt_key_internal,\@function,3
.align 16
-AES_set_encrypt_key:
+aes_set_encrypt_key_internal:
_CET_ENDBR
push %rbx
push %rbp
add \$56,%rsp
.Lenc_key_epilogue:
ret
-.size AES_set_encrypt_key,.-AES_set_encrypt_key
+.size aes_set_encrypt_key_internal,.-aes_set_encrypt_key_internal
.type _x86_64_AES_set_encrypt_key,\@abi-omnipotent
.align 16
___
}
-# int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
-# AES_KEY *key)
+# int aes_set_decrypt_key_internal(const unsigned char *userKey, const int bits,
+# AES_KEY *key)
$code.=<<___;
-.globl AES_set_decrypt_key
-.type AES_set_decrypt_key,\@function,3
+.globl aes_set_decrypt_key_internal
+.type aes_set_decrypt_key_internal,\@function,3
.align 16
-AES_set_decrypt_key:
+aes_set_decrypt_key_internal:
_CET_ENDBR
push %rbx
push %rbp
add \$56,%rsp
.Ldec_key_epilogue:
ret
-.size AES_set_decrypt_key,.-AES_set_decrypt_key
+.size aes_set_decrypt_key_internal,.-aes_set_decrypt_key_internal
___
# void aes_cbc_encrypt_internal(const void char *inp, unsigned char *out,
.rva .LSEH_end_AES_decrypt
.rva .LSEH_info_AES_decrypt
- .rva .LSEH_begin_AES_set_encrypt_key
- .rva .LSEH_end_AES_set_encrypt_key
- .rva .LSEH_info_AES_set_encrypt_key
+ .rva .LSEH_begin_aes_set_encrypt_key_internal
+ .rva .LSEH_end_aes_set_encrypt_key_internal
+ .rva .LSEH_info_aes_set_encrypt_key_internal
- .rva .LSEH_begin_AES_set_decrypt_key
- .rva .LSEH_end_AES_set_decrypt_key
- .rva .LSEH_info_AES_set_decrypt_key
+ .rva .LSEH_begin_aes_set_decrypt_key_internal
+ .rva .LSEH_end_aes_set_decrypt_key_internal
+ .rva .LSEH_info_aes_set_decrypt_key_internal
.rva .LSEH_begin_aes_cbc_encrypt_internal
.rva .LSEH_end_aes_cbc_encrypt_internal
.byte 9,0,0,0
.rva block_se_handler
.rva .Ldec_prologue,.Ldec_epilogue # HandlerData[]
-.LSEH_info_AES_set_encrypt_key:
+.LSEH_info_aes_set_encrypt_key_internal:
.byte 9,0,0,0
.rva key_se_handler
.rva .Lenc_key_prologue,.Lenc_key_epilogue # HandlerData[]
-.LSEH_info_AES_set_decrypt_key:
+.LSEH_info_aes_set_decrypt_key_internal:
.byte 9,0,0,0
.rva key_se_handler
.rva .Ldec_key_prologue,.Ldec_key_epilogue # HandlerData[]
-# $OpenBSD: Makefile.inc,v 1.22 2024/03/29 02:33:44 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.23 2024/03/29 04:39:54 jsing Exp $
# amd64-specific libcrypto build rules
SSLASM+= aes vpaes-x86_64
SSLASM+= aes aesni-x86_64
CFLAGS+= -DHAVE_AES_CBC_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+SRCS+= aes_core.c
# bn
CFLAGS+= -DOPENSSL_IA32_SSE2
CFLAGS+= -DRSA_ASM
# aes
CFLAGS+= -DAES_ASM
SSLASM+= aes aes-armv4
+CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+SRCS+= aes_core.c
# bn
CFLAGS+= -DOPENSSL_BN_ASM_MONT
SSLASM+= bn armv4-mont
-# $OpenBSD: Makefile.inc,v 1.19 2024/03/29 02:33:44 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.20 2024/03/29 04:39:54 jsing Exp $
# i386-specific libcrypto build rules
SSLASM+= aes vpaes-x86
SSLASM+= aes aesni-x86
CFLAGS+= -DHAVE_AES_CBC_ENCRYPT_INTERNAL
+CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+SRCS+= aes_core.c
# bn
CFLAGS+= -DOPENSSL_IA32_SSE2
SSLASM+= bn bn-586
-# $OpenBSD: Makefile.inc,v 1.13 2024/03/29 02:33:44 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.14 2024/03/29 04:39:54 jsing Exp $
# mips64-specific libcrypto build rules
# aes
CFLAGS+= -DAES_ASM
SSLASM+= aes aes-mips aes-mips
+CFLAGS+= -DHAVE_AES_SET_ENCRYPT_KEY_INTERNAL
+CFLAGS+= -DHAVE_AES_SET_DECRYPT_KEY_INTERNAL
+SRCS+= aes_core.c
# bn
SSLASM+= bn mips bn-mips
SSLASM+= bn mips-mont mips-mont