- 添加OTA固件升级功能,包括应用程序验证和跳转机制 - 实现CANFD数据传输协议,支持加密和CRC校验 - 优化CAN通信处理,添加调试输出和错误处理 - 更新RTE组件配置,升级csolution版本到2.12.0 - 增加Flash擦除和写入的安全验证机制 - 添加应用程序区域扫描和验证功能 refactor(can): 重构CAN通信模块和OTA数据处理 - 移除未使用的常量定义和辅助函数 - 改进数据解包和加密解密流程 - 添加条件编译调试输出 - 优化Flash操作的安全性和可靠性 chore(build): 更新项目配置和忽略文件 - 添加tmp/和out/目录到.gitignore - 扩展ROM0_SIZE从0x0020000到0x08005000 - 添加bin输出格式支持
42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
#ifndef __AES_H
|
|
#define __AES_H
|
|
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
// AES-128 密钥长度 (16 bytes)
|
|
#define AES128_KEY_LEN 16
|
|
// AES 块大小 (16 bytes)
|
|
#define AES_BLOCK_SIZE 16
|
|
|
|
// AES 状态结构
|
|
typedef struct {
|
|
u8 key[AES128_KEY_LEN]; // 128位/16字节密钥
|
|
u8 round_keys[11][16]; // 10轮 + 初始轮密钥
|
|
u8 state[AES_BLOCK_SIZE]; // 状态矩阵
|
|
} aes128_context;
|
|
|
|
// 内部函数声明(需要在头文件中声明,因为解密函数会使用)
|
|
void add_round_key(u8 *state, const u8 *round_key);
|
|
void sub_bytes(u8 *state);
|
|
void shift_rows(u8 *state);
|
|
void mix_columns(u8 *state);
|
|
void inv_sub_bytes(u8 *state);
|
|
void inv_shift_rows(u8 *state);
|
|
void inv_mix_columns(u8 *state);
|
|
|
|
// 公共函数声明
|
|
void aes128_set_key(aes128_context *ctx, const u8 *key);
|
|
void aes128_encrypt_block(aes128_context *ctx, const u8 *input, u8 *output);
|
|
void aes128_ecb_encrypt_48bytes(aes128_context *ctx, const u8 *input,
|
|
u8 *output);
|
|
void aes128_decrypt_block(aes128_context *ctx, const u8 *input, u8 *output);
|
|
void aes128_ecb_decrypt_48bytes(aes128_context *ctx, const u8 *input,
|
|
u8 *output);
|
|
u8 aes128_verify_encryption(aes128_context *ctx, const u8 *original_data,
|
|
size_t length);
|
|
|
|
// 逆S盒 (用于解密)
|
|
extern const u8 inv_sbox[256];
|
|
|
|
#endif /* __AES_H */ |