diff --git a/CMakeLists.txt b/CMakeLists.txt index deeef99a..29bbf036 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,6 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) include_directories(include) -#enable_language(ASM) set(src @@ -76,6 +75,14 @@ set(src src/tls13.c ) +option(ENABLE_SM3_AVX_BMI2 "Enable SM3 AVX+BMI2 assembly implementation" OFF) + + +if (ENABLE_SM3_AVX_BMI2) + enable_language(ASM) + list(APPEND src src/sm3_avx_bmi2.s) +endif() + if (WIN32) list(APPEND src src/u_time.c) list(APPEND src src/rand_win.c) @@ -247,4 +254,4 @@ if (CMAKE_C_COMPILER_ID MATCHES "MSVC") target_compile_options(gmssl PRIVATE /wd4996) target_compile_options(gmssl-bin PRIVATE /wd4996) # target_compile_options(gmssl PRIVATE /wd4996) -endif() \ No newline at end of file +endif() diff --git a/src/sm3.c b/src/sm3.c index 6ab76cee..e68be8e8 100644 --- a/src/sm3.c +++ b/src/sm3.c @@ -152,6 +152,7 @@ static uint32_t K[64] = { */ }; +#ifndef ENABLE_SM3_AVX_BMI2 void sm3_compress_blocks(uint32_t digest[8], const uint8_t *data, size_t blocks) { uint32_t A; @@ -293,7 +294,7 @@ void sm3_compress_blocks(uint32_t digest[8], const uint8_t *data, size_t blocks) data += 64; } } - +#endif void sm3_init(SM3_CTX *ctx) { @@ -311,7 +312,7 @@ void sm3_init(SM3_CTX *ctx) void sm3_update(SM3_CTX *ctx, const uint8_t *data, size_t data_len) { size_t blocks; - + ctx->num &= 0x3f; if (ctx->num) { size_t left = SM3_BLOCK_SIZE - ctx->num;