mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Update SM4 API
This commit is contained in:
@@ -91,49 +91,36 @@ static int test_sm4(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int test_sm4_speed(void)
|
||||
static int test_sm4_encrypt_speed(void)
|
||||
{
|
||||
SM4_KEY sm4_key;
|
||||
uint8_t key[16] = {0};
|
||||
uint8_t block[16] = {0};
|
||||
clock_t start, end;
|
||||
uint8_t buf[16];
|
||||
size_t nbytes = 16 * 1024 * 1024;
|
||||
clock_t begin, end;
|
||||
double seconds;
|
||||
int i;
|
||||
|
||||
sm4_set_encrypt_key(&sm4_key, key);
|
||||
|
||||
start = clock();
|
||||
for (i = 0; i < 1024*1024; i++) {
|
||||
sm4_encrypt(&sm4_key, block, block);
|
||||
begin = clock();
|
||||
for (i = 0; i < nbytes/sizeof(buf); i++) {
|
||||
sm4_encrypt(&sm4_key, buf, buf);
|
||||
}
|
||||
end = clock();
|
||||
|
||||
seconds = (double)(end - start)/ CLOCKS_PER_SEC;
|
||||
|
||||
fprintf(stderr, "sm4_encrypt: %f-MiB per seconds\n", 16/seconds);
|
||||
seconds = (double)(end - begin)/ CLOCKS_PER_SEC;
|
||||
fprintf(stderr, "sm4_encrypt: %f MiB per second\n", nbytes/(1024 * 1024 *seconds));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (test_sm4() != 1) goto err;
|
||||
if (test_sm4_speed() != 1) goto err;
|
||||
|
||||
|
||||
/*
|
||||
if (test_sm4_cbc() != 1) goto err;
|
||||
if (test_sm4_cbc_padding() != 1) goto err;
|
||||
|
||||
if (test_sm4_gcm() != 1) goto err;
|
||||
if (test_sm4_gcm_gbt36624_1() != 1) goto err;
|
||||
if (test_sm4_gcm_gbt36624_2() != 1) goto err;
|
||||
if (test_sm4_cbc_update() != 1) goto err;
|
||||
|
||||
|
||||
*/
|
||||
#if ENABLE_TEST_SPEED
|
||||
if (test_sm4_encrypt_speed() != 1) goto err;
|
||||
#endif
|
||||
printf("%s all tests passed\n", __FILE__);
|
||||
return 0;
|
||||
err:
|
||||
|
||||
Reference in New Issue
Block a user