Update SM4 API

This commit is contained in:
Zhi Guan
2024-04-27 12:08:35 +08:00
parent 3f1fdc147a
commit bc15f7a0c7
8 changed files with 157 additions and 113 deletions

View File

@@ -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: