下载此文档

aes算法加密c语言完整程序.doc


文档分类:IT计算机 | 页数:约21页 举报非法文档有奖
1/21
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/21 下载此文档
文档列表 文档介绍
AES 算法加密 C 语言完整程序#include <> #include "" #include "" #define byte unsigned char #define BPOLY 0x1b //!< Lower 8 bits of (x^8+x^4+x^3+x+1), ie. (x^4+x^3+x+1). #define BLOCKSIZE 16 //!< Block size in number of bytes. #define KEYBITS 128 //!< Use AES128. #define ROUNDS 10 //!< Number of rounds. #define KEYLENGTH 16 //!< Key length in number of bytes. byte xdata block1[ 256 ]; //!< Workspace 1. byte xdata block2[ 256 ]; //!< Worksapce 2. byte xdata * powTbl; //!< Final location of exponentiation lookup table. byte xdata * logTbl; //!< Final location of logarithm lookup table. byte xdata * sBox; //!< Final location of s-box. byte xdata * sBoxInv; //!< Final location of inverse s-box. byte xdata * expandedKey; //!< Final location of expanded key. void CalcPowLog( byte * powTbl, byte * logTbl ) { byte xdata i= 0; byte xdata t= 1; do{ // Use 0x03 as root for exponentiation and logarithms. powTbl[i] = t; logTbl[t] = i; i++; // Muliply t by3 in GF(2^8). t ^= (t << 1)^ (t& 0x80 ? BPOLY : 0); } while( t !=1 ); // Cyclic properties ensure that i < 255. powTbl[255] = powTbl[0]; // 255 = '-0', 254 = -1, etc. } void CalcSBox( byte * sBox ) { byte xdata i, rot; byte xdata temp; byte xdata result; // Fill all entries of sBox[]. i= 0; do{ // Inverse in GF(2^8). if( i>0){ temp = powTbl[ 255 - logTbl[i] ]; } else { temp = 0; } // Affine transformation in GF(2). result = temp ^ 0x63; // Start with adding a vector in GF(2). for( rot = 0; rot < 4; rot++ ){ // Rotate left. temp = (temp<<1) | (temp>>7); // Add rotated byte in GF(2). result ^= temp; } // Put result in table. sBox[i] = result; } while( ++i !=0 ); } void CalcSBoxInv( byte * sBox, byte * sBoxInv ) { byte xdata i= 0; byte xdata j= 0; // Iterate through all elements in sBoxInv using i. do{ // Search through sBox using j. cleardog(); do{ // Check if current j is the inverse of current i. if( sBox[ j] ==i){ // If so, set sBoxInc and indicate search finished. sBoxInv[ i]= j; j= 255; }} while( ++j !=0 ); } whil

aes算法加密c语言完整程序 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数21
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xxj16588
  • 文件大小0 KB
  • 时间2016-03-23
最近更新