初始化:添加本地配置文件
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
This commit is contained in:
28
inc/type.h
Normal file
28
inc/type.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#ifndef __TYPE_H
|
||||
#define __TYPE_H
|
||||
|
||||
#include <stdint.h>
|
||||
/* IO definitions */
|
||||
#define __I volatile const /* defines 'read only' permissions */
|
||||
|
||||
#define __O volatile /* defines 'write only' permissions */
|
||||
#define __IO volatile /* defines 'read / write' permissions */
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef __IO uint64_t vu64;
|
||||
typedef __IO uint32_t vu32;
|
||||
typedef __IO uint16_t vu16;
|
||||
typedef __IO uint8_t vu8;
|
||||
|
||||
typedef __I uint64_t vuc64; /* Read Only */
|
||||
typedef __I uint32_t vuc32; /* Read Only */
|
||||
typedef __I uint16_t vuc16; /* Read Only */
|
||||
typedef __I uint8_t vuc8; /* Read Only */
|
||||
|
||||
|
||||
#endif /*__TYPE_H*/
|
||||
36
inc/zuc256.h
Normal file
36
inc/zuc256.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user