mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-16 21:36:28 +08:00
95 lines
2.0 KiB
C
95 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "sm3.h"
|
|
|
|
int sm3_test1()
|
|
{
|
|
char *msg = "abc";
|
|
unsigned char dgst[SM3_DIGEST_LENGTH];
|
|
unsigned char result[] = {
|
|
0x66,0xc7,0xf0,0xf4,0x62,0xee,0xed,0xd9,
|
|
0xd1,0xf2,0xd4,0x6b,0xdc,0x10,0xe4,0xe2,
|
|
0x41,0x67,0xc4,0x87,0x5c,0xf2,0xf7,0xa2,
|
|
0x29,0x7d,0xa0,0x2b,0x8f,0x4b,0xa8,0xe0
|
|
};
|
|
int i;
|
|
|
|
printf("sm3 test 1\n");
|
|
memset(dgst, 0, sizeof(dgst));
|
|
sm3((unsigned char *)msg, strlen(msg), dgst);
|
|
|
|
printf(" message : %s\n", msg);
|
|
printf(" digest : 0x");
|
|
for(i = 0; i < sizeof(dgst); i++) {
|
|
printf("%02x", dgst[i]);
|
|
}
|
|
printf("\n");
|
|
|
|
printf(" result : ");
|
|
if (memcmp(dgst, result, sizeof(result))) {
|
|
printf("failed\n");
|
|
return -1;
|
|
} else {
|
|
printf("passed\n");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int sm3_test2()
|
|
{
|
|
unsigned char msg[] = {
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64,
|
|
};
|
|
|
|
unsigned char dgst[SM3_DIGEST_LENGTH];
|
|
unsigned char result[] = {
|
|
0xde,0xbe,0x9f,0xf9,0x22,0x75,0xb8,0xa1,
|
|
0x38,0x60,0x48,0x89,0xc1,0x8e,0x5a,0x4d,
|
|
0x6f,0xdb,0x70,0xe5,0x38,0x7e,0x57,0x65,
|
|
0x29,0x3d,0xcb,0xa3,0x9c,0x0c,0x57,0x32,
|
|
};
|
|
int i;
|
|
|
|
printf("sm3 test 2\n");
|
|
memset(dgst, 0, sizeof(dgst));
|
|
sm3(msg, sizeof(msg), dgst);
|
|
|
|
printf(" message : 0x");
|
|
for (i = 0; i < sizeof(msg); i++) {
|
|
printf("%02x", msg[i]);
|
|
}
|
|
printf("\n");
|
|
printf(" digest: 0x");
|
|
for (i = 0; i < sizeof(dgst); i++) {
|
|
printf("%02x", dgst[i]);
|
|
}
|
|
printf("\n");
|
|
|
|
printf(" result : ");
|
|
if (memcmp(dgst, result, sizeof(result))) {
|
|
printf("failed\n");
|
|
return -1;
|
|
} else {
|
|
printf("passed\n");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
if (sm3_test1())
|
|
return -1;
|
|
|
|
if (sm3_test2())
|
|
return -2;
|
|
|
|
return 0;
|
|
}
|