From 53f353337b90200b0db1e23f9c784f2abe869177 Mon Sep 17 00:00:00 2001 From: lean Date: Thu, 17 Jun 2021 15:37:02 +0800 Subject: [PATCH] mbedtls: add ARMv8 Crypto Extensions AES and SSE2 on x86 --- package/libs/mbedtls/Makefile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/package/libs/mbedtls/Makefile b/package/libs/mbedtls/Makefile index 7f6bf4e4c..088d3284d 100644 --- a/package/libs/mbedtls/Makefile +++ b/package/libs/mbedtls/Makefile @@ -23,6 +23,8 @@ PKG_CPE_ID:=cpe:/a:arm:mbed_tls PKG_CONFIG_DEPENDS := \ CONFIG_LIBMBEDTLS_DEBUG_C \ + CONFIG_LIBMBEDTLS_HAVE_ARMV8CE_AES \ + CONFIG_LIBMBEDTLS_HAVE_SSE2 \ CONFIG_LIBMBEDTLS_HKDF_C include $(INCLUDE_DIR)/package.mk @@ -60,6 +62,34 @@ config LIBMBEDTLS_DEBUG_C Usually, you don't need this, so don't select this if you're unsure. +config LIBMBEDTLS_HAVE_ARMV8CE_AES + depends on PACKAGE_libmbedtls + bool + default y + prompt "Enable use of the ARMv8 Crypto Extensions" + depends on aarch64 && !TARGET_bcm27xx && !TARGET_bcm4908 + help + Use of the ARMv8 Crypto Extensions greatly increase performance + (up to 4x faster on AES-GCM while 10x faster on raw AES). + + Related instructions should be included in all modern Aarch64 + devices, except some wastes like Broadcom. + If you don't sure, say Y here. + +config LIBMBEDTLS_HAVE_SSE2 + depends on PACKAGE_libmbedtls + bool + default y if !TARGET_x86_legacy && !TARGET_x86_geode + prompt "Enable use of x86 SSE2 instructions" + depends on x86_64 || i386 + help + Use of SSE2 instructions greatly increase performance (up to + 3x faster) with a minimum (~0.2%, or 23KB) increase in package + size, but it will bring no benefit if your hardware does not + support them, such as Geode GX and LX. In this case you may + save 23KB by saying yes here. AMD Geode NX, and Intel + Pentium 4 and above support SSE2. + config LIBMBEDTLS_HKDF_C depends on PACKAGE_libmbedtls bool "Enable the HKDF algorithm (RFC 5869)" @@ -92,6 +122,9 @@ PKG_INSTALL:=1 TARGET_CFLAGS += -ffunction-sections -fdata-sections TARGET_CFLAGS := $(filter-out -O%,$(TARGET_CFLAGS)) +ifneq ($(CONFIG_LIBMBEDTLS_HAVE_ARMV8CE_AES),) + TARGET_CFLAGS := $(filter-out -march=%,$(TARGET_CFLAGS)) -march=armv8-a+crypto +endif CMAKE_OPTIONS += \ -DUSE_SHARED_MBEDTLS_LIBRARY:Bool=ON \ @@ -103,6 +136,8 @@ define Build/Configure awk 'BEGIN { rc = 1 } \ /#define MBEDTLS_DEBUG_C/ { $$$$0 = "$(if $(CONFIG_LIBMBEDTLS_DEBUG_C),,// )#define MBEDTLS_DEBUG_C"; rc = 0 } \ + /#define MBEDTLS_ARMV8CE_AES_C/ { $$$$0 = "$(if $(CONFIG_LIBMBEDTLS_HAVE_ARMV8CE_AES),,// )#define MBEDTLS_ARMV8CE_AES_C"; rc = 0 } \ + /#define MBEDTLS_HAVE_SSE2/ { $$$$0 = "$(if $(CONFIG_LIBMBEDTLS_HAVE_SSE2),,// )#define MBEDTLS_HAVE_SSE2"; rc = 0 } \ { print } \ END { exit(rc) }' $(PKG_BUILD_DIR)/include/mbedtls/config.h \ >$(PKG_BUILD_DIR)/include/mbedtls/config.h.new && \