HomeServer/lualib-src/lua-aes.h
2024-11-20 15:41:37 +08:00

78 lines
3.8 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#ifndef _AES_H
#define _AES_H
/****************************************************************************
* Include Files
*****************************************************************************/
/*****************************************************************************
* Define
******************************************************************************/
//以bit为单位的密钥长度只能为 128192 和 256 三种
#define AES_KEY_LENGTH 256
//加解密模式
#define AES_MODE_ECB 0 // 电子密码本模式
#define AES_MODE_CBC 1 // 密码分组链接模式
#define AES_MODE AES_MODE_ECB // 配置加密模式
/*****************************************************************************
* Functions Define
******************************************************************************/
/******************************************************************************
// 函数名: AES_Init
// 描述: 初始化,在此执行扩展密钥操作。
// 输入参数: pKey -- 原始密钥,其长度必须为 AES_KEY_LENGTH/8 字节。
// 输出参数: 无。
// 返回值: 无。
******************************************************************************/
extern void AES_Init(const void* pKey);
/******************************************************************************
// 函数名: AES_Encrypt
// 描述: 加密数据
// 输入参数: pPlainText -- 明文即需加密的数据其长度为nDataLen字节。
// nDataLen -- 数据长度以字节为单位必须为AES_KEY_LENGTH/8的整倍数。
// pIV -- 初始化向量如果使用ECB模式可设为NULL。
// 输出参数: pCipherText -- 密文即由明文加密后的数据可以与pPlainText相同。
// 返回值: 无。
******************************************************************************/
void AES_Encrypt(const unsigned char* pPlainText, unsigned char* pCipherText,
unsigned int nDataLen, const unsigned char* pIV);
/******************************************************************************
// 函数名: AES_Decrypt
// 描述: 解密数据
// 输入参数: pCipherText -- 密文即需解密的数据其长度为nDataLen字节。
// nDataLen -- 数据长度以字节为单位必须为AES_KEY_LENGTH/8的整倍数。
// pIV -- 初始化向量如果使用ECB模式可设为NULL。
// 输出参数: pPlainText -- 明文即由密文解密后的数据可以与pCipherText相同。
// 返回值: 无。
******************************************************************************/
void AES_Decrypt(unsigned char* pPlainText, const unsigned char* pCipherText,
unsigned int nDataLen, const unsigned char* pIV);
/*****************************************************************************
// 函数名: AES_add_pkcs7Padding
// 描述: PKCS7Padding填充补齐
// 输入参数: input -- 后面最多预留16个字节空间用于存放填充值
// len -- 数据的长度
// 输出参数: input -- 添加填充码后的数据
// 返回值: 填充后的长度
*****************************************************************************/
unsigned int AES_add_pkcs7Padding(unsigned char* input, unsigned int len);
/*****************************************************************************
// 函数名: AES_delete_pkcs7Padding
// 描述: PKCS7Padding填充密文解密后剔除填充值
// 输入参数: input -- 解密后的数据
// len -- 数据的长度
// 输出参数: input -- 删除填充码后的数据
// 返回值: 删除后的实际有效数据长度为0表示传入的数据异常
*****************************************************************************/
unsigned int AES_delete_pkcs7Padding(unsigned char* input, unsigned int len);
#endif /* _AES_H */