#pragma once #include #include #include #include #include "iAlgEnc_global.h" typedef unsigned long DWORD; typedef unsigned char UCHAR,*PUCHAR; typedef void *PVOID,*LPVOID; typedef unsigned char byte; typedef DWORD *PDWORD,*LPDWORD; // AES算法实现 class I_ALGENC_EXPORT zxAes { public: zxAes(int nKeySize, unsigned char* pKeyBytes); ~zxAes(); // 入口函数 void enc(unsigned char* input, unsigned char* output); void dec(unsigned char* input, unsigned char* output); private: void initParas(int nKeySize, unsigned char* pKeyBytes);//设置初始参数 void addRoundKey(int round); //轮密钥加 void replaceSubBytes(); //S盒字节代换 void replaceInvSubBytes(); //逆S盒字节代换 void shiftRows(); //行移位 void shiftInvRows(); void mixColumns(); //列混淆 void mixInvColumns(); // 内部转换函数 unsigned char _runMultiBy01(unsigned char b); unsigned char _runMultiBy02(unsigned char b); unsigned char _runMultiBy03(unsigned char b); unsigned char _runMultiBy09(unsigned char b); unsigned char _runMultiBy0b(unsigned char b); unsigned char _runMultiBy0d(unsigned char b); unsigned char _runMultiBy0e(unsigned char b); void enpandKey(); //密钥扩展 unsigned char* replaceSubWord(unsigned char* word); //密钥代换 unsigned char* shiftWord(unsigned char* word); //密钥移位 private: unsigned char m_arrStates[4][4];//状态缓存 int m_nSizeBlock; //块大小(32-bits) int m_nSizeKey; //秘钥大小 int m_nSizeRound; //轮大小 // 内部局部变量 unsigned char* m_pArrKeys; unsigned char* m_pArrChars; unsigned char* m_pArrSBox; unsigned char* m_pArrISBox; unsigned char* m_pArrRcon; };