国密SM2,SM3,SM4源代码
安全技术
1014.69KB
19
需要积分: 1
立即下载
资源介绍:
国密SM2,SM3,SM4源代码,C语言
if (CMAKE_VERSION VERSION_LESS "3.0")
cmake_minimum_required(VERSION 2.8)
else()
cmake_minimum_required(VERSION 3.6)
endif()
project(GmSSL C)
SET(CMAKE_PROJECT_HOMEPAGE_URL "http://gmssl.org")
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include_directories(include)
if(MSVC)
#add_compile_options(/O2) # conflict with CI /0d (not optimized)
else()
add_compile_options(-O3)
endif()
option(ENABLE_TEST_SPEED "Enable test speed" OFF)
option(ENABLE_SM2_ARM64 "Enable SM2_Z256 ARMv8 assembly" OFF)
option(ENABLE_SM3_ARM64 "Enable SM3 Arm Neon implementation (10% faster on Apple M2)" OFF)
option(ENABLE_SM4_ARM64 "Enable SM4 AARCH64 assembly implementation" OFF)
option(ENABLE_SM4_CE "Enable SM4 ARM CE assembly implementation" OFF)
option(ENABLE_SM9_ARM64 "Enable SM9_Z256 ARMv8 assembly" OFF)
option(ENABLE_GMUL_ARM64 "Enable GF(2^128) Multiplication AArch64 assembly" OFF)
option(ENABLE_SM4_AVX2 "Enable SM4 AVX2 8x implementation" OFF)
option(ENABLE_SM4_AESNI "Enable SM4 AES-NI (4x) implementation" OFF)
option(ENABLE_SM2_AMD64 "Enable SM2_Z256 X86_64 assembly" OFF)
option(ENABLE_SM3_SSE "Enable SM3 SSE assembly implementation" OFF)
option(ENABLE_SM4_CTR_AESNI_AVX "Enable SM4 CTR AESNI+AVX assembly implementation" OFF)
option(ENABLE_SM4_CL "Enable SM4 OpenCL" OFF)
option(ENABLE_INTEL_RDRAND "Enable Intel RDRAND instructions" OFF)
option(ENABLE_INTEL_RDSEED "Enable Intel RDSEED instructions" OFF)
option(ENABLE_SM4_ECB "Enable SM4 ECB mode" ON)
option(ENABLE_SM4_OFB "Enable SM4 OFB mode" ON)
option(ENABLE_SM4_CFB "Enable SM4 CFB mode" ON)
option(ENABLE_SM4_CCM "Enable SM4 CCM mode" ON)
option(ENABLE_SM4_XTS "Enable SM4 XTS mode" ON)
option(ENABLE_SM4_CBC_MAC "Enable SM4-CBC-MAC" ON)
option(ENABLE_SM2_EXTS "Enable SM2 Extensions" OFF)
option(ENABLE_SM3_XMSS "Enable SM3-XMSS signature" ON)
option(ENABLE_SHA1 "Enable SHA1" ON)
option(ENABLE_SHA2 "Enable SHA2" ON)
option(ENABLE_AES "Enable AES" ON)
option(ENABLE_CHACHA20 "Enable Chacha20" ON)
option(ENABLE_SKF "Enable SKF module" OFF)
option(ENABLE_SDF "Enable SDF module" ON)
option(ENABLE_ASM_UNDERSCORE_PREFIX "Add prefix `_` to assembly symbols" ON)
option(ENABLE_TLS_DEBUG "Enable TLS and TLCP print debug message" OFF)
option (ENABLE_SM2_ENC_PRE_COMPUTE "Enable SM2 encryption precomputing" ON)
set(src
src/version.c
src/debug.c
src/sm4.c
src/sm4_cbc.c
src/sm4_ctr.c
src/sm4_gcm.c
src/sm3.c
src/sm3_hmac.c
src/sm3_kdf.c
src/sm3_pbkdf2.c
src/sm3_digest.c
src/sm2_z256.c
src/sm2_z256_table.c
src/sm2_key.c
src/sm2_sign.c
src/sm2_enc.c
src/sm2_exch.c
src/sm9_z256.c
src/sm9_z256_table.c
src/sm9_key.c
src/sm9_sign.c
src/sm9_enc.c
src/sm9_exch.c
src/zuc.c
src/zuc_modes.c
src/block_cipher.c
src/digest.c
src/hmac.c
src/hkdf.c
src/gf128.c
src/ghash.c
src/sm4_cbc_sm3_hmac.c
src/sm4_ctr_sm3_hmac.c
src/pkcs8.c
src/ec.c
src/rsa.c
src/asn1.c
src/hex.c
src/base64.c
src/pem.c
src/x509_alg.c
src/x509_cer.c
src/x509_ext.c
src/x509_req.c
src/x509_crl.c
src/x509_new.c
src/cms.c
src/socket.c
src/tls.c
src/tls_ext.c
src/tls_trace.c
src/tlcp.c
src/tls12.c
src/tls13.c
src/file.c
src/file.c
)
set(tools
tools/gmssl.c
tools/version.c
tools/sm4.c
tools/sm4_cbc.c
tools/sm4_ctr.c
tools/sm4_gcm.c
tools/sm4_cbc_sm3_hmac.c
tools/sm4_ctr_sm3_hmac.c
tools/sm3.c
tools/sm3hmac.c
tools/sm3_pbkdf2.c
tools/sm3xmss_keygen.c
tools/sm2keygen.c
tools/sm2sign.c
tools/sm2verify.c
tools/sm2encrypt.c
tools/sm2decrypt.c
tools/sm9setup.c
tools/sm9keygen.c
tools/sm9sign.c
tools/sm9verify.c
tools/sm9encrypt.c
tools/sm9decrypt.c
tools/zuc.c
tools/rand.c
tools/ghash.c
tools/certgen.c
tools/certparse.c
tools/certverify.c
tools/certrevoke.c
tools/reqgen.c
tools/reqparse.c
tools/reqsign.c
tools/crlgen.c
tools/crlget.c
tools/crlparse.c
tools/crlverify.c
tools/cmssign.c
tools/cmsverify.c
tools/cmsencrypt.c
tools/cmsdecrypt.c
tools/cmsparse.c
tools/tlcp_client.c
tools/tlcp_server.c
tools/tls12_client.c
tools/tls12_server.c
tools/tls13_client.c
tools/tls13_server.c
)
set(tests
sm4
sm4_cbc
sm4_ctr
sm4_gcm
sm3
sm4_sm3_hmac
sm2_z256
sm2_key
sm2_sign
sm2_enc
sm9
zuc
block_cipher
digest
hmac
hkdf
gf128
ghash
pkcs8
ec
asn1
hex
base64
pem
x509
x509_oid
x509_alg
x509_str
x509_ext
x509_req
x509_crl
cms
tls
tls13
)
include(CheckSymbolExists)
option(ENABLE_SMALL_FOOTPRINT "Enable small code size" OFF)
if (ENABLE_SMALL_FOOTPRINT)
message(STATUS "ENABLE_SMALL_FOOTPRINT is ON")
add_definitions(-DENABLE_SMALL_FOOTPRINT)
endif()
if (ENABLE_TEST_SPEED)
message(STATUS "ENABLE_TEST_SPEED is ON")
add_definitions(-DENABLE_TEST_SPEED)
endif()
option(ENABLE_SM2_ALGOR_ID_ENCODE_NULL "Enable AlgorithmIdenifier with algorithm sm2sign_with_sm3 encode a NULL object as parameters" OFF)
if (ENABLE_SM2_ALGOR_ID_ENCODE_NULL)
message(STATUS "ENABLE_SM2_ALGOR_ID_ENCODE_NULL is ON")
add_definitions(-DENABLE_SM2_ALGOR_ID_ENCODE_NULL)
endif()
if (ENABLE_ASM_UNDERSCORE_PREFIX)
message(STATUS "ENABLE_ASM_UNDERSCORE_PREFIX is ON")
add_definitions(-DENABLE_ASM_UNDERSCORE_PREFIX)
endif()
if (ENABLE_GMUL_ARM64)
message(STATUS "ENABLE_GMUL_ARM64 is ON")
add_definitions(-DENABLE_GMUL_ARM64)
enable_language(ASM)
#list(APPEND src src/gf128_arm64.S)
list(APPEND src src/gf128_arm64.c)
endif()
if (ENABLE_SM2_ARM64)
message(STATUS "ENABLE_SM2_ARM64 is ON")
add_definitions(-DENABLE_SM2_ARM64)
enable_language(ASM)
list(APPEND src src/sm2_z256_arm64.S)
endif()
if (ENABLE_SM2_AMD64)
message(STATUS "ENABLE_SM2_AMD64 is ON")
add_definitions(-DENABLE_SM2_AMD64)
enable_language(ASM)
list(APPEND src src/sm2_z256_amd64.S)
endif()
if (ENABLE_SM2_NEON)
message(STATUS "ENABLE_SM2_NEON is ON")
add_definitions(-DENABLE_SM2_NEON)
endif()
if (ENABLE_SM9_ARM64)
message(STATUS "ENABLE_SM9_ARM64 is ON")
add_definitions(-DENABLE_SM9_ARM64)
enable_language(ASM)
list(APPEND src src/sm9_z256_arm64.S)
endif()
if (ENABLE_TLS_DEBUG)
message(STATUS "ENABLE_TLS_DEBUG is ON")
add_definitions(-DENABLE_TLS_DEBUG)
endif()
if (ENABLE_SM3_SSE)
message(STATUS "ENABLE_SM3_SSE is ON")
list(FIND src src/sm3.c sm3_index)
list(REMOVE_AT src ${sm3_index})
list(INSERT src ${sm3_index} src/sm3_sse.c)
endif()
if (ENABLE_SM3_ARM64)
message(STATUS "ENABLE_SM3_ARM64 is ON")
list(FIND src src/sm3.c index)
list(REMOVE_AT src ${index})
list(INSERT src ${index} src/sm3_arm64.c)
endif()
if (ENABLE_SM4_ARM64)
message(STATUS "ENABLE_SM4_ARM64 is ON")
list(FIND src src/sm4.c sm4_index)
list(REMOVE_AT src ${sm4_index})
list(INSERT src ${sm4_index} src/sm4_arm64.c)
enable_language(ASM)
endif()
if (ENABLE_SM4_AVX2)
message(STATUS "ENABLE_SM4_AVX2 is ON")
list(FIND src src/sm4.c sm4_index)
list(REMOVE_AT src ${sm4_index})
list(INSERT src ${sm4_index} src/sm4_avx2.c)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
endif()
if (ENABLE_SM4_AESNI)
message(STATUS "ENABLE_SM4_AESNI is ON")
list(FIND src src/sm4.c sm4_index)
list(REMOVE_AT src ${sm4_index})
list(INSERT src ${sm4_index} src/sm4_aesni.c)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
endif()
if (ENABLE_SM4_CE)
message(STATUS "ENABLE_SM4_CE is ON")
list(FIND src src/sm4.c sm4_index)
list(REMOVE_AT src ${sm4_index})
list(INSERT src ${sm4_index} src/sm4_ce.c)
set_source_files_properties(src/sm4_ce.c PROPERTIES COMPILE_OPTIONS "-march=armv8.2-a+sm4")
endif()
if (ENABLE_SM4_CTR_AESNI_AVX)
message(STATUS "ENABLE_SM4_CTR_AESNI_AVX is ON")
list(FIND src src/sm4_ctr.c sm4_ctr_index)
list(REMOVE_AT src ${sm4_ctr_index})
list(INSERT src ${sm4_ctr_index} src/sm4_ctr_aesni_avx.c)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
endif()
if (ENABLE_SM4_CL)
message(STATUS "ENABLE_SM4_CL is ON")
add_definitions(-DENABLE_SM4_CL)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions(-DMACOS) # to include
endif()
list(
资源文件列表:
国密源码.zip 大约有319个文件