Add tests to fixed bugs

This commit is contained in:
Zhi Guan
2026-06-20 23:56:10 +08:00
parent 0a8dad0f32
commit 1e1822205f
4 changed files with 89 additions and 2 deletions

View File

@@ -874,7 +874,7 @@ endif()
# #
set(CPACK_PACKAGE_NAME "GmSSL") set(CPACK_PACKAGE_NAME "GmSSL")
set(CPACK_PACKAGE_VENDOR "GmSSL develop team") set(CPACK_PACKAGE_VENDOR "GmSSL develop team")
set(CPACK_PACKAGE_VERSION "3.2.0-dev.1124") set(CPACK_PACKAGE_VERSION "3.2.0-dev.1131")
set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README.md) set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README.md)
set(CPACK_NSIS_MODIFY_PATH ON) set(CPACK_NSIS_MODIFY_PATH ON)
include(CPack) include(CPack)

View File

@@ -18,7 +18,7 @@ extern "C" {
#define GMSSL_VERSION_NUM 30200 #define GMSSL_VERSION_NUM 30200
#define GMSSL_VERSION_STR "GmSSL 3.2.0-dev.1124" #define GMSSL_VERSION_STR "GmSSL 3.2.0-dev.1131"
int gmssl_version_num(void); int gmssl_version_num(void);
const char *gmssl_version_str(void); const char *gmssl_version_str(void);

View File

@@ -402,6 +402,43 @@ static int test_asn1_object_identifier(void)
return 1; return 1;
} }
static int test_asn1_object_identifier_max_nodes(void)
{
uint8_t octets[ASN1_OID_MAX_NODES];
uint32_t nodes[ASN1_OID_MAX_NODES];
size_t nodes_cnt;
size_t i;
memset(octets, 0x01, sizeof(octets));
octets[0] = 42; // 1.2
nodes_cnt = 0;
if (asn1_object_identifier_from_octets(nodes, &nodes_cnt, octets, ASN1_OID_MAX_NODES - 1) != 1
|| nodes_cnt != ASN1_OID_MAX_NODES) {
error_print();
return -1;
}
if (nodes[0] != 1 || nodes[1] != 2) {
error_print();
return -1;
}
for (i = 2; i < nodes_cnt; i++) {
if (nodes[i] != 1) {
error_print();
return -1;
}
}
nodes_cnt = 0;
if (asn1_object_identifier_from_octets(nodes, &nodes_cnt, octets, ASN1_OID_MAX_NODES) != -1) {
error_print();
return -1;
}
printf("%s() ok\n", __FUNCTION__);
return 1;
}
static int test_asn1_printable_string(void) static int test_asn1_printable_string(void)
{ {
char *tests[] = { char *tests[] = {
@@ -948,6 +985,7 @@ int main(void)
if (test_asn1_tag() != 1) goto err; if (test_asn1_tag() != 1) goto err;
if (test_asn1_utf8_string() != 1) goto err; if (test_asn1_utf8_string() != 1) goto err;
if (test_asn1_string_code_point_from_bytes() != 1) goto err; if (test_asn1_string_code_point_from_bytes() != 1) goto err;
if (test_asn1_object_identifier_max_nodes() != 1) goto err;
/* /*
if (test_asn1_length() != 1) goto err; if (test_asn1_length() != 1) goto err;
if (test_asn1_length_from_ber() != 1) goto err; if (test_asn1_length_from_ber() != 1) goto err;

View File

@@ -571,6 +571,54 @@ static int test_sm2_z256_point_from_x_bytes(void)
return 1; return 1;
} }
static int test_sm2_z256_point_to_compressed_octets(void)
{
struct {
char *label;
char *point;
char *compressed;
} tests[] = {
{
"G",
"32c4ae2c1f1981195f9904466a39c9948fe30bbff2660be1715a4589334c74c7"
"bc3736a2f4f6779c59bdcee36b692153d0a9877cc62a474002df32e52139f0a0",
"02"
"32c4ae2c1f1981195f9904466a39c9948fe30bbff2660be1715a4589334c74c7",
},
{
"2G",
"56cefd60d7c87c000d58ef57fa73ba4d9c0dfa08c08a7331495c2e1da3f2bd52"
"31b7e7e6cc8189f668535ce0f8eaf1bd6de84c182f6c8e716f780d3a970a23c3",
"03"
"56cefd60d7c87c000d58ef57fa73ba4d9c0dfa08c08a7331495c2e1da3f2bd52",
},
};
SM2_Z256_POINT P;
SM2_Z256_POINT Q;
uint8_t compressed[33];
uint8_t expected[33];
size_t len;
size_t i;
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
sm2_z256_point_from_hex(&P, tests[i].point);
if (hex_to_bytes(tests[i].compressed, strlen(tests[i].compressed), expected, &len) != 1
|| len != sizeof(expected)
|| sm2_z256_point_to_compressed_octets(&P, compressed) != 1
|| memcmp(compressed, expected, sizeof(expected)) != 0
|| sm2_z256_point_from_octets(&Q, compressed, sizeof(compressed)) != 1
|| sm2_z256_point_equ(&P, &Q) != 1) {
fprintf(stderr, "%s\n", tests[i].label);
error_print();
return -1;
}
}
printf("%s() ok\n", __FUNCTION__);
return 1;
}
static int test_sm2_z256_point_add_conjugate(void) static int test_sm2_z256_point_add_conjugate(void)
{ {
char *hex_G = char *hex_G =
@@ -960,6 +1008,7 @@ int main(void)
if (test_sm2_z256_point_mul_generator() != 1) goto err; if (test_sm2_z256_point_mul_generator() != 1) goto err;
if (test_sm2_z256_point_from_hash() != 1) goto err; if (test_sm2_z256_point_from_hash() != 1) goto err;
if (test_sm2_z256_point_from_x_bytes() != 1) goto err; if (test_sm2_z256_point_from_x_bytes() != 1) goto err;
if (test_sm2_z256_point_to_compressed_octets() != 1) goto err;
if (test_sm2_z256_point_dbl_infinity() != 1) goto err; if (test_sm2_z256_point_dbl_infinity() != 1) goto err;