From 5acf4ca03be66e876e85e64f62bc19fe5e9154a6 Mon Sep 17 00:00:00 2001 From: jsing Date: Thu, 28 Mar 2024 12:52:58 +0000 Subject: [PATCH] Merge aes_cbc.c into aes.c now that aes_cbc.c is used on all platforms. --- lib/libcrypto/Makefile | 3 +- lib/libcrypto/aes/aes.c | 27 +++++++- lib/libcrypto/aes/aes_cbc.c | 78 ----------------------- lib/libcrypto/arch/aarch64/Makefile.inc | 4 +- lib/libcrypto/arch/alpha/Makefile.inc | 4 +- lib/libcrypto/arch/amd64/Makefile.inc | 3 +- lib/libcrypto/arch/arm/Makefile.inc | 1 - lib/libcrypto/arch/hppa/Makefile.inc | 4 +- lib/libcrypto/arch/i386/Makefile.inc | 3 +- lib/libcrypto/arch/mips64/Makefile.inc | 3 +- lib/libcrypto/arch/powerpc/Makefile.inc | 4 +- lib/libcrypto/arch/powerpc64/Makefile.inc | 4 +- lib/libcrypto/arch/riscv64/Makefile.inc | 3 +- lib/libcrypto/arch/sparc64/Makefile.inc | 4 +- 14 files changed, 43 insertions(+), 102 deletions(-) delete mode 100644 lib/libcrypto/aes/aes_cbc.c diff --git a/lib/libcrypto/Makefile b/lib/libcrypto/Makefile index 06af0eee923..918454e7a44 100644 --- a/lib/libcrypto/Makefile +++ b/lib/libcrypto/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.184 2024/03/28 06:45:36 beck Exp $ +# $OpenBSD: Makefile,v 1.185 2024/03/28 12:52:58 jsing Exp $ LIB= crypto LIBREBUILD=y @@ -789,7 +789,6 @@ obj_dat.h: obj_mac.h ${SSL_OBJECTS}/obj_dat.pl .else CFLAGS+=-DOPENSSL_NO_ASM SRCS+= aes_core.c -SRCS+= aes_cbc.c SRCS+= camellia.c SRCS+= cmll_cbc.c SRCS+= cmll_misc.c diff --git a/lib/libcrypto/aes/aes.c b/lib/libcrypto/aes/aes.c index d3bf85947d7..9b25a21f4cb 100644 --- a/lib/libcrypto/aes/aes.c +++ b/lib/libcrypto/aes/aes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aes.c,v 1.1 2024/03/28 00:57:26 jsing Exp $ */ +/* $OpenBSD: aes.c,v 1.2 2024/03/28 12:52:58 jsing Exp $ */ /* ==================================================================== * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. * @@ -59,6 +59,31 @@ static const unsigned char aes_wrap_default_iv[] = { 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, }; +#ifdef HAVE_AES_CBC_ENCRYPT_INTERNAL +void aes_cbc_encrypt_internal(const unsigned char *in, unsigned char *out, + size_t len, const AES_KEY *key, unsigned char *ivec, const int enc); + +#else +static inline void +aes_cbc_encrypt_internal(const unsigned char *in, unsigned char *out, + size_t len, const AES_KEY *key, unsigned char *ivec, const int enc) +{ + if (enc) + CRYPTO_cbc128_encrypt(in, out, len, key, ivec, + (block128_f)AES_encrypt); + else + CRYPTO_cbc128_decrypt(in, out, len, key, ivec, + (block128_f)AES_decrypt); +} +#endif + +void +AES_cbc_encrypt(const unsigned char *in, unsigned char *out, + size_t len, const AES_KEY *key, unsigned char *ivec, const int enc) +{ + aes_cbc_encrypt_internal(in, out, len, key, ivec, enc); +} + /* * The input and output encrypted as though 128bit cfb mode is being * used. The extra state information to record how much of the diff --git a/lib/libcrypto/aes/aes_cbc.c b/lib/libcrypto/aes/aes_cbc.c deleted file mode 100644 index f578be9901b..00000000000 --- a/lib/libcrypto/aes/aes_cbc.c +++ /dev/null @@ -1,78 +0,0 @@ -/* $OpenBSD: aes_cbc.c,v 1.13 2024/03/28 12:28:48 jsing Exp $ */ -/* ==================================================================== - * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - */ - -#include -#include - -#ifdef HAVE_AES_CBC_ENCRYPT_INTERNAL -void aes_cbc_encrypt_internal(const unsigned char *in, unsigned char *out, - size_t len, const AES_KEY *key, unsigned char *ivec, const int enc); - -#else -static inline void -aes_cbc_encrypt_internal(const unsigned char *in, unsigned char *out, - size_t len, const AES_KEY *key, unsigned char *ivec, const int enc) -{ - if (enc) - CRYPTO_cbc128_encrypt(in, out, len, key, ivec, - (block128_f)AES_encrypt); - else - CRYPTO_cbc128_decrypt(in, out, len, key, ivec, - (block128_f)AES_decrypt); -} -#endif - -void -AES_cbc_encrypt(const unsigned char *in, unsigned char *out, - size_t len, const AES_KEY *key, unsigned char *ivec, const int enc) -{ - aes_cbc_encrypt_internal(in, out, len, key, ivec, enc); -} diff --git a/lib/libcrypto/arch/aarch64/Makefile.inc b/lib/libcrypto/arch/aarch64/Makefile.inc index d9ab7789bbf..6f57fa230f4 100644 --- a/lib/libcrypto/arch/aarch64/Makefile.inc +++ b/lib/libcrypto/arch/aarch64/Makefile.inc @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.9 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.10 2024/03/28 12:52:58 jsing Exp $ # aarch64-specific libcrypto build rules # aes -SRCS+= aes_core.c aes_cbc.c +SRCS+= aes_core.c # bn # camellia SRCS+= camellia.c cmll_cbc.c cmll_misc.c diff --git a/lib/libcrypto/arch/alpha/Makefile.inc b/lib/libcrypto/arch/alpha/Makefile.inc index 2a3bf263b1f..ac8314563c9 100644 --- a/lib/libcrypto/arch/alpha/Makefile.inc +++ b/lib/libcrypto/arch/alpha/Makefile.inc @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.10 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.11 2024/03/28 12:52:58 jsing Exp $ # alpha-specific libcrypto build rules # aes -SRCS+= aes_core.c aes_cbc.c +SRCS+= aes_core.c # bn SSLASM+= bn alpha-mont CFLAGS+= -DOPENSSL_BN_ASM_MONT diff --git a/lib/libcrypto/arch/amd64/Makefile.inc b/lib/libcrypto/arch/amd64/Makefile.inc index 13d2c0b1beb..2dcf64d045d 100644 --- a/lib/libcrypto/arch/amd64/Makefile.inc +++ b/lib/libcrypto/arch/amd64/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.19 2024/03/28 12:28:48 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.20 2024/03/28 12:52:58 jsing Exp $ # amd64-specific libcrypto build rules @@ -14,7 +14,6 @@ CFLAGS+= -DVPAES_ASM SSLASM+= aes vpaes-x86_64 SSLASM+= aes aesni-x86_64 CFLAGS+= -DHAVE_AES_CBC_ENCRYPT_INTERNAL -SRCS+= aes_cbc.c # bn CFLAGS+= -DOPENSSL_IA32_SSE2 CFLAGS+= -DRSA_ASM diff --git a/lib/libcrypto/arch/arm/Makefile.inc b/lib/libcrypto/arch/arm/Makefile.inc index 443fe9e6478..b0d125572cf 100644 --- a/lib/libcrypto/arch/arm/Makefile.inc +++ b/lib/libcrypto/arch/arm/Makefile.inc @@ -3,7 +3,6 @@ # arm-specific libcrypto build rules # aes -SRCS+= aes_cbc.c CFLAGS+= -DAES_ASM SSLASM+= aes aes-armv4 # bn diff --git a/lib/libcrypto/arch/hppa/Makefile.inc b/lib/libcrypto/arch/hppa/Makefile.inc index 84128559ced..bbe4c9ac1e9 100644 --- a/lib/libcrypto/arch/hppa/Makefile.inc +++ b/lib/libcrypto/arch/hppa/Makefile.inc @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.19 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.20 2024/03/28 12:52:58 jsing Exp $ # hppa-specific libcrypto build rules # aes -SRCS+= aes_core.c aes_cbc.c +SRCS+= aes_core.c CFLAGS+= -DAES_ASM SSLASM+= aes aes-parisc aes-parisc # bn diff --git a/lib/libcrypto/arch/i386/Makefile.inc b/lib/libcrypto/arch/i386/Makefile.inc index cd356eeea5d..5741bc6f3b4 100644 --- a/lib/libcrypto/arch/i386/Makefile.inc +++ b/lib/libcrypto/arch/i386/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.16 2024/03/28 12:28:48 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.17 2024/03/28 12:52:58 jsing Exp $ # i386-specific libcrypto build rules @@ -12,7 +12,6 @@ CFLAGS+= -DVPAES_ASM SSLASM+= aes vpaes-x86 SSLASM+= aes aesni-x86 CFLAGS+= -DHAVE_AES_CBC_ENCRYPT_INTERNAL -SRCS+= aes_cbc.c # bn CFLAGS+= -DOPENSSL_IA32_SSE2 SSLASM+= bn bn-586 diff --git a/lib/libcrypto/arch/mips64/Makefile.inc b/lib/libcrypto/arch/mips64/Makefile.inc index b3a9406f407..d40bbdf00e3 100644 --- a/lib/libcrypto/arch/mips64/Makefile.inc +++ b/lib/libcrypto/arch/mips64/Makefile.inc @@ -1,9 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.11 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.12 2024/03/28 12:52:58 jsing Exp $ # mips64-specific libcrypto build rules # aes -SRCS+= aes_cbc.c CFLAGS+= -DAES_ASM SSLASM+= aes aes-mips aes-mips # bn diff --git a/lib/libcrypto/arch/powerpc/Makefile.inc b/lib/libcrypto/arch/powerpc/Makefile.inc index 9011d0b5e9d..9e3a2f7280f 100644 --- a/lib/libcrypto/arch/powerpc/Makefile.inc +++ b/lib/libcrypto/arch/powerpc/Makefile.inc @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.8 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.9 2024/03/28 12:52:58 jsing Exp $ # powerpc-specific libcrypto build rules # aes -SRCS+= aes_core.c aes_cbc.c +SRCS+= aes_core.c # slower than C code #CFLAGS+= -DAES_ASM #SSLASM+= aes aes-ppc aes-ppc diff --git a/lib/libcrypto/arch/powerpc64/Makefile.inc b/lib/libcrypto/arch/powerpc64/Makefile.inc index f45bb013e3d..ea466bb8a3c 100644 --- a/lib/libcrypto/arch/powerpc64/Makefile.inc +++ b/lib/libcrypto/arch/powerpc64/Makefile.inc @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.10 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.11 2024/03/28 12:52:58 jsing Exp $ # powerpc-specific libcrypto build rules # aes -SRCS+= aes_core.c aes_cbc.c +SRCS+= aes_core.c # slower than C code #CFLAGS+= -DAES_ASM #SSLASM+= aes aes-ppc aes-ppc diff --git a/lib/libcrypto/arch/riscv64/Makefile.inc b/lib/libcrypto/arch/riscv64/Makefile.inc index 909cc218294..0737d3ce118 100644 --- a/lib/libcrypto/arch/riscv64/Makefile.inc +++ b/lib/libcrypto/arch/riscv64/Makefile.inc @@ -1,10 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.6 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.7 2024/03/28 12:52:58 jsing Exp $ # riscv64 libcrypto build rules # aes SRCS+= aes_core.c -SRCS+= aes_cbc.c # camellia SRCS+= camellia.c diff --git a/lib/libcrypto/arch/sparc64/Makefile.inc b/lib/libcrypto/arch/sparc64/Makefile.inc index b34a66e2264..e540fcbbba5 100644 --- a/lib/libcrypto/arch/sparc64/Makefile.inc +++ b/lib/libcrypto/arch/sparc64/Makefile.inc @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.13 2024/03/28 01:57:00 jsing Exp $ +# $OpenBSD: Makefile.inc,v 1.14 2024/03/28 12:52:58 jsing Exp $ # sparc64-specific libcrypto build rules # aes -SRCS+= aes_core.c aes_cbc.c +SRCS+= aes_core.c CFLAGS+= -DAES_ASM SSLASM+= aes aes-sparcv9 aes-sparcv9 # bn -- 2.20.1