OVMS3-idf/examples/06_bluedroid_demos/components/bluedroid_demos/include/wechat_aes.h

73 lines
2.8 KiB
C
Raw 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.

///////////////////////////////////////////////////////////////////////////////
// 文 件 名AES.h
// 描 述AES加密算法
// 创 建 人Liangbofu
// 创建日期2009-07-17
///////////////////////////////////////////////////////////////////////////////
#ifndef __WECHAT_AES_H
#define __WECHAT_AES_H
#include "prf_defs.h"
#if (WX_AIRSYNC_CFG)
#ifdef __cplusplus
extern "C" {
#endif
// 以bit为单位的密钥长度只能为 128192 和 256 三种
#define AES_KEY_LENGTH 128
// 加解密模式
#define AES_MODE_ECB 0 // 电子密码本模式(一般模式)
#define AES_MODE_CBC 1 // 密码分组链接模式
#define AES_MODE AES_MODE_CBC
///////////////////////////////////////////////////////////////////////////////
// 函数名: AES_Init
// 描述: 初始化,在此执行扩展密钥操作。
// 输入参数: pKey -- 原始密钥,其长度必须为 AES_KEY_LENGTH/8 字节。
// 输出参数: 无。
// 返回值: 无。
///////////////////////////////////////////////////////////////////////////////
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);
//对数据进行解密操作成功返回1失败返回0
unsigned char app_data_encode_aes(char *input, char *output, unsigned short *slen);
unsigned char app_data_decode_aes(unsigned char *input, char *output, unsigned short *slen);
unsigned int AES_Encrypt_PKCS7(const unsigned char *pPlainText, unsigned char *pCipherText,
unsigned int nDataLen, const unsigned char *pIV);
unsigned int AES_get_length(unsigned int length);
void AES_free(unsigned char* p);
#ifdef __cplusplus
}
#endif ///__cplusplus
#endif ///WX_AIRSYNC_CFG
#endif // __WECHAT_AES_H