mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-08 23:13:38 +08:00
Update sm3test.c
This commit is contained in:
@@ -53,8 +53,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <gmssl/sm3.h>
|
#include <gmssl/sm3.h>
|
||||||
#include <gmssl/hex.h>
|
#include <gmssl/hex.h>
|
||||||
|
#include <gmssl/error.h>
|
||||||
|
|
||||||
static char *testhex[] = {
|
|
||||||
|
static int test_sm3(void)
|
||||||
|
{
|
||||||
|
const char *testhex[] = {
|
||||||
/* 0 "abc" */
|
/* 0 "abc" */
|
||||||
"616263",
|
"616263",
|
||||||
/* 1 "abcd" 16 times */
|
/* 1 "abcd" 16 times */
|
||||||
@@ -161,7 +165,7 @@ static char *testhex[] = {
|
|||||||
"03020057",
|
"03020057",
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *dgsthex[] = {
|
const char *dgsthex[] = {
|
||||||
"66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0",
|
"66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0",
|
||||||
"debe9ff92275b8a138604889c18e5a4d6fdb70e5387e5765293dcba39c0c5732",
|
"debe9ff92275b8a138604889c18e5a4d6fdb70e5387e5765293dcba39c0c5732",
|
||||||
"F4A38489E32B45B6F876E3AC2168CA392362DC8F23459C1D1146FC3DBFB7BC9A",
|
"F4A38489E32B45B6F876E3AC2168CA392362DC8F23459C1D1146FC3DBFB7BC9A",
|
||||||
@@ -175,8 +179,6 @@ static char *dgsthex[] = {
|
|||||||
"C3B02E500A8B60B77DEDCF6F4C11BEF8D56E5CDE708C72065654FD7B2167915A",
|
"C3B02E500A8B60B77DEDCF6F4C11BEF8D56E5CDE708C72065654FD7B2167915A",
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
char *p;
|
char *p;
|
||||||
uint8_t testbuf[sizeof(testhex)/2 + 1000];
|
uint8_t testbuf[sizeof(testhex)/2 + 1000];
|
||||||
@@ -193,18 +195,29 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (memcmp(dgstbuf, dgst, sizeof(dgst)) != 0) {
|
if (memcmp(dgstbuf, dgst, sizeof(dgst)) != 0) {
|
||||||
int n;
|
int n;
|
||||||
printf("error calculating SM3 on %s\n", testhex[i]);
|
fprintf(stderr, "sm3 test %lu failed\n", i+1);
|
||||||
printf(" digest(corret) = ");
|
fprintf(stderr, "error calculating SM3 on %s\n", testhex[i]);
|
||||||
|
fprintf(stderr, " digest(corret) = ");
|
||||||
for (n = 0; n < sizeof(dgst); n++) {
|
for (n = 0; n < sizeof(dgst); n++) {
|
||||||
printf("%02X", dgst[n]);
|
fprintf(stderr, "%02X", dgst[n]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
fprintf(stderr, "\n");
|
||||||
printf(" digest(error) = %s\n", dgsthex[i]);
|
fprintf(stderr, " digest(error) = %s\n", dgsthex[i]);
|
||||||
err++;
|
return -1;
|
||||||
} else {
|
|
||||||
printf("sm3 test %lu ok\n", i+1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
printf("%s() ok\n", __FUNCTION__);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
if (test_sm3() != 1) goto err;
|
||||||
|
printf("%s all tests passed\n", __FILE__);
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
error_print();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user