欢迎来到天天文库
浏览记录
ID:14321575
大小:47.50 KB
页数:21页
时间:2018-07-27
《aes算法加密c语言完整程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、AES算法加密C语言完整程序#include#include"aes.h"#include"commonage.h"#definebyteunsignedchar#defineBPOLY0x1b//!2、#defineKEYLENGTH16//!3、ofs-box.bytexdata*sBoxInv;//!4、F(2^8).t^=(t<<1)^(t&0x80?BPOLY:0);}while(t!=1);//Cyclicpropertiesensurethati<255.powTbl[255]=powTbl[0];//255='-0',254=-1,etc.}voidCalcSBox(byte*sBox){bytexdatai,rot;bytexdatatemp;bytexdataresult;//FillallentriesofsBox[].i=0;do{//InverseinGF(2^8).if(i>0){temp=powTbl[255-5、logTbl[i]];}else{temp=0;}//AffinetransformationinGF(2).result=temp^0x63;//StartwithaddingavectorinGF(2).for(rot=0;rot<4;rot++){//Rotateleft.temp=(temp<<1)6、(temp>>7);//AddrotatedbyteinGF(2).result^=temp;}//Putresultintable.sBox[i]=result;}while(++i!=0);}voidCalcSBoxInv(b7、yte*sBox,byte*sBoxInv){bytexdatai=0;bytexdataj=0;//IteratethroughallelementsinsBoxInvusingi.do{//SearchthroughsBoxusingj.cleardog();do{//Checkifcurrentjistheinverseofcurrenti.if(sBox[j]==i){//Ifso,setsBoxIncandindicatesearchfinished.sBoxInv[i]=j;j=255;}}while(++j!=0);}w8、hile(++i!=0);}voidCycleLeft(byte*row){//Cycle4bytesinanarrayleftonce.bytexdatatemp=row[0];row[0]=row[1];row[1]=row[2];row[2]=row[3];row[3]=temp;}voidInvMixColumn(byte*column){bytexdatar0,r1,r2,r3;r0=column[1]^column[2]^column[3];r1=column[0]^column[2]^column[3];r2=colum9、n[0]^column[1]^column[3];r3=column[0]^column[1]^column[2];column[0]=(column[0]<<1)^(column[0]&0x80?BPOLY:0);co
2、#defineKEYLENGTH16//!3、ofs-box.bytexdata*sBoxInv;//!4、F(2^8).t^=(t<<1)^(t&0x80?BPOLY:0);}while(t!=1);//Cyclicpropertiesensurethati<255.powTbl[255]=powTbl[0];//255='-0',254=-1,etc.}voidCalcSBox(byte*sBox){bytexdatai,rot;bytexdatatemp;bytexdataresult;//FillallentriesofsBox[].i=0;do{//InverseinGF(2^8).if(i>0){temp=powTbl[255-5、logTbl[i]];}else{temp=0;}//AffinetransformationinGF(2).result=temp^0x63;//StartwithaddingavectorinGF(2).for(rot=0;rot<4;rot++){//Rotateleft.temp=(temp<<1)6、(temp>>7);//AddrotatedbyteinGF(2).result^=temp;}//Putresultintable.sBox[i]=result;}while(++i!=0);}voidCalcSBoxInv(b7、yte*sBox,byte*sBoxInv){bytexdatai=0;bytexdataj=0;//IteratethroughallelementsinsBoxInvusingi.do{//SearchthroughsBoxusingj.cleardog();do{//Checkifcurrentjistheinverseofcurrenti.if(sBox[j]==i){//Ifso,setsBoxIncandindicatesearchfinished.sBoxInv[i]=j;j=255;}}while(++j!=0);}w8、hile(++i!=0);}voidCycleLeft(byte*row){//Cycle4bytesinanarrayleftonce.bytexdatatemp=row[0];row[0]=row[1];row[1]=row[2];row[2]=row[3];row[3]=temp;}voidInvMixColumn(byte*column){bytexdatar0,r1,r2,r3;r0=column[1]^column[2]^column[3];r1=column[0]^column[2]^column[3];r2=colum9、n[0]^column[1]^column[3];r3=column[0]^column[1]^column[2];column[0]=(column[0]<<1)^(column[0]&0x80?BPOLY:0);co
3、ofs-box.bytexdata*sBoxInv;//!4、F(2^8).t^=(t<<1)^(t&0x80?BPOLY:0);}while(t!=1);//Cyclicpropertiesensurethati<255.powTbl[255]=powTbl[0];//255='-0',254=-1,etc.}voidCalcSBox(byte*sBox){bytexdatai,rot;bytexdatatemp;bytexdataresult;//FillallentriesofsBox[].i=0;do{//InverseinGF(2^8).if(i>0){temp=powTbl[255-5、logTbl[i]];}else{temp=0;}//AffinetransformationinGF(2).result=temp^0x63;//StartwithaddingavectorinGF(2).for(rot=0;rot<4;rot++){//Rotateleft.temp=(temp<<1)6、(temp>>7);//AddrotatedbyteinGF(2).result^=temp;}//Putresultintable.sBox[i]=result;}while(++i!=0);}voidCalcSBoxInv(b7、yte*sBox,byte*sBoxInv){bytexdatai=0;bytexdataj=0;//IteratethroughallelementsinsBoxInvusingi.do{//SearchthroughsBoxusingj.cleardog();do{//Checkifcurrentjistheinverseofcurrenti.if(sBox[j]==i){//Ifso,setsBoxIncandindicatesearchfinished.sBoxInv[i]=j;j=255;}}while(++j!=0);}w8、hile(++i!=0);}voidCycleLeft(byte*row){//Cycle4bytesinanarrayleftonce.bytexdatatemp=row[0];row[0]=row[1];row[1]=row[2];row[2]=row[3];row[3]=temp;}voidInvMixColumn(byte*column){bytexdatar0,r1,r2,r3;r0=column[1]^column[2]^column[3];r1=column[0]^column[2]^column[3];r2=colum9、n[0]^column[1]^column[3];r3=column[0]^column[1]^column[2];column[0]=(column[0]<<1)^(column[0]&0x80?BPOLY:0);co
4、F(2^8).t^=(t<<1)^(t&0x80?BPOLY:0);}while(t!=1);//Cyclicpropertiesensurethati<255.powTbl[255]=powTbl[0];//255='-0',254=-1,etc.}voidCalcSBox(byte*sBox){bytexdatai,rot;bytexdatatemp;bytexdataresult;//FillallentriesofsBox[].i=0;do{//InverseinGF(2^8).if(i>0){temp=powTbl[255-
5、logTbl[i]];}else{temp=0;}//AffinetransformationinGF(2).result=temp^0x63;//StartwithaddingavectorinGF(2).for(rot=0;rot<4;rot++){//Rotateleft.temp=(temp<<1)
6、(temp>>7);//AddrotatedbyteinGF(2).result^=temp;}//Putresultintable.sBox[i]=result;}while(++i!=0);}voidCalcSBoxInv(b
7、yte*sBox,byte*sBoxInv){bytexdatai=0;bytexdataj=0;//IteratethroughallelementsinsBoxInvusingi.do{//SearchthroughsBoxusingj.cleardog();do{//Checkifcurrentjistheinverseofcurrenti.if(sBox[j]==i){//Ifso,setsBoxIncandindicatesearchfinished.sBoxInv[i]=j;j=255;}}while(++j!=0);}w
8、hile(++i!=0);}voidCycleLeft(byte*row){//Cycle4bytesinanarrayleftonce.bytexdatatemp=row[0];row[0]=row[1];row[1]=row[2];row[2]=row[3];row[3]=temp;}voidInvMixColumn(byte*column){bytexdatar0,r1,r2,r3;r0=column[1]^column[2]^column[3];r1=column[0]^column[2]^column[3];r2=colum
9、n[0]^column[1]^column[3];r3=column[0]^column[1]^column[2];column[0]=(column[0]<<1)^(column[0]&0x80?BPOLY:0);co
此文档下载收益归作者所有