mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-14 01:53:41 +08:00
update zuc
with zuc_spec test passed
This commit is contained in:
@@ -53,18 +53,13 @@
|
||||
#include <stdlib.h>
|
||||
#include "zuc_spec.h"
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t lfsr_s[16];
|
||||
uint32_t f_r[2];
|
||||
uint32_t brc_x[4];
|
||||
uint32_t S[16];
|
||||
uint32_t R1;
|
||||
uint32_t R2;
|
||||
} zuc_key_t;
|
||||
|
||||
|
||||
|
||||
|
||||
static unsigned char S0[256] = {
|
||||
static const unsigned char S0[256] = {
|
||||
0x3e,0x72,0x5b,0x47,0xca,0xe0,0x00,0x33,0x04,0xd1,0x54,0x98,0x09,0xb9,0x6d,0xcb,
|
||||
0x7b,0x1b,0xf9,0x32,0xaf,0x9d,0x6a,0xa5,0xb8,0x2d,0xfc,0x1d,0x08,0x53,0x03,0x90,
|
||||
0x4d,0x4e,0x84,0x99,0xe4,0xce,0xd9,0x91,0xdd,0xb6,0x85,0x48,0x8b,0x29,0x6e,0xac,
|
||||
@@ -83,7 +78,7 @@ static unsigned char S0[256] = {
|
||||
0x8d,0x27,0x1a,0xdb,0x81,0xb3,0xa0,0xf4,0x45,0x7a,0x19,0xdf,0xee,0x78,0x34,0x60,
|
||||
};
|
||||
|
||||
static unsigned char S1[256] = {
|
||||
static const unsigned char S1[256] = {
|
||||
0x55,0xc2,0x63,0x71,0x3b,0xc8,0x47,0x86,0x9f,0x3c,0xda,0x5b,0x29,0xaa,0xfd,0x77,
|
||||
0x8c,0xc5,0x94,0x0c,0xa6,0x1a,0x13,0x00,0xe3,0xa8,0x16,0x72,0x40,0xf9,0xf8,0x42,
|
||||
0x44,0x26,0x68,0x96,0x81,0xd9,0x45,0x3e,0x10,0x76,0xc6,0xa7,0x8b,0x39,0x43,0xe1,
|
||||
@@ -102,21 +97,20 @@ static unsigned char S1[256] = {
|
||||
0x64,0xbe,0x85,0x9b,0x2f,0x59,0x8a,0xd7,0xb0,0x25,0xac,0xaf,0x12,0x03,0xe2,0xf2,
|
||||
};
|
||||
|
||||
uint32_t EK_d[16] = {
|
||||
static uint32_t const EK_d[16] = {
|
||||
0x44D7,0x26BC,0x626B,0x135E,0x5789,0x35E2,0x7135,0x09AF,
|
||||
0x4D78,0x2F13,0x6BC4,0x1AF1,0x5E26,0x3C4D,0x789A,0x47AC,
|
||||
};
|
||||
|
||||
|
||||
inline uint32_t zuc_madd(uint32_t a, uint32_t b)
|
||||
{
|
||||
u32 c = a + b;
|
||||
uint32_t c = a + b;
|
||||
return (c & 0x7FFFFFFF) + (c >> 31);
|
||||
}
|
||||
|
||||
|
||||
/* LFSR with initialization mode */
|
||||
#define MulByPow2(x, k) ((((x) << k) | ((x) >> (31 - k))) & 0x7FFFFFFF)
|
||||
#define MulByPow2(x, k) ((((x) << (k)) | ((x) >> (31 - (k)))) & 0x7FFFFFFF)
|
||||
|
||||
void zuc_lfsr_init(zuc_key_t *key, uint32_t u)
|
||||
{
|
||||
@@ -195,6 +189,12 @@ void zuc_bit_reorganization(zuc_key_t *key)
|
||||
key->brc_x[3] = ((key->lfsr_s[2] & 0xFFFF) << 16) | (key->lfsr_s[0] >> 15);
|
||||
}
|
||||
|
||||
#define ZUC_BIT_REORG(x,x0,x1,x2,x3) \
|
||||
x0 = ((s[15] & 0x7FFF8000) << 1) | (s[14] & 0xFFFF); \
|
||||
x1 = ((s[11] & 0xFFFF) << 16) | (s[9] >> 15); \
|
||||
x2 = ((s[7] & 0xFFFF) << 16) | (s[5] >> 15); \
|
||||
x3 = ((s[2] & 0xFFFF) << 16) | (s[0] >> 15)
|
||||
|
||||
#define ROT32(a, k) (((a) << k) | ((a) >> (32 - k)))
|
||||
|
||||
#define L1(x) \
|
||||
@@ -299,5 +299,3 @@ void ZUC(const unsigned char *key, const unsigned char *iv, uint32_t *keystream,
|
||||
zuc_key_init(&zuc, key, iv);
|
||||
zuc_generate_keystream(&zuc, keystream, num);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user