Skip to content

Commit 0cd3bd7

Browse files
Merge pull request #7653 from SparkiDev/sm2_offical_tv
SM2: change to official test vector
2 parents 1eea372 + 8d77df1 commit 0cd3bd7

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32071,6 +32071,7 @@ static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
3207132071

3207232072
static int test_sm2_create_digest(void)
3207332073
{
32074+
#ifndef WOLFSSL_SM3
3207432075
const byte msg[] = "message to sign";
3207532076
const byte id[] = "0123456789";
3207632077
const byte badId[] = "0123556789";
@@ -32090,7 +32091,32 @@ static int test_sm2_create_digest(void)
3209032091
"89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
3209132092
const char d[] =
3209232093
"b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
32094+
int hash_type = WC_HASH_TYPE_SHA256;
3209332095
byte digest[WC_SHA256_DIGEST_SIZE];
32096+
#else
32097+
ecc_key key;
32098+
int ret;
32099+
const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
32100+
0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
32101+
const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
32102+
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
32103+
0x00 };
32104+
const byte badId[] = "0123556789";
32105+
const char qx[] =
32106+
"09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
32107+
const char qy[] =
32108+
"CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
32109+
const char d[] =
32110+
"3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
32111+
byte expected[] = {
32112+
0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
32113+
0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
32114+
0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
32115+
0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
32116+
};
32117+
int hash_type = WC_HASH_TYPE_SM3;
32118+
byte digest[WC_SM3_DIGEST_SIZE];
32119+
#endif
3209432120

3209532121
ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
3209632122
if (ret != 0)
@@ -32101,17 +32127,17 @@ static int test_sm2_create_digest(void)
3210132127
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
3210232128

3210332129
ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
32104-
msg, (int)XSTRLEN((const char*)msg), WC_HASH_TYPE_SHA256, digest,
32105-
WC_SHA256_DIGEST_SIZE, &key);
32130+
msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
32131+
&key);
3210632132
if (ret != 0)
3210732133
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
3210832134

3210932135
if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
3211032136
ERROR_OUT(WC_TEST_RET_ENC_NC, done);
3211132137

3211232138
ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
32113-
msg, (int)XSTRLEN((const char*)msg), WC_HASH_TYPE_SHA256, digest,
32114-
WC_SHA256_DIGEST_SIZE, &key);
32139+
msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
32140+
&key);
3211532141
if (ret != 0)
3211632142
goto done;
3211732143

0 commit comments

Comments
 (0)