new file: .gitignore new file: .vscode/settings.json new file: LICENSE new file: README.md new file: SConscript new file: SConstruct new file: algo.py new file: inc/type.h new file: inc/zuc256.h new file: run.sh new file: src/main.c new file: src/zuc256.c
37 lines
1002 B
C
37 lines
1002 B
C
#ifndef ZUC256_H
|
||
#define ZUC256_H
|
||
|
||
#include <stdint.h>
|
||
#include <stddef.h>
|
||
|
||
// ZUC256算法上下文结构
|
||
typedef struct {
|
||
uint32_t LFSR[16]; // 线性反馈移位寄存器
|
||
uint32_t NFSR[16]; // 非线性反馈移位寄存器
|
||
uint32_t R1, R2; // 寄存器
|
||
uint32_t key[8]; // 256位密钥 (8*32)
|
||
uint32_t iv[4]; // 128位初始向量 (4*32)
|
||
} zuc256_context;
|
||
|
||
/**
|
||
* @brief 初始化ZUC256算法上下文
|
||
*
|
||
* @param ctx 算法上下文指针
|
||
* @param key 256位密钥(32字节)
|
||
* @param iv 128位初始向量(16字节)
|
||
*/
|
||
void zuc256_init(zuc256_context *ctx, const uint8_t *key, const uint8_t *iv);
|
||
|
||
/**
|
||
* @brief 使用ZUC256算法进行加密或解密
|
||
*
|
||
* @param ctx 算法上下文指针
|
||
* @param input 输入数据
|
||
* @param output 输出数据(与输入数据长度相同)
|
||
* @param length 数据长度(字节数)
|
||
*/
|
||
void zuc256_crypt(zuc256_context *ctx, const uint8_t *input, uint8_t *output, size_t length);
|
||
|
||
#endif // ZUC256_H
|
||
|