From 149e429d1c1f38ad30726c9bb5cee6c5b038c710 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Mon, 1 Apr 2024 09:53:52 +0800 Subject: [PATCH] Add SM4 aarch64 asm support --- CMakeLists.txt | 7 +++++++ src/sm4.c | 4 +++- src/sm4_tbox.c | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64072714..1dc83daa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,6 +302,13 @@ if (ENABLE_SM4_AESNI_AVX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") endif() +option(ENABLE_SM4_AARCH64 "Enable SM4 AARCH64 assembly implementation" OFF) +if (ENABLE_SM4_AARCH64) + message(STATUS "ENABLE_SM4_AARCH64 is ON") + add_definitions(-DENABLE_SM4_AARCH64) + enable_language(ASM) + list(APPEND src src/sm4_aarch64.S) +endif() option(ENABLE_SM4_ECB "Enable SM4 ECB mode" OFF) if (ENABLE_SM4_ECB) diff --git a/src/sm4.c b/src/sm4.c index 43f4a0fd..1ba465c6 100644 --- a/src/sm4.c +++ b/src/sm4.c @@ -1,4 +1,4 @@ -/* +out/* * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may @@ -94,6 +94,7 @@ const uint8_t S[256] = { (S[((A)) & 0xff])) +#ifndef ENABLE_SM4_AARCH64 void sm4_set_encrypt_key(SM4_KEY *key, const uint8_t user_key[16]) { uint32_t X0, X1, X2, X3, X4; @@ -171,3 +172,4 @@ void sm4_encrypt(const SM4_KEY *key, const unsigned char in[16], unsigned char o PUTU32(out + 8, X1); PUTU32(out + 12, X0); } +#endif diff --git a/src/sm4_tbox.c b/src/sm4_tbox.c index 4f930e0d..cd25ed5a 100644 --- a/src/sm4_tbox.c +++ b/src/sm4_tbox.c @@ -161,6 +161,7 @@ const uint32_t T[256] = { (S[((A)) & 0xff])) +#ifndef ENABLE_SM4_AARCH64 void sm4_set_encrypt_key(SM4_KEY *key, const uint8_t user_key[16]) { uint32_t X0, X1, X2, X3, X4; @@ -242,3 +243,4 @@ void sm4_encrypt(const SM4_KEY *key, const unsigned char in[16], unsigned char o PUTU32(out + 8, X1); PUTU32(out + 12, X0); } +#endif