From 42630cf6dc18f113ba6112fd4a8affff82b9a123 Mon Sep 17 00:00:00 2001 From: zhao_zhen_zhou Date: Sat, 25 Jun 2022 00:00:17 -0700 Subject: [PATCH] modify the config file to adapt x86_64 Signed-off-by: zhao_zhen_zhou --- BUILD.gn | 62 +++++++++++++++++++++++++++++++++++ README.ASM | 29 +++++++++++++++- create_asm_file.sh | 55 ++++++++++++++++++++++++++++++- crypto/buildinf.h | 48 ++++++++++++++++++++++++++- include/crypto/bn_conf.h | 4 +-- include/crypto/dso_conf.h | 4 +-- include/openssl/opensslconf.h | 8 +++-- 7 files changed, 201 insertions(+), 9 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 0d0459ed6c..0d4b4159d0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -76,6 +76,26 @@ config("crypto_config") { "-DECP_NISTZ256_ASM", "-DPOLY1305_ASM", ] + } else if (current_cpu == "x86_64" && current_os != "mingw") { + cflags += [ + "-DOPENSSL_CPUID_OBJ", + "-DOPENSSL_BN_ASM_MONT", + "-DSHA1_ASM", + "-DSHA256_ASM", + "-DSHA512_ASM", + "-DKECCAK1600_ASM", + "-DVPAES_ASM", + "-DECP_NISTZ256_ASM", + "-DPOLY1305_ASM", + "-DOPENSSL_IA32_SSE2", + "-DOPENSSL_BN_ASM_MONT5", + "-DOPENSSL_BN_ASM_GF2m", + "-DRC4_ASM", + "-DMD5_ASM", + "-DAESNI_ASM", + "-DGHASH_ASM", + "-DX25519_ASM", + ] } else if (is_mingw) { cflags -= [ "-fPIC", @@ -133,6 +153,8 @@ config("crypto_config_public") { } else if (current_cpu == "arm64" && !(current_os == "linux" || host_os == "mac")) { cflags = [ "-DOPENSSL_ARM64_PLATFORM" ] + } else if (current_cpu == "x86_64" && current_os != "mingw") { + cflags = [ "-DOPENSSL_X86_64_PLATFORM" ] } else if (is_mingw) { cflags = [ "-DWINDOWS_PLATFORM" ] } else if (current_os == "linux" || host_os == "mac") { @@ -784,6 +806,44 @@ ohos_source_set("crypto_source") { "crypto/sha/sha256-armv8.S", "crypto/sha/sha512-armv8.S", ] + } else if (current_cpu == "x86_64" && current_os != "mingw") { + sources -= [ + "crypto/rc4/rc4_enc.c", + "crypto/rc4/rc4_skey.c", + "crypto/whrlpool/wp_block.c", + ] + sources += [ + "crypto/aes/aes_core.c", + "crypto/aes/asm/x86_64/aesni-mb-x86_64.s", + "crypto/aes/asm/x86_64/aesni-sha1-x86_64.s", + "crypto/aes/asm/x86_64/aesni-sha256-x86_64.s", + "crypto/aes/asm/x86_64/aesni-x86_64.s", + "crypto/aes/asm/x86_64/vpaes-x86_64.s", + "crypto/bn/asm/x86_64/rsaz-avx2.s", + "crypto/bn/asm/x86_64/rsaz-x86_64.s", + "crypto/bn/asm/x86_64/x86_64-gf2m.s", + "crypto/bn/asm/x86_64/x86_64-mont.s", + "crypto/bn/asm/x86_64/x86_64-mont5.s", + "crypto/bn/rsaz_exp.c", + "crypto/chacha/asm/x86_64/chacha-x86_64.s", + "crypto/ec/asm/x86_64/ecp_nistz256-x86_64.s", + "crypto/ec/asm/x86_64/x25519-x86_64.s", + "crypto/ec/ecp_nistz256.c", + "crypto/md5/asm/x86_64/md5-x86_64.s", + "crypto/modes/asm/x86_64/aesni-gcm-x86_64.s", + "crypto/modes/asm/x86_64/ghash-x86_64.s", + "crypto/poly1305/asm/x86_64/poly1305-x86_64.s", + "crypto/rc4/asm/x86_64/rc4-md5-x86_64.s", + "crypto/rc4/asm/x86_64/rc4-x86_64.s", + "crypto/sha/asm/x86_64/keccak1600-x86_64.s", + "crypto/sha/asm/x86_64/sha1-mb-x86_64.s", + "crypto/sha/asm/x86_64/sha1-x86_64.s", + "crypto/sha/asm/x86_64/sha256-mb-x86_64.s", + "crypto/sha/asm/x86_64/sha256-x86_64.s", + "crypto/sha/asm/x86_64/sha512-x86_64.s", + "crypto/whrlpool/asm/x86_64/wp-x86_64.s", + "crypto/x86_64cpuid.s", + ] } else if (is_mingw || (current_os == "linux" || host_os == "mac")) { sources += [ "crypto/aes/aes_core.c", @@ -908,6 +968,8 @@ config("ssl_config") { } else if (current_cpu == "arm64" && !(current_os == "linux" || host_os == "mac")) { cflags += [ "-DOPENSSL_ARM64_PLATFORM" ] + } else if (current_cpu == "x86_64" && current_os != "mingw") { + cflags += [ "-DOPENSSL_X86_64_PLATFORM" ] } else if (is_mingw) { cflags -= [ "-fPIC" ] cflags += [ diff --git a/README.ASM b/README.ASM index 1fb9eec83f..f3b8c9b4c9 100644 --- a/README.ASM +++ b/README.ASM @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. * Description: This README describes how to generate the .S files. * Create: 2020-05-30 */ @@ -32,4 +32,31 @@ "crypto/sha/sha1-armv8.S", "crypto/sha/sha256-armv8.S", "crypto/sha/sha512-armv8.S", + "crypto/aes/asm/x86_64/aesni-mb-x86_64.s", + "crypto/aes/asm/x86_64/aesni-sha1-x86_64.s", + "crypto/aes/asm/x86_64/aesni-sha256-x86_64.s", + "crypto/aes/asm/x86_64/aesni-x86_64.s", + "crypto/aes/asm/x86_64/vpaes-x86_64.s", + "crypto/bn/asm/x86_64/rsaz-avx2.s", + "crypto/bn/asm/x86_64/rsaz-x86_64.s", + "crypto/bn/asm/x86_64/x86_64-gf2m.s", + "crypto/bn/asm/x86_64/x86_64-mont.s", + "crypto/bn/asm/x86_64/x86_64-mont5.s", + "crypto/chacha/asm/x86_64/chacha-x86_64.s", + "crypto/ec/asm/x86_64/ecp_nistz256-x86_64.s", + "crypto/ec/asm/x86_64/x25519-x86_64.s", + "crypto/md5/asm/x86_64/md5-x86_64.s", + "crypto/modes/asm/x86_64/aesni-gcm-x86_64.s", + "crypto/modes/asm/x86_64/ghash-x86_64.s", + "crypto/poly1305/asm/x86_64/poly1305-x86_64.s", + "crypto/rc4/asm/x86_64/rc4-md5-x86_64.s", + "crypto/rc4/asm/x86_64/rc4-x86_64.s", + "crypto/sha/asm/x86_64/keccak1600-x86_64.s", + "crypto/sha/asm/x86_64/sha1-mb-x86_64.s", + "crypto/sha/asm/x86_64/sha1-x86_64.s", + "crypto/sha/asm/x86_64/sha256-mb-x86_64.s", + "crypto/sha/asm/x86_64/sha256-x86_64.s", + "crypto/sha/asm/x86_64/sha512-x86_64.s", + "crypto/whrlpool/asm/x86_64/wp-x86_64.s", + "crypto/x86_64cpuid.s", are generated by perl executing .pl files. you can also execute the script of create_asm_file.sh to generate it. \ No newline at end of file diff --git a/create_asm_file.sh b/create_asm_file.sh index 2e797681e8..4302957b2e 100755 --- a/create_asm_file.sh +++ b/create_asm_file.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. +# Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved. # Description: This script is used to generate .S files. # Create: 2020-05-30 @@ -59,6 +59,59 @@ perl crypto/sha/asm/keccak1600-armv8.pl linux64 crypto/sha/keccak1600-armv8.S perl crypto/sha/asm/sha1-armv8.pl linux64 crypto/sha/sha1-armv8.S perl crypto/sha/asm/sha512-armv8.pl linux64 crypto/sha/sha256-armv8.S perl crypto/sha/asm/sha512-armv8.pl linux64 crypto/sha/sha512-armv8.S + +#need x86_64-linux-android-clang cross compile chain in your environment path, +#otherwise the generated asm files cannot be used +x86_64-linux-android-clang -v +rm -rf crypto/aes/asm/x86_64 +rm -rf crypto/bn/asm/x86_64 +rm -rf crypto/chacha/asm/x86_64 +rm -rf crypto/ec/asm/x86_64 +rm -rf crypto/md5/asm/x86_64 +rm -rf crypto/modes/asm/x86_64 +rm -rf crypto/poly1305/asm/x86_64 +rm -rf crypto/rc4/asm/x86_64 +rm -rf crypto/sha/asm/x86_64 +rm -rf crypto/whrlpool/asm/x86_64 +rm -rf crypto/x86_64cpuid.s +mkdir crypto/aes/asm/x86_64 +mkdir crypto/bn/asm/x86_64 +mkdir crypto/chacha/asm/x86_64 +mkdir crypto/ec/asm/x86_64 +mkdir crypto/md5/asm/x86_64 +mkdir crypto/modes/asm/x86_64 +mkdir crypto/poly1305/asm/x86_64 +mkdir crypto/rc4/asm/x86_64 +mkdir crypto/sha/asm/x86_64 +mkdir crypto/whrlpool/asm/x86_64 +# for x86_64: +CC="x86_64-linux-android-clang" perl crypto/aes/asm/aesni-mb-x86_64.pl elf crypto/aes/asm/x86_64/aesni-mb-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/aes/asm/aesni-sha1-x86_64.pl elf crypto/aes/asm/x86_64/aesni-sha1-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/aes/asm/aesni-sha256-x86_64.pl elf crypto/aes/asm/x86_64/aesni-sha256-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/aes/asm/aesni-x86_64.pl elf crypto/aes/asm/x86_64/aesni-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/aes/asm/vpaes-x86_64.pl elf crypto/aes/asm/x86_64/vpaes-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/bn/asm/rsaz-avx2.pl elf crypto/bn/asm/x86_64/rsaz-avx2.s +CC="x86_64-linux-android-clang" perl crypto/bn/asm/rsaz-x86_64.pl elf crypto/bn/asm/x86_64/rsaz-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/bn/asm/x86_64-gf2m.pl elf crypto/bn/asm/x86_64/x86_64-gf2m.s +CC="x86_64-linux-android-clang" perl crypto/bn/asm/x86_64-mont.pl elf crypto/bn/asm/x86_64/x86_64-mont.s +CC="x86_64-linux-android-clang" perl crypto/bn/asm/x86_64-mont5.pl elf crypto/bn/asm/x86_64/x86_64-mont5.s +CC="x86_64-linux-android-clang" perl crypto/chacha/asm/chacha-x86_64.pl elf crypto/chacha/asm/x86_64/chacha-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/ec/asm/ecp_nistz256-x86_64.pl elf crypto/ec/asm/x86_64/ecp_nistz256-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/ec/asm/x25519-x86_64.pl elf crypto/ec/asm/x86_64/x25519-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/md5/asm/md5-x86_64.pl elf crypto/md5/asm/x86_64/md5-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/modes/asm/aesni-gcm-x86_64.pl elf crypto/modes/asm/x86_64/aesni-gcm-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/modes/asm/ghash-x86_64.pl elf crypto/modes/asm/x86_64/ghash-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/poly1305/asm/poly1305-x86_64.pl elf crypto/poly1305/asm/x86_64/poly1305-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/rc4/asm/rc4-md5-x86_64.pl elf crypto/rc4/asm/x86_64/rc4-md5-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/rc4/asm/rc4-x86_64.pl elf crypto/rc4/asm/x86_64/rc4-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/sha/asm/keccak1600-x86_64.pl elf crypto/sha/asm/x86_64/keccak1600-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/sha/asm/sha1-mb-x86_64.pl elf crypto/sha/asm/x86_64/sha1-mb-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/sha/asm/sha1-x86_64.pl elf crypto/sha/asm/x86_64/sha1-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/sha/asm/sha256-mb-x86_64.pl elf crypto/sha/asm/x86_64/sha256-mb-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/sha/asm/sha512-x86_64.pl elf crypto/sha/asm/x86_64/sha256-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/sha/asm/sha512-x86_64.pl elf crypto/sha/asm/x86_64/sha512-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/whrlpool/asm/wp-x86_64.pl elf crypto/whrlpool/asm/x86_64/wp-x86_64.s +CC="x86_64-linux-android-clang" perl crypto/x86_64cpuid.pl elf crypto/x86_64cpuid.s if [ $? -ne 0 ]; then error else diff --git a/crypto/buildinf.h b/crypto/buildinf.h index bf867c768c..e7e346184b 100644 --- a/crypto/buildinf.h +++ b/crypto/buildinf.h @@ -120,4 +120,50 @@ static const char compiler_flags[] = { 'I','C',' ','-','D','_','R','E','E','N','T','R','A','N','T',' ', '-','D','N','D','E','B','U','G','\0' }; -#endif // MAC_PLATFORM \ No newline at end of file +#endif // MAC_PLATFORM + +#ifdef OPENSSL_X86_64_PLATFORM +#define PLATFORM "platform: android-x86_64" +#define DATE "built on: Mon Jun 20 03:40:52 2022 UTC" + +/* + * Generate compiler_flags as an array of individual characters. This is a + * workaround for the situation where CFLAGS gets too long for a C90 string + * literal + */ +static const char compiler_flags[] = { + 'c','o','m','p','i','l','e','r',':',' ','x','8','6','_','6','4', + '-','l','i','n','u','x','-','a','n','d','r','o','i','d','-','c', + 'l','a','n','g',' ','-','f','P','I','C',' ','-','p','t','h','r', + 'e','a','d',' ',' ','-','-','s','y','s','r','o','o','t','=','/', + 'h','o','m','e','/','z','h','a','o','z','h','e','n','z','h','o', + 'u','/','w','o','r','k','s','p','a','c','e','/','t','h','i','r', + 'd','_','p','a','r','t','y','_','o','p','e','n','s','s','l','/', + 'o','p','e','n','s','s','l','_','f','r','o','m','_','o','f','f', + 'i','c','a','l','/','n','d','k','/','n','d','k','_','t','o','o', + 'l','_','r','2','1','e','/','n','d','k','_','m','a','c','/','s', + 'y','s','r','o','o','t',' ','-','W','a',',','-','-','n','o','e', + 'x','e','c','s','t','a','c','k',' ','-','Q','u','n','u','s','e', + 'd','-','a','r','g','u','m','e','n','t','s',' ','-','W','a','l', + 'l',' ','-','O','3',' ','-','D','O','P','E','N','S','S','L','_', + 'U','S','E','_','N','O','D','E','L','E','T','E',' ','-','D','O', + 'P','E','N','S','S','L','_','P','I','C',' ','-','D','O','P','E', + 'N','S','S','L','_','C','P','U','I','D','_','O','B','J',' ','-', + 'D','O','P','E','N','S','S','L','_','I','A','3','2','_','S','S', + 'E','2',' ','-','D','O','P','E','N','S','S','L','_','B','N','_', + 'A','S','M','_','M','O','N','T',' ','-','D','O','P','E','N','S', + 'S','L','_','B','N','_','A','S','M','_','M','O','N','T','5',' ', + '-','D','O','P','E','N','S','S','L','_','B','N','_','A','S','M', + '_','G','F','2','m',' ','-','D','S','H','A','1','_','A','S','M', + ' ','-','D','S','H','A','2','5','6','_','A','S','M',' ','-','D', + 'S','H','A','5','1','2','_','A','S','M',' ','-','D','K','E','C', + 'C','A','K','1','6','0','0','_','A','S','M',' ','-','D','R','C', + '4','_','A','S','M',' ','-','D','M','D','5','_','A','S','M',' ', + '-','D','A','E','S','N','I','_','A','S','M',' ','-','D','V','P', + 'A','E','S','_','A','S','M',' ','-','D','G','H','A','S','H','_', + 'A','S','M',' ','-','D','E','C','P','_','N','I','S','T','Z','2', + '5','6','_','A','S','M',' ','-','D','X','2','5','5','1','9','_', + 'A','S','M',' ','-','D','P','O','L','Y','1','3','0','5','_','A', + 'S','M',' ','-','D','N','D','E','B','U','G','\0' +}; +#endif // OPENSSL_X86_64_PLATFORM \ No newline at end of file diff --git a/include/crypto/bn_conf.h b/include/crypto/bn_conf.h index 8bde99218d..d12092d7a6 100644 --- a/include/crypto/bn_conf.h +++ b/include/crypto/bn_conf.h @@ -9,7 +9,7 @@ * https://www.openssl.org/source/license.html */ -#ifdef OPENSSL_ARM64_PLATFORM +#if defined(OPENSSL_ARM64_PLATFORM) || defined(OPENSSL_X86_64_PLATFORM) #ifndef OSSL_CRYPTO_BN_CONF_H # define OSSL_CRYPTO_BN_CONF_H @@ -27,7 +27,7 @@ #undef THIRTY_TWO_BIT #endif -#endif // OPENSSL_ARM64_PLATFORM +#endif // OPENSSL_ARM64_PLATFORM || OPENSSL_X86_64_PLATFORM #ifdef OPENSSL_ARM_PLATFORM #ifndef OSSL_CRYPTO_BN_CONF_H diff --git a/include/crypto/dso_conf.h b/include/crypto/dso_conf.h index d6057d9c3c..55b03e2a2a 100644 --- a/include/crypto/dso_conf.h +++ b/include/crypto/dso_conf.h @@ -9,14 +9,14 @@ * https://www.openssl.org/source/license.html */ -#ifdef OPENSSL_ARM64_PLATFORM +#if defined(OPENSSL_ARM64_PLATFORM) || defined(OPENSSL_X86_64_PLATFORM) #ifndef OSSL_CRYPTO_DSO_CONF_H # define OSSL_CRYPTO_DSO_CONF_H # define DSO_DLFCN # define HAVE_DLFCN_H # define DSO_EXTENSION ".so" #endif -#endif // OPENSSL_ARM64_PLATFORM +#endif // OPENSSL_ARM64_PLATFORM || OPENSSL_X86_64_PLATFORM #ifdef OPENSSL_ARM_PLATFORM #ifndef OSSL_CRYPTO_DSO_CONF_H diff --git a/include/openssl/opensslconf.h b/include/openssl/opensslconf.h index 1746043f02..af13cfcaa3 100644 --- a/include/openssl/opensslconf.h +++ b/include/openssl/opensslconf.h @@ -10,7 +10,7 @@ * https://www.openssl.org/source/license.html */ -#ifdef OPENSSL_ARM64_PLATFORM +#if defined(OPENSSL_ARM64_PLATFORM) || defined(OPENSSL_X86_64_PLATFORM) #include #ifdef __cplusplus @@ -212,12 +212,16 @@ extern "C" { # undef THIRTY_TWO_BIT #endif +#ifdef OPENSSL_ARM64_PLATFORM #define RC4_INT unsigned char +#else +#define RC4_INT unsigned int +#endif #ifdef __cplusplus } #endif -#endif // OPENSSL_ARM64_PLATFORM +#endif // OPENSSL_ARM64_PLATFORM || OPENSSL_X86_64_PLATFORM #ifdef OPENSSL_ARM_PLATFORM #include -- GitLab