From 5dfd357e163beb68a5f436a67808f7ac87ed7801 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 17 Jul 2021 08:56:42 -0700 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BC=96=E8=AF=91=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 59 +++++++++++++++++++++++++++++++++++++--- include/gmssl/aes.h | 2 ++ include/gmssl/chacha20.h | 3 ++ include/gmssl/des.h | 3 ++ include/gmssl/rc4.h | 3 ++ src/aes.c | 2 ++ src/chacha20.c | 2 ++ src/des.c | 3 ++ src/rc4.c | 5 ++++ 9 files changed, 78 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe2fdf7b..4dff701b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,43 @@ project(GmSSL) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) -include_directories(include) +option(NO_RC4 "Option For Not Compile RC4" OFF) +option(NO_MD5 "Option For Not Compile RC4" OFF) +option(NO_AES "Option For Not Compile RC4" OFF) +option(NO_DES "Option For Not Compile RC4" OFF) +option(NO_CHACHA20 "Option For Not Compile RC4" OFF) +option(NO_SHA1 "Option For Not Compile RC4" OFF) +option(NO_SHA2 "Option For Not Compile RC4" OFF) +if (NO_RC4) +add_definitions(-DNO_RC4) +endif() + +if (NO_MD5) +add_definitions(-DNO_MD5) +endif() + +if (NO_AES) +add_definitions(-DNO_AES) +endif() + +if (NO_DES) +add_definitions(-DNO_DES) +endif() + +if (NO_CHACHA20) +add_definitions(-DNO_CHACHA20) +endif() + +if (NO_SHA1) +add_definitions(-DNO_SHA1) +endif() + +if (NO_SHA2) +add_definitions(-DNO_SHA2) +endif() + +include_directories(include) add_library( gmssl @@ -119,6 +154,7 @@ target_link_libraries (tlcp_server LINK_PUBLIC gmssl) add_executable (tls12_client tools/tls12_client.c) target_link_libraries (tls12_client LINK_PUBLIC gmssl) + add_executable (tls12_server tools/tls12_server.c) target_link_libraries (tls12_server LINK_PUBLIC gmssl) @@ -126,18 +162,25 @@ target_link_libraries (tls12_server LINK_PUBLIC gmssl) # tests add_executable(sm2test tests/sm2test.c) target_link_libraries (sm2test LINK_PUBLIC gmssl) + add_executable(sm2asn1test tests/sm2asn1test.c) target_link_libraries (sm2asn1test LINK_PUBLIC gmssl) add_executable(sm3test tests/sm3test.c) target_link_libraries (sm3test LINK_PUBLIC gmssl) +if (!NO_MD5) add_executable(md5test tests/md5test.c) target_link_libraries (md5test LINK_PUBLIC gmssl) +endif() +if (!NO_SHA1) add_executable(sha1test tests/sha1test.c) target_link_libraries (sha1test LINK_PUBLIC gmssl) +endif() + +if (!NO_SHA2) add_executable(sha224test tests/sha224test.c) target_link_libraries (sha224test LINK_PUBLIC gmssl) @@ -149,6 +192,8 @@ target_link_libraries (sha384test LINK_PUBLIC gmssl) add_executable(sha512test tests/sha512test.c) target_link_libraries (sha512test LINK_PUBLIC gmssl) +endif() + add_executable(hmactest tests/hmactest.c) target_link_libraries (hmactest LINK_PUBLIC gmssl) @@ -167,23 +212,32 @@ target_link_libraries (sm4cbctest LINK_PUBLIC gmssl) add_executable(zuctest tests/zuctest.c) target_link_libraries (zuctest LINK_PUBLIC gmssl) +if (!NO_AES) add_executable(aestest tests/aestest.c) target_link_libraries (aestest LINK_PUBLIC gmssl) +endif() +if (!NO_RC4) add_executable(rc4test tests/rc4test.c) target_link_libraries (rc4test LINK_PUBLIC gmssl) +endif() +if (!NO_CHACHA20) add_executable(chacha20test tests/chacha20test.c) target_link_libraries (chacha20test LINK_PUBLIC gmssl) +endif() add_executable(hash_drbgtest tests/hash_drbgtest.c) target_link_libraries (hash_drbgtest LINK_PUBLIC gmssl) +if (!NO_SHA1) add_executable(pbkdf2test tests/pbkdf2test.c) target_link_libraries (pbkdf2test LINK_PUBLIC gmssl) add_executable(pkcs8test tests/pkcs8test.c) target_link_libraries (pkcs8test LINK_PUBLIC gmssl) +endif() + add_executable(oidtest tests/oidtest.c) target_link_libraries (oidtest LINK_PUBLIC gmssl) @@ -214,8 +268,5 @@ INSTALL(TARGETS gmssl #安装头文件 INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/gmssl DESTINATION include - PATTERN "gmssl/*" - PERMISSIONS OWNER_WRITE OWNER_READ - GROUP_READ WORLD_READ ) diff --git a/include/gmssl/aes.h b/include/gmssl/aes.h index 6b7997f4..98e97f51 100644 --- a/include/gmssl/aes.h +++ b/include/gmssl/aes.h @@ -46,6 +46,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NO_AES #ifndef GMSSL_AES_H #define GMSSL_AES_H @@ -89,3 +90,4 @@ void aes_decrypt(const AES_KEY *aes_key, const uint8_t in[AES_BLOCK_SIZE], uint8 } #endif #endif +#endif diff --git a/include/gmssl/chacha20.h b/include/gmssl/chacha20.h index a8a04250..2afffabf 100644 --- a/include/gmssl/chacha20.h +++ b/include/gmssl/chacha20.h @@ -46,6 +46,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NO_CHACHA20 + /* RFC 8439 "ChaCha20 and Poly1305 for IETF Protocols" */ #ifndef GMSSL_CHACHA20_H @@ -95,3 +97,4 @@ void chacha20_generate_keystream(CHACHA20_STATE *state, } #endif #endif +#endif diff --git a/include/gmssl/des.h b/include/gmssl/des.h index 78647cde..9f9b4fb0 100644 --- a/include/gmssl/des.h +++ b/include/gmssl/des.h @@ -46,6 +46,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NO_DES + /* FIPS PUB 46-3 "Data Encryption Standard (DES)" */ #ifndef GMSSL_DES_H @@ -93,3 +95,4 @@ void des_ede_encrypt(DES_EDE_KEY *key, const unsigned char in[8], unsigned char } #endif #endif +#endif diff --git a/include/gmssl/rc4.h b/include/gmssl/rc4.h index d7f583c7..01726e82 100644 --- a/include/gmssl/rc4.h +++ b/include/gmssl/rc4.h @@ -46,6 +46,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NO_RC4 #ifndef GMSSL_RC4_H #define GMSSL_RC4_H @@ -74,3 +75,5 @@ void rc4_generate_keystream(RC4_STATE *state, size_t outlen, uint8_t *out); } #endif #endif + +#endif \ No newline at end of file diff --git a/src/aes.c b/src/aes.c index 9e2e4c81..67cad7d6 100644 --- a/src/aes.c +++ b/src/aes.c @@ -47,6 +47,7 @@ */ +#ifndef NO_AES #include #include #include @@ -478,3 +479,4 @@ void aes_decrypt(const AES_KEY *aes_key, const uint8_t in[16], uint8_t out[16]) memset(state, 0, sizeof(state)); } +#endif \ No newline at end of file diff --git a/src/chacha20.c b/src/chacha20.c index 88d57c3e..61fc6d58 100644 --- a/src/chacha20.c +++ b/src/chacha20.c @@ -46,6 +46,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NO_CHACHA20 #include #include @@ -121,3 +122,4 @@ void chacha20_generate_keystream(CHACHA20_STATE *state, unsigned int counts, uns state->d[12]++; } } +#endif \ No newline at end of file diff --git a/src/des.c b/src/des.c index 6bd6d70b..61cbd066 100644 --- a/src/des.c +++ b/src/des.c @@ -46,6 +46,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NO_DES + #include #include #include @@ -265,3 +267,4 @@ void des_encrypt(DES_KEY *key, const unsigned char in[DES_BLOCK_SIZE], PUTU64(out, T); } +#endif \ No newline at end of file diff --git a/src/rc4.c b/src/rc4.c index 1d647ab1..425796d2 100644 --- a/src/rc4.c +++ b/src/rc4.c @@ -45,10 +45,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef NO_RC4 #include #include #include + + #include void rc4_set_key(RC4_STATE *state, const unsigned char *key, size_t keylen) @@ -115,3 +118,5 @@ unsigned char rc4_generate_keybyte(RC4_STATE *state) rc4_generate_keystream(state, 1, out); return out[0]; } + +#endif