mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Update Makefile and some tests
This commit is contained in:
238
CMakeLists.txt
238
CMakeLists.txt
@@ -1,46 +1,10 @@
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(GmSSL)
|
||||
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
|
||||
|
||||
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(
|
||||
@@ -92,16 +56,20 @@ add_library(
|
||||
src/block_cipher.c
|
||||
|
||||
# pkix
|
||||
src/oid.c
|
||||
src/asn1.c
|
||||
src/base64.c
|
||||
src/pem.c
|
||||
src/pbkdf2.c
|
||||
src/pkcs8.c
|
||||
src/x509_lib.c
|
||||
src/x509_asn1.c
|
||||
|
||||
src/x509_str.c
|
||||
src/x509_alg.c
|
||||
src/x509_oid.c
|
||||
src/x509_cer.c
|
||||
src/x509_ext.c
|
||||
src/x509_algor.c
|
||||
src/x509_req.c
|
||||
src/x509_crl.c
|
||||
|
||||
src/cms.c
|
||||
|
||||
# for tls 1.3
|
||||
@@ -110,13 +78,14 @@ add_library(
|
||||
src/gcm.c
|
||||
|
||||
# ssl/tls/tlcp
|
||||
src/tls.c
|
||||
src/tls_trace.c
|
||||
src/tls12.c
|
||||
src/tlcp.c
|
||||
src/tls13.c
|
||||
#src/tls.c
|
||||
#src/tls_trace.c
|
||||
#src/tls12.c
|
||||
#src/tlcp.c
|
||||
#src/tls13.c
|
||||
|
||||
)
|
||||
|
||||
SET_TARGET_PROPERTIES(gmssl PROPERTIES VERSION 3.0 SOVERSION 3)
|
||||
|
||||
|
||||
@@ -138,58 +107,99 @@ target_link_libraries (sm3 LINK_PUBLIC gmssl)
|
||||
add_executable (sm3hmac tools/sm3hmac.c)
|
||||
target_link_libraries (sm3hmac LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable (reqgen tools/reqgen.c)
|
||||
target_link_libraries (reqgen LINK_PUBLIC gmssl)
|
||||
add_executable (reqparse tools/reqparse.c)
|
||||
target_link_libraries (reqparse LINK_PUBLIC gmssl)
|
||||
#add_executable (reqgen tools/reqgen.c)
|
||||
#target_link_libraries (reqgen LINK_PUBLIC gmssl)
|
||||
#add_executable (reqparse tools/reqparse.c)
|
||||
#target_link_libraries (reqparse LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable (certgen tools/certgen.c)
|
||||
target_link_libraries (certgen LINK_PUBLIC gmssl)
|
||||
#add_executable (certgen tools/certgen.c)
|
||||
#target_link_libraries (certgen LINK_PUBLIC gmssl)
|
||||
add_executable (certparse tools/certparse.c)
|
||||
target_link_libraries (certparse LINK_PUBLIC gmssl)
|
||||
add_executable (certverify tools/certverify.c)
|
||||
target_link_libraries (certverify LINK_PUBLIC gmssl)
|
||||
#add_executable (certverify tools/certverify.c)
|
||||
#target_link_libraries (certverify LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable (tlcp_client tools/tlcp_client.c)
|
||||
target_link_libraries (tlcp_client LINK_PUBLIC gmssl)
|
||||
add_executable (tlcp_server tools/tlcp_server.c)
|
||||
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)
|
||||
add_executable (tls13_client tools/tls13_client.c)
|
||||
target_link_libraries (tls13_client LINK_PUBLIC gmssl)
|
||||
add_executable (tls13_server tools/tls13_server.c)
|
||||
target_link_libraries (tls13_server LINK_PUBLIC gmssl)
|
||||
#add_executable (tlcp_client tools/tlcp_client.c)
|
||||
#target_link_libraries (tlcp_client LINK_PUBLIC gmssl)
|
||||
#add_executable (tlcp_server tools/tlcp_server.c)
|
||||
#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)
|
||||
#add_executable (tls13_client tools/tls13_client.c)
|
||||
#target_link_libraries (tls13_client LINK_PUBLIC gmssl)
|
||||
#add_executable (tls13_server tools/tls13_server.c)
|
||||
#target_link_libraries (tls13_server LINK_PUBLIC gmssl)
|
||||
|
||||
|
||||
|
||||
# tests
|
||||
enable_testing()
|
||||
|
||||
add_executable(aestest tests/aestest.c)
|
||||
target_link_libraries (aestest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(sm2test tests/sm2test.c)
|
||||
target_link_libraries (sm2test LINK_PUBLIC gmssl)
|
||||
add_executable(asn1test tests/asn1test.c)
|
||||
target_link_libraries (asn1test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(sm2asn1test tests/sm2asn1test.c)
|
||||
target_link_libraries (sm2asn1test LINK_PUBLIC gmssl)
|
||||
add_executable(base64test tests/base64test.c)
|
||||
target_link_libraries (base64test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(sm3test tests/sm3test.c)
|
||||
target_link_libraries (sm3test LINK_PUBLIC gmssl)
|
||||
add_executable(block_ciphertest tests/block_ciphertest.c)
|
||||
target_link_libraries (block_ciphertest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(chacha20test tests/chacha20test.c)
|
||||
target_link_libraries (chacha20test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(cmstest tests/cmstest.c)
|
||||
target_link_libraries (cmstest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(destest tests/destest.c)
|
||||
target_link_libraries (destest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(digesttest tests/digesttest.c)
|
||||
target_link_libraries (digesttest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(ectest tests/ectest.c)
|
||||
target_link_libraries (ectest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(gcmtest tests/gcmtest.c)
|
||||
target_link_libraries (gcmtest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(gf128test tests/gf128test.c)
|
||||
target_link_libraries (gf128test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(hash_drbgtest tests/hash_drbgtest.c)
|
||||
target_link_libraries (hash_drbgtest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(hextest tests/hextest.c)
|
||||
target_link_libraries (hextest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(hkdftest tests/hkdftest.c)
|
||||
target_link_libraries (hkdftest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(hmactest tests/hmactest.c)
|
||||
target_link_libraries (hmactest 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(pbkdf2test tests/pbkdf2test.c)
|
||||
target_link_libraries (pbkdf2test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(pemtest tests/pemtest.c)
|
||||
target_link_libraries (pemtest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(pkcs8test tests/pkcs8test.c)
|
||||
target_link_libraries (pkcs8test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(rc4test tests/rc4test.c)
|
||||
target_link_libraries (rc4test LINK_PUBLIC gmssl)
|
||||
|
||||
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)
|
||||
|
||||
@@ -201,87 +211,44 @@ target_link_libraries (sha384test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(sha512test tests/sha512test.c)
|
||||
target_link_libraries (sha512test LINK_PUBLIC gmssl)
|
||||
endif()
|
||||
|
||||
add_executable(sm2test tests/sm2test.c)
|
||||
target_link_libraries (sm2test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(hmactest tests/hmactest.c)
|
||||
target_link_libraries (hmactest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(hkdftest tests/hkdftest.c)
|
||||
target_link_libraries (hkdftest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(digesttest tests/digesttest.c)
|
||||
target_link_libraries (digesttest LINK_PUBLIC gmssl)
|
||||
add_executable(sm3test tests/sm3test.c)
|
||||
target_link_libraries (sm3test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(sm4test tests/sm4test.c)
|
||||
target_link_libraries (sm4test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(sm4cbctest tests/sm4cbctest.c)
|
||||
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)
|
||||
|
||||
add_executable(asn1test tests/asn1test.c)
|
||||
target_link_libraries (asn1test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(base64test tests/base64test.c)
|
||||
target_link_libraries (base64test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(x509test tests/x509test.c)
|
||||
target_link_libraries (x509test LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(cmstest tests/cmstest.c)
|
||||
target_link_libraries (cmstest LINK_PUBLIC gmssl)
|
||||
|
||||
add_executable(zuctest tests/zuctest.c)
|
||||
target_link_libraries (zuctest LINK_PUBLIC gmssl)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME aes COMMAND aestest)
|
||||
add_test(NAME asn1 COMMAND asn1test)
|
||||
add_test(NAME base64 COMMAND base64test)
|
||||
add_test(NAME block_cipher COMMAND block_ciphertext)
|
||||
add_test(NAME block_cipher COMMAND block_ciphertest)
|
||||
add_test(NAME chacha20 COMMAND chacha20test)
|
||||
add_test(NAME cms COMMAND cmstest)
|
||||
add_test(NAME ctr COMMAND ctrtest)
|
||||
add_test(NAME des COMMAND destest)
|
||||
add_test(NAME digest COMMAND digesttest)
|
||||
add_test(NAME ec COMMAND ectest)
|
||||
add_test(NAME gcm COMMAND gcmtest)
|
||||
add_test(NAME gf128 COMMAND gf128test)
|
||||
add_test(NAME hash_drbg COMMAND hash_drbgtest)
|
||||
add_test(NAME hkdf COMMAND hkdftest)
|
||||
add_test(NAME hex COMMAND hextest)
|
||||
add_test(NAME hmac COMMAND hmactest)
|
||||
add_test(NAME md5 COMMAND md5test)
|
||||
add_test(NAME oid COMMAND oidtest)
|
||||
add_test(NAME pbkdf2 COMMAND pbkdf2test)
|
||||
add_test(NAME pem COMMAND pemtest)
|
||||
add_test(NAME pkcs8 COMMAND pkcs8test)
|
||||
add_test(NAME rc4 COMMAND rc4test)
|
||||
add_test(NAME sha1 COMMAND sha1test)
|
||||
@@ -294,14 +261,13 @@ add_test(NAME sm2 COMMAND sm2test)
|
||||
add_test(NAME sm3 COMMAND sm3test)
|
||||
add_test(NAME sm4cbc COMMAND sm4cbctest)
|
||||
add_test(NAME sm4 COMMAND sm4test)
|
||||
add_test(NAME tls COMMAND tlstest)
|
||||
add_test(NAME u128 COMMAND u128test)
|
||||
#add_test(NAME tls COMMAND tlstest)
|
||||
add_test(NAME x509 COMMAND x509test)
|
||||
add_test(NAME zuc COMMAND zuctest)
|
||||
|
||||
|
||||
INSTALL(TARGETS certparse certgen certverify reqgen sm3 sm2keygen sm2sign sm2verify sm2encrypt sm2decrypt tlcp_client tlcp_server tls12_client tls12_server tls13_client tls13_server
|
||||
RUNTIME DESTINATION bin)
|
||||
INSTALL(TARGETS certparse sm3 sm2keygen sm2sign sm2verify sm2encrypt sm2decrypt RUNTIME DESTINATION bin)
|
||||
#INSTALL(TARGETS certparse certgen certverify reqgen tlcp_client tlcp_server tls12_client tls12_server tls13_client tls13_server RUNTIME DESTINATION bin)
|
||||
INSTALL(TARGETS gmssl LIBRARY DESTINATION lib)
|
||||
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/gmssl DESTINATION include)
|
||||
|
||||
|
||||
@@ -169,6 +169,7 @@ int cms_encrypted_data_from_der(
|
||||
int cms_encrypted_data_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen);
|
||||
|
||||
int cms_encrypted_data_encrypt_to_der(
|
||||
int version,
|
||||
int content_type,
|
||||
int enc_algor, const uint8_t *iv, size_t ivlen,
|
||||
const uint8_t *content, size_t content_len,
|
||||
@@ -177,6 +178,7 @@ int cms_encrypted_data_encrypt_to_der(
|
||||
const uint8_t *key, size_t keylen,
|
||||
uint8_t **out, size_t *outlen);
|
||||
int cms_encrypted_data_decrypt_from_der(
|
||||
int *version,
|
||||
int *content_type,
|
||||
int *enc_algor, const uint8_t **iv, size_t *ivlen,
|
||||
uint8_t *content, size_t *content_len,
|
||||
@@ -238,8 +240,7 @@ int cms_signer_info_sign_to_der(
|
||||
const uint8_t *serial_number, size_t serial_number_len,
|
||||
const uint8_t *authed_attrs, size_t authed_attrs_len,
|
||||
const uint8_t *unauthed_attrs, size_t unauthed_attrs_len,
|
||||
const SM3_CTX *sm3_ctx,
|
||||
const SM2_KEY *sign_key, const char *signer_id, size_t signer_id_len,
|
||||
const SM3_CTX *sm3_ctx, const SM2_KEY *sign_key,
|
||||
uint8_t **out, size_t *outlen);
|
||||
int cms_signer_info_verify_from_der(
|
||||
int *version,
|
||||
@@ -250,7 +251,7 @@ int cms_signer_info_verify_from_der(
|
||||
int *signature_algor,
|
||||
const uint8_t **enced_digest, size_t *enced_digest_len,
|
||||
const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len,
|
||||
const uint8_t *certs, size_t certslen,
|
||||
const SM3_CTX *sm3_ctx, const SM2_KEY *sign_pub_key,
|
||||
const uint8_t **in, size_t *inlen);
|
||||
|
||||
/*
|
||||
@@ -263,8 +264,7 @@ int cms_signer_infos_add_signer_info(
|
||||
const uint8_t *serial_number, size_t serial_number_len,
|
||||
const uint8_t *authed_attrs, size_t authed_attrs_len,
|
||||
const uint8_t *unauthed_attrs, size_t unauthed_attrs_len,
|
||||
const SM3_CTX *sm3_ctx,
|
||||
const SM2_KEY *sign_key, const char *signer_id, size_t signer_id_len);
|
||||
const SM3_CTX *sm3_ctx, const SM2_KEY *sign_key);
|
||||
|
||||
#define cms_signer_infos_to_der(d,dlen,out,outlen) asn1_set_to_der(d,dlen,out,outlen)
|
||||
#define cms_signer_infos_from_der(d,dlen,in,inlen) asn1_set_from_der(d,dlen,in,inlen)
|
||||
@@ -293,6 +293,11 @@ int cms_extened_certs_add_cert(uint8_t *d, size_t *dlen, size_t maxlen, const ui
|
||||
#define cms_extened_certs_from_der(d,dlen,in,inlen) asn1_set_from_der(d,dlen,in,inlen)
|
||||
int cms_extended_certs_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen);
|
||||
|
||||
int cms_digest_algors_to_der(const int *digest_algors, size_t digest_algors_cnt, uint8_t **out, size_t *outlen);
|
||||
int cms_digest_algors_from_der(int *digest_algors, size_t *digest_algors_cnt, size_t max_digest_algors,
|
||||
const uint8_t **in, size_t *inlen);
|
||||
int cms_digest_algors_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen);
|
||||
|
||||
/*
|
||||
SignedData ::= SEQUENCE {
|
||||
version INTEGER (1),
|
||||
@@ -304,15 +309,15 @@ SignedData ::= SEQUENCE {
|
||||
*/
|
||||
int cms_signed_data_to_der(
|
||||
int version,
|
||||
const int *digest_algors, const size_t digest_algors_cnt,
|
||||
const int *digest_algors, size_t digest_algors_cnt,
|
||||
const int content_type, const uint8_t *content, const size_t content_len,
|
||||
const uint8_t *certs, size_t certs_len,
|
||||
const uint8_t *crls, const size_t crls_lens,
|
||||
const uint8_t *signer_infos, size_t signer_infos_lens,
|
||||
const uint8_t *crls, const size_t crls_len,
|
||||
const uint8_t *signer_infos, size_t signer_infos_len,
|
||||
uint8_t **out, size_t *outlen);
|
||||
int cms_signed_data_from_der(
|
||||
int *version,
|
||||
const uint8_t *digest_algors, size_t *digest_algors_count, size_t max_digest_algors,
|
||||
int *digest_algors, size_t *digest_algors_cnt, size_t max_digest_algors,
|
||||
int *content_type, const uint8_t **content, size_t *content_len,
|
||||
const uint8_t **certs, size_t *certs_len,
|
||||
const uint8_t **crls, size_t *crls_len,
|
||||
@@ -401,7 +406,7 @@ int cms_enveloped_data_to_der(
|
||||
const uint8_t *enced_content, size_t enced_content_len,
|
||||
const uint8_t *shared_info1, size_t shared_info1_len,
|
||||
const uint8_t *shared_info2, size_t shared_info2_len,
|
||||
const uint8_t **out, size_t *outlen);
|
||||
uint8_t **out, size_t *outlen);
|
||||
int cms_enveloped_data_from_der(
|
||||
int *version,
|
||||
const uint8_t **rcpt_infos, size_t *rcpt_infos_len,
|
||||
@@ -445,7 +450,7 @@ SignedAndEnvelopedData ::= SEQUENCE {
|
||||
int cms_signed_and_enveloped_data_to_der(
|
||||
int version,
|
||||
const uint8_t *rcpt_infos, size_t rcpt_infos_len,
|
||||
const int *digest_algors, size_t digest_algors_count,
|
||||
const int *digest_algors, size_t digest_algors_cnt,
|
||||
int content_type,
|
||||
int enc_algor, const uint8_t *iv, size_t ivlen,
|
||||
const uint8_t *enced_content, size_t enced_content_len,
|
||||
@@ -453,11 +458,12 @@ int cms_signed_and_enveloped_data_to_der(
|
||||
const uint8_t *shared_info2, size_t shared_info2_len,
|
||||
const uint8_t *certs, size_t certs_len,
|
||||
const uint8_t *crls, size_t crls_len,
|
||||
const uint8_t *signer_infos, size_t signer_infos_len);
|
||||
const uint8_t *signer_infos, size_t signer_infos_len,
|
||||
uint8_t **out, size_t *outlen);
|
||||
int cms_signed_and_enveloped_data_from_der(
|
||||
int *version,
|
||||
const uint8_t **rcpt_infos, size_t *rcpt_infos_len,
|
||||
const uint8_t **digest_algors, size_t *digest_algors_len,
|
||||
int *digest_algors, size_t *digest_algors_cnt, size_t max_digest_algors,
|
||||
int *content_type,
|
||||
int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len,
|
||||
const uint8_t **enced_content, size_t *enced_content_len,
|
||||
@@ -527,14 +533,14 @@ int cms_key_agreement_info_print(FILE *fp, int fmt, int ind, const char *label,
|
||||
|
||||
|
||||
// 生成ContentInfo, type == data
|
||||
int cms_set_data(uint8_t *cms, size_t *cms_len, const uint8_t *d, size_t dlen);
|
||||
int cms_set_data(uint8_t *cms, size_t *cmslen, size_t maxlen, const uint8_t *d, size_t dlen);
|
||||
|
||||
int cms_encrypt(
|
||||
int enc_algor, const uint8_t *key, size_t keylen, const uint8_t *iv, size_t ivlen, // 对称加密算法、密钥和IV
|
||||
int content_type, const uint8_t *content, size_t content_len, // 待加密的输入数据
|
||||
const uint8_t *shared_info1, size_t shared_info1_len, // 附加信息
|
||||
const uint8_t *shared_info2, size_t shared_info2_len, // 附加信息
|
||||
uint8_t *cms, size_t *cms_len); // 输出的ContentInfo (type encryptedData)
|
||||
uint8_t *cms, size_t *cmslen, size_t maxlen); // 输出的ContentInfo (type encryptedData)
|
||||
|
||||
int cms_decrypt(
|
||||
const uint8_t *key, size_t keylen, // 解密密钥(我们不知道解密算法)
|
||||
|
||||
@@ -273,6 +273,8 @@ int x509_cert_sign(
|
||||
int x509_cert_verify(const uint8_t *a, size_t alen, const SM2_KEY *pub_key, const char *signer_id, size_t signer_id_len);
|
||||
int x509_cert_verify_by_ca_cert(const uint8_t *a, size_t alen, const uint8_t *cacert, size_t cacertlen);
|
||||
|
||||
int x509_cert_to_der(const uint8_t *a, size_t alen, uint8_t **out, size_t *outlen);
|
||||
int x509_cert_from_der(const uint8_t **a, size_t *alen, const uint8_t **in, size_t *inlen);
|
||||
int x509_cert_to_pem(const uint8_t *a, size_t alen, FILE *fp);
|
||||
int x509_cert_from_pem(uint8_t *a, size_t *alen, size_t maxlen, FILE *fp);
|
||||
int x509_cert_from_pem_by_index(uint8_t *a, size_t *alen, size_t maxlen, int index, FILE *fp);
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
#include <gmssl/chacha20.h>
|
||||
#include "endian.h"
|
||||
|
||||
void chacha20_set_key(CHACHA20_STATE *state,
|
||||
void chacha20_init(CHACHA20_STATE *state,
|
||||
const uint8_t key[CHACHA20_KEY_SIZE],
|
||||
const uint8_t nonce[CHACHA20_NONCE_SIZE],
|
||||
uint32_t counter)
|
||||
|
||||
@@ -994,6 +994,16 @@ int x509_cert_verify_by_ca_cert(const uint8_t *a, size_t alen, const uint8_t *ca
|
||||
return ret;
|
||||
}
|
||||
|
||||
int x509_cert_to_der(const uint8_t *a, size_t alen, uint8_t **out, size_t *outlen)
|
||||
{
|
||||
return asn1_any_to_der(a, alen, out, outlen);
|
||||
}
|
||||
|
||||
int x509_cert_from_der(const uint8_t **a, size_t *alen, const uint8_t **in, size_t *inlen)
|
||||
{
|
||||
return asn1_any_from_der(a, alen, in, inlen);
|
||||
}
|
||||
|
||||
int x509_cert_to_pem(const uint8_t *a, size_t alen, FILE *fp)
|
||||
{
|
||||
if (pem_write(fp, "CERTIFICATE", a, alen) != 1) {
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
|
||||
#define OCTETS_1 "\x12\x34\x45\x56"
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
static void print_buf(const uint8_t *a, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
@@ -540,7 +543,7 @@ static int test_asn1_generalized_time(void)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -552,18 +555,18 @@ static int test_asn1_generalized_time(void)
|
||||
int main(void)
|
||||
{
|
||||
int err = 0;
|
||||
err += test_asn1_tag();
|
||||
err += test_asn1_length();
|
||||
err += test_asn1_boolean();
|
||||
err += test_asn1_integer();
|
||||
//err += test_asn1_tag();
|
||||
//err += test_asn1_length();
|
||||
//err += test_asn1_boolean();
|
||||
//err += test_asn1_integer();
|
||||
//err += test_asn1_bit_string();
|
||||
err += test_asn1_null();
|
||||
err += test_asn1_object_identifier();
|
||||
err += test_asn1_printable_string();
|
||||
err += test_asn1_utf8_string();
|
||||
err += test_asn1_ia5_string();
|
||||
err += test_asn1_utc_time();
|
||||
err += test_asn1_generalized_time();
|
||||
//err += test_asn1_null();
|
||||
//err += test_asn1_object_identifier();
|
||||
//err += test_asn1_printable_string();
|
||||
//err += test_asn1_utf8_string();
|
||||
//err += test_asn1_ia5_string();
|
||||
//err += test_asn1_utc_time();
|
||||
//err += test_asn1_generalized_time();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -51,44 +51,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/block_cipher.h>
|
||||
|
||||
|
||||
int block_cipher_sm4_test(void)
|
||||
int main(void)
|
||||
{
|
||||
static char *iv_hex[] = {
|
||||
"A9993E364706816ABA3E25717850C26C9CD0D89D",
|
||||
"A9993E364706816ABA3E25717850C26C9CD0D89D",
|
||||
};
|
||||
|
||||
// 提供256比特的密钥长度
|
||||
static char *key_hex[] = {
|
||||
};
|
||||
|
||||
static char *plaintext_hex[] = {
|
||||
};
|
||||
|
||||
static char *ciphertext_hex[] = {
|
||||
};
|
||||
|
||||
const BLOCK_CIPEHR *cipher;
|
||||
BLOCK_CIPHER_KEY cipher_key;
|
||||
uint8_t key[32];
|
||||
uint8_t iv[16];
|
||||
uint8_t plaintext[16 * 3];
|
||||
uint8_t ciphertext[16 * 4];
|
||||
uint8_t buf[16 * 4];
|
||||
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
hex2bin(key_hex, strlen(key_hex), key);
|
||||
hex2bin(iv_hex, strlen(iv_hex), iv);
|
||||
hex2bin(plaintext_hex, strlen(plaintext_hex), plaintext);
|
||||
hex2bin(ciphertext_hex, strlen(ciphertext_hex), ciphertext);
|
||||
|
||||
block_cipher_set_encrypt_key(&cipher_key, cipher, key, 16, iv);
|
||||
block_cipher_cbc_encrypt(&cipher_key, iv, plaintext, 3, buf);
|
||||
|
||||
if (memcmp(buf, 16 * 3, ciphertext) != 0) {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ int main(void)
|
||||
unsigned char buf[64];
|
||||
|
||||
CHACHA20_STATE state;
|
||||
chacha20_set_key(&state, key, nonce, counter);
|
||||
chacha20_init(&state, key, nonce, counter);
|
||||
chacha20_generate_keystream(&state, 1, buf);
|
||||
|
||||
if (memcmp(buf, testdata, sizeof(testdata)) != 0) {
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include <gmssl/sm4.h>
|
||||
#include <gmssl/cms.h>
|
||||
|
||||
#if 0
|
||||
static int test_cms_data(void)
|
||||
{
|
||||
uint8_t data[20];
|
||||
@@ -604,7 +605,7 @@ static int test_cms_sign(void)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -620,7 +621,7 @@ int main(void)
|
||||
//test_cms_recipient_info();
|
||||
//test_cms_signer_info();
|
||||
//test_cms_signed_data();
|
||||
test_cms_enveloped_data();
|
||||
//test_cms_enveloped_data();
|
||||
//test_cms_sign();
|
||||
return 0;
|
||||
}
|
||||
|
||||
57
tests/ectest.c
Normal file
57
tests/ectest.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project.
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||
* products derived from this software without prior written
|
||||
* permission. For written permission, please contact
|
||||
* guanzhi1980@gmail.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "GmSSL"
|
||||
* nor may "GmSSL" appear in their names without prior written
|
||||
* permission of the GmSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/ec.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
57
tests/hextest.c
Normal file
57
tests/hextest.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project.
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||
* products derived from this software without prior written
|
||||
* permission. For written permission, please contact
|
||||
* guanzhi1980@gmail.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "GmSSL"
|
||||
* nor may "GmSSL" appear in their names without prior written
|
||||
* permission of the GmSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/hex.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ int main(void)
|
||||
size_t len;
|
||||
|
||||
for (i = 0; i < sizeof(pbkdf2_hmac_sha1_tests)/sizeof(pbkdf2_hmac_sha1_tests[0]); i++) {
|
||||
hex2bin(pbkdf2_hmac_sha1_tests[i].dk, strlen(pbkdf2_hmac_sha1_tests[i].dk), buf);
|
||||
hex_to_bytes(pbkdf2_hmac_sha1_tests[i].dk, strlen(pbkdf2_hmac_sha1_tests[i].dk), buf, &len);
|
||||
|
||||
pbkdf2_genkey(DIGEST_sha1(),
|
||||
pbkdf2_hmac_sha1_tests[i].pass, strlen(pbkdf2_hmac_sha1_tests[i].pass),
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project.
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||
* products derived from this software without prior written
|
||||
* permission. For written permission, please contact
|
||||
* guanzhi1980@gmail.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "GmSSL"
|
||||
* nor may "GmSSL" appear in their names without prior written
|
||||
* permission of the GmSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/pem.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ static int test_pkcs8(void)
|
||||
const uint8_t *cp = buf;
|
||||
size_t len = 0;
|
||||
|
||||
sm2_keygen(&sm2_key);
|
||||
sm2_key_generate(&sm2_key);
|
||||
memcpy(&sm2_buf, &sm2_key, sizeof(sm2_key));
|
||||
//sm2_key_print(stdout, &sm2_key, 0, 0);
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ int main(void)
|
||||
|
||||
for (i = 0; i < sizeof(keybits)/sizeof(keybits[0]); i++) {
|
||||
int e = 0;
|
||||
rc4_set_key(&state, key1, keybits[i]/8);
|
||||
rc4_init(&state, key1, keybits[i]/8);
|
||||
rc4_generate_keystream(&state, sizeof(buf), buf);
|
||||
for (j = 0; j < sizeof(testindex)/sizeof(testindex[0]); j++) {
|
||||
if (memcmp(buf + testindex[j], &testdata1[i][j * 16], 16) != 0) {
|
||||
@@ -410,7 +410,7 @@ int main(void)
|
||||
|
||||
for (i = 0; i < sizeof(keybits)/sizeof(keybits[0]); i++) {
|
||||
int e = 0;
|
||||
rc4_set_key(&state, key2 + sizeof(key2) - keybits[i]/8, keybits[i]/8);
|
||||
rc4_init(&state, key2 + sizeof(key2) - keybits[i]/8, keybits[i]/8);
|
||||
rc4_generate_keystream(&state, sizeof(buf), buf);
|
||||
for (j = 0; j < sizeof(testindex)/sizeof(testindex[0]); j++) {
|
||||
if (memcmp(buf + testindex[j], &testdata2[i][j * 16], 16) != 0) {
|
||||
|
||||
@@ -99,7 +99,6 @@ static int test_sm4_cbc_padding(void)
|
||||
sm4_cbc_padding_decrypt(&dec_key, iv, out, len1, buf, &len2);
|
||||
printf("m = (%zu) ", len2); for (i = 0; i < len2; i++) printf("%02x", buf[i]); printf("\n");
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -313,19 +313,19 @@ static int test_x509_cert_request(void)
|
||||
end:
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int err = 0;
|
||||
//err += test_x509_validity();
|
||||
err += test_x509_signature_algor(OID_sm2sign_with_sm3);
|
||||
err += test_x509_signature_algor(OID_rsasign_with_sm3);
|
||||
err += test_x509_name();
|
||||
err += test_x509_public_key_info();
|
||||
err += test_x509_certificate();
|
||||
err += test_x509_cert_request();
|
||||
//err += test_x509_signature_algor(OID_sm2sign_with_sm3);
|
||||
//err += test_x509_signature_algor(OID_rsasign_with_sm3);
|
||||
//err += test_x509_name();
|
||||
//err += test_x509_public_key_info();
|
||||
//err += test_x509_certificate();
|
||||
//err += test_x509_cert_request();
|
||||
//test_x509_extensions();
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user