Update ZUC algorithm with EVP module

128-EEA3, 128-EIA3, byte-order and tests need to be updated.
This commit is contained in:
Zhi Guan
2018-01-03 15:26:09 +08:00
parent f4e43474ab
commit c41e135604
12 changed files with 360 additions and 356 deletions

View File

@@ -1,5 +1,5 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 The GmSSL Project. All rights reserved.
* Copyright (c) 2014 - 2018 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -62,6 +62,20 @@ int main(int argc, char **argv)
# include <openssl/evp.h>
# include <openssl/zuc.h>
/*
static int zuc_128eea3_test1(void)
{
unsigned char ck[] = {
0x17,0x3d,0x14,0xba,0x50,0x03,0x73,0x1d,0x7a,0x60,0x04,0x94,0x70,0xf0,0x0a,0x29,
};
uint32_t count = 0x66035492;
uint8_t bearer = 0x0f;
uint8_t direction = 0;
uint32_t length = c1;
unsigned char ibs[] = {
0x6cf65340, 735552ab,
}
static int zuc_eia3_test1(void)
{
unsigned char key[16] = {0};
@@ -103,24 +117,43 @@ static int zuc_eia3_test2(int verbose)
return 1;
}
*/
int main(int argc, char **argv)
{
int err = 0;
int i;
unsigned char key[][] = {
unsigned char key[][16] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0x3d,0x4c,0x4b,0xe9,0x6a,0x82,0xfd,0xae,0xb5,0x8f,0x64,0x1d,0xb1,0x7b,0x45,0x5b},
};
unsigned char iv[][] = {
unsigned char iv[][16] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0x84,0x31,0x9a,0xa8,0xde,0x69,0x15,0xca,0x1f,0x6b,0xda,0x6b,0xfb,0xd8,0xc7,0x66},
};
uint32_t z0[] = {0x286dafe5,0x668b56df,0x3ead461d};
uint32_t z1[] = {0x27bedc74,0x0657cfa0,0x14f1c272};
uint32_t z2[] = {0x018082da,0x7096398b,0x3279c419};
uint32_t ciphertext[][2] = {
{0x27bede74, 0x018082da},
{0x0657cfa0, 0x7096398b},
{0x14f1c272, 0x3279c419},
};
for (i = 0; i < 3; i++) {
ZUC_KEY zuc = {{0}};
uint32_t buf[3] = {0};
ZUC_set_key(&zuc, key[i], iv[i]);
ZUC_generate_keystream(&zuc, 2, buf);
printf("%08x %08x\n", buf[0], buf[1]);
printf("%08x %08x\n", ciphertext[i][0], ciphertext[i][1]);
if (buf[0] != ciphertext[i][0] || buf[1] != ciphertext[i][1]) {
fprintf(stderr, "error generating ZUC key stream on test vector %d\n", i);
err++;
} else {
fprintf(stderr, "ZUC test vector %d success\n", i);
}
}
return err;
}