From 155d61b65eb0efea074b6b9b82bfc3985126301d Mon Sep 17 00:00:00 2001 From: AmadeusGhost <42570690+AmadeusGhost@users.noreply.github.com> Date: Tue, 1 Mar 2022 23:10:50 +0800 Subject: [PATCH] mbedtls: refresh armv8ce_aes patches Signed-off-by: AmadeusGhost --- ...and-GCM-with-ARMv8-Crypto-Extensions.patch | 68 +++++++++---------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/package/libs/mbedtls/patches/100-Implements-AES-and-GCM-with-ARMv8-Crypto-Extensions.patch b/package/libs/mbedtls/patches/100-Implements-AES-and-GCM-with-ARMv8-Crypto-Extensions.patch index 7c840c020f..7ae41e82b8 100644 --- a/package/libs/mbedtls/patches/100-Implements-AES-and-GCM-with-ARMv8-Crypto-Extensions.patch +++ b/package/libs/mbedtls/patches/100-Implements-AES-and-GCM-with-ARMv8-Crypto-Extensions.patch @@ -100,7 +100,7 @@ Then run normal make or cmake etc. +#endif /* MBEDTLS_ARMV8CE_AES_H */ --- a/include/mbedtls/check_config.h +++ b/include/mbedtls/check_config.h -@@ -95,6 +95,10 @@ +@@ -72,6 +72,10 @@ #error "MBEDTLS_AESNI_C defined, but not all prerequisites" #endif @@ -111,25 +111,21 @@ Then run normal make or cmake etc. #if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C) #error "MBEDTLS_CTR_DRBG_C defined, but not all prerequisites" #endif -@@ -772,3 +776,4 @@ - typedef int mbedtls_iso_c_forbids_empty_translation_units; - - #endif /* MBEDTLS_CHECK_CONFIG_H */ -+ --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h -@@ -73,6 +73,7 @@ - * Requires support for asm() in compiler. +@@ -47,6 +47,7 @@ * * Used in: -+ * library/armv8ce_aes.c * library/aria.c ++ * library/armv8ce_aes.c * library/timing.c * include/mbedtls/bn_mul.h -@@ -1905,6 +1906,21 @@ + * +@@ -2312,6 +2313,21 @@ + */ #define MBEDTLS_AESNI_C - /** ++/** + * \def MBEDTLS_ARMV8CE_AES_C + * + * Enable ARMv8 Crypto Extensions for AES and GCM @@ -144,30 +140,28 @@ Then run normal make or cmake etc. + */ +//#define MBEDTLS_ARMV8CE_AES_C + -+/** + /** * \def MBEDTLS_AES_C * - * Enable the AES block cipher. --- a/library/aes.c +++ b/library/aes.c -@@ -69,7 +69,9 @@ +@@ -39,6 +39,9 @@ #if defined(MBEDTLS_AESNI_C) #include "mbedtls/aesni.h" #endif -- +#if defined(MBEDTLS_ARMV8CE_AES_C) +#include "mbedtls/armv8ce_aes.h" +#endif + #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) - #include "mbedtls/platform.h" -@@ -1052,6 +1054,11 @@ +@@ -999,6 +1002,11 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) ); #endif +#if defined(MBEDTLS_ARMV8CE_AES_C) -+ // We don't do runtime checking for ARMv8 Crypto Extensions -+ return mbedtls_armv8ce_aes_crypt_ecb( ctx, mode, input, output ); ++ // We don't do runtime checking for ARMv8 Crypto Extensions ++ return mbedtls_armv8ce_aes_crypt_ecb( ctx, mode, input, output ); +#endif + #if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) @@ -320,7 +314,7 @@ Then run normal make or cmake etc. +#endif /* MBEDTLS_ARMV8CE_AES_C */ --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt -@@ -7,6 +7,7 @@ +@@ -15,6 +15,7 @@ set(src_crypto aesni.c arc4.c aria.c @@ -330,7 +324,7 @@ Then run normal make or cmake etc. base64.c --- a/library/gcm.c +++ b/library/gcm.c -@@ -71,6 +71,10 @@ +@@ -41,6 +41,10 @@ #include "mbedtls/aesni.h" #endif @@ -341,26 +335,26 @@ Then run normal make or cmake etc. #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) #include "mbedtls/aes.h" #include "mbedtls/platform.h" -@@ -140,6 +144,12 @@ +@@ -87,6 +91,12 @@ static int gcm_gen_table( mbedtls_gcm_context *ctx ) if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, h, 16, h, &olen ) ) != 0 ) return( ret ); +#if defined(MBEDTLS_ARMV8CE_AES_C) -+ // we don't do feature testing with ARMv8 cryptography extensions ++ // we don't do feature testing with ARMv8 cryptography extensions + memcpy( ctx ->HL, h, 16 ); // put H at the beginning of buffer + return( 0 ); // that's all we need +#endif + /* pack h as two 64-bits ints, big-endian */ - GET_UINT32_BE( hi, h, 0 ); - GET_UINT32_BE( lo, h, 4 ); -@@ -248,6 +258,11 @@ + hi = MBEDTLS_GET_UINT32_BE( h, 0 ); + lo = MBEDTLS_GET_UINT32_BE( h, 4 ); +@@ -196,6 +206,11 @@ static void gcm_mult( mbedtls_gcm_context *ctx, const unsigned char x[16], unsigned char lo, hi, rem; uint64_t zh, zl; +#if defined(MBEDTLS_ARMV8CE_AES_C) -+ mbedtls_armv8ce_gcm_mult( output, x, (const unsigned char *) ctx->HL ); -+ return; ++ mbedtls_armv8ce_gcm_mult( output, x, (const unsigned char *) ctx->HL ); ++ return; +#endif + #if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) @@ -368,17 +362,17 @@ Then run normal make or cmake etc. unsigned char h[16]; --- a/library/Makefile +++ b/library/Makefile -@@ -65,6 +65,7 @@ - - OBJS_CRYPTO= aes.o aesni.o arc4.o \ - aria.o asn1parse.o asn1write.o \ -+ armv8ce_aes.o \ - base64.o bignum.o blowfish.o \ - camellia.o ccm.o chacha20.o \ - chachapoly.o cipher.o cipher_wrap.o \ +@@ -72,6 +72,7 @@ OBJS_CRYPTO= \ + aesni.o \ + arc4.o \ + aria.o \ ++ armv8ce_aes.o \ + asn1parse.o \ + asn1write.o \ + base64.o \ --- a/library/version_features.c +++ b/library/version_features.c -@@ -586,6 +586,9 @@ +@@ -624,6 +624,9 @@ static const char * const features[] = { #if defined(MBEDTLS_AESNI_C) "MBEDTLS_AESNI_C", #endif /* MBEDTLS_AESNI_C */