Skip to content

Commit

Permalink
Add zuc speed test
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Apr 23, 2024
1 parent 329b539 commit 2e45b3f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions tests/zuctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <gmssl/zuc.h>
#include <gmssl/error.h>

Expand All @@ -25,7 +26,7 @@ static void bswap_buf(uint32_t *buf, size_t nwords)
}
}

int zuc_test(void)
static int zuc_test(void)
{
unsigned char key[][16] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
Expand Down Expand Up @@ -61,6 +62,30 @@ int zuc_test(void)
return 1;
}

static int test_zuc_encrypt_speed(void)
{
ZUC_STATE zuc_state;
uint8_t key[16];
uint8_t iv[16];
uint8_t buf[4096];
clock_t begin, end;
double seconds;
int i;

zuc_init(&zuc_state, key, iv);

begin = clock();
for (i = 0; i < 4096; i++) {
zuc_encrypt(&zuc_state, buf, sizeof(buf), buf);
}
end = clock();
seconds = (double)(end - begin)/CLOCKS_PER_SEC;

fprintf(stderr, "speed zuc_encrypt: %f-MiB per seconds\n", 16/seconds);

return 1;
}

/* test vector from GM/T 0001.2-2012 */
static int zuc_eea_test(void)
{
Expand Down Expand Up @@ -284,7 +309,7 @@ static int zuc_eia_test(void)
}

/* from ZUC256 draft */
int zuc256_test(void)
static int zuc256_test(void)
{
unsigned char key[][32] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
Expand Down Expand Up @@ -335,7 +360,7 @@ int zuc256_test(void)
return 1;
}

int zuc256_mac_test(void)
static int zuc256_mac_test(void)
{
unsigned char key[][32] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
Expand Down Expand Up @@ -479,5 +504,6 @@ int main(void)
if (zuc_eia_test() != 1) { error_print(); return -1; }
if (zuc256_test() != 1) { error_print(); return -1; }
if (zuc256_mac_test() != 1) { error_print(); return -1; }
if (test_zuc_encrypt_speed() != 1) { error_print(); return -1; }
return 0;
}

0 comments on commit 2e45b3f

Please sign in to comment.