mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Update ZUC algorithm with EVP module
128-EEA3, 128-EIA3, byte-order and tests need to be updated.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2014 - 2017 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
|
||||
@@ -920,6 +920,10 @@ const EVP_CIPHER *EVP_sms4_wrap_pad(void);
|
||||
# define EVP_sm4_ofb EVP_sms4_ofb
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_ZUC
|
||||
const EVP_CIPHER *EVP_zuc(void);
|
||||
# endif
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define OPENSSL_add_all_algorithms_conf() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2015 - 2016 The GmSSL Project. All rights reserved.
|
||||
* Copyright (c) 2015 - 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
|
||||
@@ -51,73 +51,82 @@
|
||||
#define HEADER_ZUC_H
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#ifndef OPENSSL_NO_ZUC
|
||||
# ifndef OPENSSL_NO_ZUC
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <openssl/e_os2.h>
|
||||
# include <stdlib.h>
|
||||
# include <openssl/e_os2.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define ZUC_IV_LENGTH 16
|
||||
# define ZUC_KEY_LENGTH 16
|
||||
|
||||
typedef uint32_t ZUC_UINT1;
|
||||
typedef uint32_t ZUC_UINT5;
|
||||
typedef uint32_t ZUC_UINT15;
|
||||
typedef uint32_t ZUC_UINT31;
|
||||
typedef uint32_t ZUC_UINT32;
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t state[22];
|
||||
} zuc_key_t;
|
||||
/* ZUC stream cipher */
|
||||
|
||||
void zuc_set_key(zuc_key_t *key, const unsigned char *user_key, const unsigned char *iv);
|
||||
void zuc_generate_keystream(zuc_key_t *key, size_t nwords, uint32_t *words);
|
||||
typedef struct zuc_key_st {
|
||||
ZUC_UINT31 LFSR[16];
|
||||
uint32_t R1;
|
||||
uint32_t R2;
|
||||
} ZUC_KEY;
|
||||
|
||||
typedef struct {
|
||||
zuc_key_t key;
|
||||
unsigned char buf[4];
|
||||
size_t buflen;
|
||||
} zuc_ctx_t;
|
||||
void ZUC_set_key(ZUC_KEY *key, const unsigned char *user_key, const unsigned char *iv);
|
||||
void ZUC_generate_keystream(ZUC_KEY *key, size_t nwords, uint32_t *words);
|
||||
uint32_t ZUC_generate_keyword(ZUC_KEY *key);
|
||||
|
||||
void zuc_ctx_init(zuc_ctx_t *ctx, const unsigned char *user_key, const unsigned char *iv);
|
||||
void zuc_encrypt(zuc_ctx_t *ctx, size_t len, const unsigned char *in, unsigned char *out);
|
||||
#define zuc_decrypt(ctx,len,in,out) zuc_encrypt(ctx,len,in,out)
|
||||
# define ZUC_128EEA3_MIN_BITS 1
|
||||
# define ZUC_128EEA3_MAX_BITS 65504
|
||||
# define ZUC_128EEA3_MIN_BYTES ((ZUC_128EEA3_MIN_BITS + 7)/8)
|
||||
# define ZUC_128EEA3_MAX_BYTES ((ZUC_128EEA3_MAX_BITS + 7)/8)
|
||||
|
||||
#define ZUC_128EEA3_MIN_BITS 1
|
||||
#define ZUC_128EEA3_MAX_BITS 65504
|
||||
#define ZUC_128EEA3_MIN_BYTES ((ZUC_128EEA3_MIN_BITS + 7)/8)
|
||||
#define ZUC_128EEA3_MAX_BYTES ((ZUC_128EEA3_MAX_BITS + 7)/8)
|
||||
/* ZUC 128-EEA3 */
|
||||
|
||||
typedef struct {
|
||||
zuc_ctx_t zuc;
|
||||
size_t length;
|
||||
/* maybe buffer */
|
||||
} eea3_ctx_t;
|
||||
typedef struct zuc_128eea3_st {
|
||||
ZUC_KEY ks;
|
||||
} ZUC_128EEA3;
|
||||
|
||||
void zuc_128eea3_init(zuc_128eea3_t *eea3, const unsigned char *user_key,
|
||||
uint32_t count, uint32_t bearer, int direction);
|
||||
void zuc_128eea3_encrypt(zuc_128eea3_t *ctx, size_t len,
|
||||
void ZUC_128eea3_set_key(ZUC_128EEA3 *ctx, const unsigned char user_key[16],
|
||||
ZUC_UINT32 count, ZUC_UINT5 bearer, ZUC_UINT1 direction);
|
||||
void ZUC_128eea3_encrypt(ZUC_128EEA3 *ctx, size_t len,
|
||||
const unsigned char *in, unsigned char *out);
|
||||
#define eea3_decrypt(ctx,len,in,out) eea3_encrypt(ctx,len,in,out)
|
||||
void eea3(const unsigned char *key, uint32_t count, uint32_t bearer,
|
||||
int direction, size_t len, const unsigned char *in, unsigned char *out);
|
||||
# define ZUC_128eea3_decrypt(ctx,len,in,out) \
|
||||
ZUC_128eea3_encrypt(ctx,len,in,out)
|
||||
void ZUC_128eea3(const unsigned char key[ZUC_KEY_LENGTH],
|
||||
ZUC_UINT32 count, ZUC_UINT5 bearer, ZUC_UINT1 direction,
|
||||
size_t len, const unsigned char *in, unsigned char *out);
|
||||
|
||||
#define ZUC_128EIA3_MIN_BYTES EEA3_MIN_BYTES
|
||||
#define ZUC_128EIA3_MAX_BYTES EEA3_MAX_BYTES
|
||||
#define ZUC_128EIA3_MAC_SIZE 4
|
||||
/* ZUC 128-EIA3 */
|
||||
|
||||
typedef struct {
|
||||
zuc_ctx_t zuc;
|
||||
size_t length;
|
||||
/* maybe buffer */
|
||||
} eia3_ctx_t;
|
||||
# define ZUC_128EIA3_MIN_BYTES EEA3_MIN_BYTES
|
||||
# define ZUC_128EIA3_MAX_BYTES EEA3_MAX_BYTES
|
||||
# define ZUC_128EIA3_MAC_SIZE 4
|
||||
|
||||
void zuc_128eia3_init(zuc_128eia3_t *eia3, const unsigned char *user_key,
|
||||
uint32_t count, uint32_t bearer, int direction);
|
||||
void zuc_128eia3_update(zuc_128eia3_t *eia3, const unsigned char *data,
|
||||
typedef struct zuc_128eia3_st {
|
||||
ZUC_KEY ks;
|
||||
unsigned char buf[4];
|
||||
size_t num;
|
||||
} ZUC_128EIA3;
|
||||
|
||||
void ZUC_128eia3_set_key(ZUC_128EIA3 *ctx, const unsigned char *user_key,
|
||||
ZUC_UINT32 count, ZUC_UINT5 bearer, ZUC_UINT1 direction);
|
||||
void ZUC_128eia3_update(ZUC_128EIA3 *ctx, const unsigned char *data,
|
||||
size_t datalen);
|
||||
void zuc_128eia3_final(zuc_128eia3_t *eia3, uint32_t *mac);
|
||||
void zuc_128eia3(const unsigned char *key, uint32_t count, uint32_t bearer,
|
||||
int direction, const unsigned char *data, size_t len, uint32_t *mac);
|
||||
void ZUC_128eia3_final(ZUC_128EIA3 *ctx, uint32_t *mac);
|
||||
void ZUC_128eia3(const unsigned char key[ZUC_KEY_LENGTH],
|
||||
ZUC_UINT32 count, ZUC_UINT5 bearer, ZUC_UINT1 direction,
|
||||
const unsigned char *data, size_t dlen, uint32_t *mac);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user