- 添加AES128加密解密功能支持安全固件传输 - 实现基于随机数握手的安全会话密钥协商机制 - 集成CRC32带密钥校验确保数据完整性 - 重构OTA状态机支持握手、数据传输和验证流程 - 添加CANFD数据长度规范处理和安全跳转逻辑 - 移除调试打印语句优化性能 refactor(can): 优化CANFD发送和OTA确认处理逻辑 - 重构CANFD_AsyncSend函数支持规范数据长度 - 重命名sendACK为sendDATA_ACK并添加重载函数 - 修复数据长度处理和缓冲区填充逻辑 - 优化CAN消息发送的数据复制和验证流程 - 移除未使用的联合体类型定义 chore(project): 添加AES加密模块和系统初始化配置 - 在项目配置中添加AES128加密解密文件 - 在main.cpp中初始化CRC外设模块 - 添加安全十六进制打印调试函数 - 集成AES加密库到OTA处理流程中 - 优化系统时钟初始化配置
39 lines
1.3 KiB
C
39 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 */ |