基于Modelsim的verilog语言设计AES加密解密(硬件电路HDL)

news/2024/11/26 4:53:59/

 

全程手撕AES加密(verilog)

以下部分截图若涉及侵权,及时联系,随时撤销!

关于AES的原理我不多叙述,博客众多大佬比我厉害的多,该篇文章仅用来纪念自己的学习过程以及分享代码参考,毕竟有关这个AES的verilog代码基本都要付费下载,在我这不需要哈哈。

学习历程

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWFhYQUxFWEFO,size_20,color_FFFFFF,t_70,g_se,x_16watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWFhYQUxFWEFO,size_20,color_FFFFFF,t_70,g_se,x_16

 

 

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWFhYQUxFWEFO,size_20,color_FFFFFF,t_70,g_se,x_16

 设计中遇到的问题

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWFhYQUxFWEFO,size_20,color_FFFFFF,t_70,g_se,x_16

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWFhYQUxFWEFO,size_20,color_FFFFFF,t_70,g_se,x_16

 列混合中涉及到的不是普通的矩阵相乘,而是满足以下公式:

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWFhYQUxFWEFO,size_20,color_FFFFFF,t_70,g_se,x_16

密钥扩展要注意或非数:980228c90c8a457cbd60058df057afb9.png 

AES代码大致流程

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWFhYQUxFWEFO,size_20,color_FFFFFF,t_70,g_se,x_16

现在到了大家最想要的部分代码!!! 

程序代码:

module AES(//cyxmingwen00,mingwen01,mingwen02,mingwen03,mingwen10,mingwen11,mingwen12,mingwen13,mingwen20,mingwen21,mingwen22,mingwen23,mingwen30,mingwen31,mingwen32,mingwen33,clk,rst_n,miyao00,miyao01,miyao02,miyao03,miyao10,miyao11,miyao12,miyao13,miyao20,miyao21,miyao22,miyao23,miyao30,miyao31,miyao32,miyao33,key,miwen00,miwen01,miwen02,miwen03,miwen10,miwen11,miwen12,miwen13,miwen20,miwen21,miwen22,miwen23,miwen30,miwen31,miwen32,miwen33);
input [7:0] mingwen00,mingwen01,mingwen02,mingwen03;
input [7:0] mingwen10,mingwen11,mingwen12,mingwen13;
input [7:0] mingwen20,mingwen21,mingwen22,mingwen23;
input [7:0] mingwen30,mingwen31,mingwen32,mingwen33;
input clk;
input rst_n;
input [7:0] miyao00,miyao01,miyao02,miyao03;
input [7:0] miyao10,miyao11,miyao12,miyao13;
input [7:0] miyao20,miyao21,miyao22,miyao23;
input [7:0] miyao30,miyao31,miyao32,miyao33;
input key;
output reg [7:0] miwen00,miwen01,miwen02,miwen03;
output reg [7:0] miwen10,miwen11,miwen12,miwen13;
output reg [7:0] miwen20,miwen21,miwen22,miwen23;
output reg [7:0] miwen30,miwen31,miwen32,miwen33;
reg [7:0] miyaox00,miyaox01,miyaox02,miyaox03;
reg [7:0] miyaox10,miyaox11,miyaox12,miyaox13;
reg [7:0] miyaox20,miyaox21,miyaox22,miyaox23;
reg [7:0] miyaox30,miyaox31,miyaox32,miyaox33;
reg [7:0] x00, x01, x02, x03;
reg [7:0] x10, x11, x12, x13;
reg [7:0] x20, x21, x22, x23;
reg [7:0] x30, x31, x32, x33;
reg [7:0] cyx;
reg [127:0] x;
reg [127:0] s_2;
reg [7:0] i;
reg [7:0] i_2;
reg [7:0] j;
reg [7:0] c;
reg [7:0] d;
reg [7:0] k;
reg [7:0] p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16;
reg [7:0] s00,s01,s02,s03,s10,s11,s12,s13,s20,s21,s22,s23,s30,s31,s32,s33;
reg [7:0] s00_2,s01_2,s02_2,s03_2,s10_2,s11_2,s12_2,s13_2,s20_2,s21_2,s22_2,s23_2,s30_2,s31_2,s32_2,s33_2;
reg [7:0] s00_3,s01_3,s02_3,s03_3,s10_3,s11_3,s12_3,s13_3,s20_3,s21_3,s22_3,s23_3,s30_3,s31_3,s32_3,s33_3;
reg [7:0] m00, m01, m02, m03;//cyx
reg [7:0] m10, m11, m12, m13;//cyx
reg [7:0] m20, m21, m22, m23;//cyx
reg [7:0] m30, m31, m32, m33;//cyx
reg [7:0] mm0, mm1, mm2, mm3;//cyx
reg [31:0] mm;
reg [7:0] jj;
reg [7:0] rcon;
always@(posedge clk or negedge rst_n)
beginif(!rst_n)begini<=0;i_2<=0;miwen00<=0; miwen01<=0; miwen02<=0; miwen03<=0;miwen10<=0; miwen11<=0; miwen12<=0; miwen13<=0;miwen20<=0; miwen21<=0; miwen22<=0; miwen23<=0;miwen30<=0; miwen31<=0; miwen32<=0; miwen33<=0;miyaox00<=0;miyaox01<=0;miyaox02<=0;miyaox03<=0;miyaox10<=0;miyaox11<=0;miyaox12<=0;miyaox13<=0;miyaox20<=0;miyaox21<=0;miyaox22<=0;miyaox23<=0;miyaox30<=0;miyaox31<=0;miyaox32<=0;miyaox33<=0;x00<=0; x01<=0; x02<=0; x03<=0;x10<=0; x11<=0; x12<=0; x13<=0;x20<=0; x21<=0; x22<=0; x23<=0;x30<=0; x31<=0; x32<=0; x33<=0;p1<=0;  p2<=0;  p3<=0;  p4<=0;p5<=0;  p6<=0;  p7<=0;  p8<=0;p9<=0;  p10<=0; p11<=0; p12<=0;p13<=0; p14<=0; p15<=0; p16<=0;s00<=0; s01<=0; s02<=0; s03<=0;s10<=0; s11<=0; s12<=0; s13<=0;s20<=0; s21<=0; s22<=0; s23<=0;s30<=0; s31<=0; s32<=0; s33<=0;s00_2<=0; s01_2<=0; s02_2<=0; s03_2<=0;s10_2<=0; s11_2<=0; s12_2<=0; s13_2<=0;s20_2<=0; s21_2<=0; s22_2<=0; s23_2<=0;s30_2<=0; s31_2<=0; s32_2<=0; s33_2<=0;s00_3<=0; s01_3<=0; s02_3<=0; s03_3<=0;s10_3<=0; s11_3<=0; s12_3<=0; s13_3<=0;s20_3<=0; s21_3<=0; s22_3<=0; s23_3<=0;s30_3<=0; s31_3<=0; s32_3<=0; s33_3<=0;m00<=0; m01<=0; m02<=0; m03<=0;m10<=0; m11<=0; m12<=0; m13<=0;m20<=0; m21<=0; m22<=0; m23<=0;m30<=0; m31<=0; m32<=0; m33<=0;mm0<=0; mm1<=0; mm2<=0; mm3<=0;mm<=0;jj<=0;rcon<=0;c<=0;d<=0;k<=0;x<=0;s_2<=0;endelsebeginif(key==1)begincase(i)0://chu shi bian huan(initial round)beginx00<=mingwen00^miyao00; x01<=mingwen01^miyao01; x02<=mingwen02^miyao02; x03<=mingwen03^miyao03;x10<=mingwen10^miyao10; x11<=mingwen11^miyao11; x12<=mingwen12^miyao12; x13<=mingwen13^miyao13;x20<=mingwen20^miyao20; x21<=mingwen21^miyao21; x22<=mingwen22^miyao22; x23<=mingwen23^miyao23;x30<=mingwen30^miyao30; x31<=mingwen31^miyao31; x32<=mingwen32^miyao32; x33<=mingwen33^miyao33;miyaox00<=miyao00;miyaox01<=miyao01;miyaox02<=miyao02;miyaox03<=miyao03;miyaox10<=miyao10;miyaox11<=miyao11;miyaox12<=miyao12;miyaox13<=miyao13;miyaox20<=miyao20;miyaox21<=miyao21;miyaox22<=miyao22;miyaox23<=miyao23;miyaox30<=miyao30;miyaox31<=miyao31;miyaox32<=miyao32;miyaox33<=miyao33;i<=1;end1://zi jie bian hua(subbytes)beginx = {x00, x01, x02, x03,x10, x11, x12, x13,x20, x21, x22, x23,x30, x31, x32, x33};j=0;i=2;end2:  beginwhile(j<16)beginc = x[8*j+7-:8];case(c)8'h00: d=8'h63; 8'h01: d=8'h7c; 8'h02: d=8'h77; 8'h03: d=8'h7b; 8'h04: d=8'hf2; 8'h05: d=8'h6b; 8'h06: d=8'h6f; 8'h07: d=8'hc5; 8'h08: d=8'h30; 8'h09: d=8'h01; 8'h0a: d=8'h67; 8'h0b: d=8'h2b; 8'h0c: d=8'hfe; 8'h0d: d=8'hd7; 8'h0e: d=8'hab; 8'h0f: d=8'h76;8'h10: d=8'hca; 8'h11: d=8'h82; 8'h12: d=8'hc9; 8'h13: d=8'h7d; 8'h14: d=8'hfa; 8'h15: d=8'h59; 8'h16: d=8'h47; 8'h17: d=8'hf0; 8'h18: d=8'had; 8'h19: d=8'hd4; 8'h1a: d=8'ha2; 8'h1b: d=8'haf; 8'h1c: d=8'h9c; 8'h1d: d=8'ha4; 8'h1e: d=8'h72; 8'h1f: d=8'hc0;8'h20: d=8'hb7; 8'h21: d=8'hfd; 8'h22: d=8'h93; 8'h23: d=8'h26; 8'h24: d=8'h36; 8'h25: d=8'h3f; 8'h26: d=8'hf7; 8'h27: d=8'hcc; 8'h28: d=8'h34; 8'h29: d=8'ha5; 8'h2a: d=8'he5; 8'h2b: d=8'hf1; 8'h2c: d=8'h71; 8'h2d: d=8'hd8; 8'h2e: d=8'h31; 8'h2f: d=8'h15;8'h30: d=8'h04; 8'h31: d=8'hc7; 8'h32: d=8'h23; 8'h33: d=8'hc3; 8'h34: d=8'h18; 8'h35: d=8'h96; 8'h36: d=8'h05; 8'h37: d=8'h9a; 8'h38: d=8'h07; 8'h39: d=8'h12; 8'h3a: d=8'h80; 8'h3b: d=8'he2; 8'h3c: d=8'heb; 8'h3d: d=8'h27; 8'h3e: d=8'hb2; 8'h3f: d=8'h75;8'h40: d=8'h09; 8'h41: d=8'h83; 8'h42: d=8'h2c; 8'h43: d=8'h1a; 8'h44: d=8'h1b; 8'h45: d=8'h6e; 8'h46: d=8'h5a; 8'h47: d=8'ha0; 8'h48: d=8'h52; 8'h49: d=8'h3b; 8'h4a: d=8'hd6; 8'h4b: d=8'hb3; 8'h4c: d=8'h29; 8'h4d: d=8'he3; 8'h4e: d=8'h2f; 8'h4f: d=8'h84;8'h50: d=8'h53; 8'h51: d=8'hd1; 8'h52: d=8'h00; 8'h53: d=8'hed; 8'h54: d=8'h20; 8'h55: d=8'hfc; 8'h56: d=8'hb1; 8'h57: d=8'h5b; 8'h58: d=8'h6a; 8'h59: d=8'hcb; 8'h5a: d=8'hbe; 8'h5b: d=8'h39; 8'h5c: d=8'h4a; 8'h5d: d=8'h4c; 8'h5e: d=8'h58; 8'h5f: d=8'hcf;8'h60: d=8'hd0; 8'h61: d=8'hef; 8'h62: d=8'haa; 8'h63: d=8'hfb; 8'h64: d=8'h43; 8'h65: d=8'h4d; 8'h66: d=8'h33; 8'h67: d=8'h85; 8'h68: d=8'h45; 8'h69: d=8'hf9; 8'h6a: d=8'h02; 8'h6b: d=8'h7f; 8'h6c: d=8'h50; 8'h6d: d=8'h3c; 8'h6e: d=8'h9f; 8'h6f: d=8'ha8;8'h70: d=8'h51; 8'h71: d=8'ha3; 8'h72: d=8'h40; 8'h73: d=8'h8f; 8'h74: d=8'h92; 8'h75: d=8'h9d; 8'h76: d=8'h38; 8'h77: d=8'hf5; 8'h78: d=8'hbc; 8'h79: d=8'hb6; 8'h7a: d=8'hda; 8'h7b: d=8'h21; 8'h7c: d=8'h10; 8'h7d: d=8'hff; 8'h7e: d=8'hf3; 8'h7f: d=8'hd2;8'h80: d=8'hcd; 8'h81: d=8'h0c; 8'h82: d=8'h13; 8'h83: d=8'hec; 8'h84: d=8'h5f; 8'h85: d=8'h97; 8'h86: d=8'h44; 8'h87: d=8'h17; 8'h88: d=8'hc4; 8'h89: d=8'ha7; 8'h8a: d=8'h7e; 8'h8b: d=8'h3d; 8'h8c: d=8'h64; 8'h8d: d=8'h5d; 8'h8e: d=8'h19; 8'h8f: d=8'h73;8'h90: d=8'h60; 8'h91: d=8'h81; 8'h92: d=8'h4f; 8'h93: d=8'hdc; 8'h94: d=8'h22; 8'h95: d=8'h2a; 8'h96: d=8'h90; 8'h97: d=8'h88; 8'h98: d=8'h46; 8'h99: d=8'hee; 8'h9a: d=8'hb8; 8'h9b: d=8'h14; 8'h9c: d=8'hde; 8'h9d: d=8'h5e; 8'h9e: d=8'h0b; 8'h9f: d=8'hdb;8'ha0: d=8'he0; 8'ha1: d=8'h32; 8'ha2: d=8'h3a; 8'ha3: d=8'h0a; 8'ha4: d=8'h49; 8'ha5: d=8'h06; 8'ha6: d=8'h24; 8'ha7: d=8'h5c; 8'ha8: d=8'hc2; 8'ha9: d=8'hd3; 8'haa: d=8'hac; 8'hab: d=8'h62; 8'hac: d=8'h91; 8'had: d=8'h95; 8'hae: d=8'he4; 8'haf: d=8'h79;8'hb0: d=8'he7; 8'hb1: d=8'hc8; 8'hb2: d=8'h37; 8'hb3: d=8'h6d; 8'hb4: d=8'h8d; 8'hb5: d=8'hd5; 8'hb6: d=8'h4e; 8'hb7: d=8'ha9; 8'hb8: d=8'h6c; 8'hb9: d=8'h56; 8'hba: d=8'hf4; 8'hbb: d=8'hea; 8'hbc: d=8'h65; 8'hbd: d=8'h7a; 8'hbe: d=8'hae; 8'hbf: d=8'h08;8'hc0: d=8'hba; 8'hc1: d=8'h78; 8'hc2: d=8'h25; 8'hc3: d=8'h2e; 8'hc4: d=8'h1c; 8'hc5: d=8'ha6; 8'hc6: d=8'hb4; 8'hc7: d=8'hc6; 8'hc8: d=8'he8; 8'hc9: d=8'hdd; 8'hca: d=8'h74; 8'hcb: d=8'h1f; 8'hcc: d=8'h4b; 8'hcd: d=8'hbd; 8'hce: d=8'h8b; 8'hcf: d=8'h8a;8'hd0: d=8'h70; 8'hd1: d=8'h3e; 8'hd2: d=8'hb5; 8'hd3: d=8'h66; 8'hd4: d=8'h48; 8'hd5: d=8'h03; 8'hd6: d=8'hf6; 8'hd7: d=8'h0e; 8'hd8: d=8'h61; 8'hd9: d=8'h35; 8'hda: d=8'h57; 8'hdb: d=8'hb9; 8'hdc: d=8'h86; 8'hdd: d=8'hc1; 8'hde: d=8'h1d; 8'hdf: d=8'h9e;8'he0: d=8'he1; 8'he1: d=8'hf8; 8'he2: d=8'h98; 8'he3: d=8'h11; 8'he4: d=8'h69; 8'he5: d=8'hd9; 8'he6: d=8'h8e; 8'he7: d=8'h94; 8'he8: d=8'h9b; 8'he9: d=8'h1e; 8'hea: d=8'h87; 8'heb: d=8'he9; 8'hec: d=8'hce; 8'hed: d=8'h55; 8'hee: d=8'h28; 8'hef: d=8'hdf;8'hf0: d=8'h8c; 8'hf1: d=8'ha1; 8'hf2: d=8'h89; 8'hf3: d=8'h0d; 8'hf4: d=8'hbf; 8'hf5: d=8'he6; 8'hf6: d=8'h42; 8'hf7: d=8'h68; 8'hf8: d=8'h41; 8'hf9: d=8'h99; 8'hfa: d=8'h2d; 8'hfb: d=8'h0f; 8'hfc: d=8'hb0; 8'hfd: d=8'h54; 8'hfe: d=8'hbb; 8'hff: d=8'h16;endcasex[8*j+7-:8] = d;j=j+1;endx00=x[127:120]; x01=x[119:112]; x02=x[111:104]; x03=x[103:96];x10=x[95:88];   x11=x[87:80];   x12=x[79:72];   x13=x[71:64];x20=x[63:56];   x21=x[55:48];   x22=x[47:40];   x23=x[39:32];x30=x[31:24];   x31=x[23:16];   x32=x[15:8];    x33=x[7:0];i=3;end3://hang yi wei(shiftrows)begin//savep1<=x00; p5<=x01; p9<=x02;  p13<=x03;p2<=x10; p6<=x11; p10<=x12; p14<=x13;p3<=x20; p7<=x21; p11<=x22; p15<=x23;p4<=x30; p8<=x31; p12<=x32; p16<=x33;i<=4;end4://hang yi wei(shiftrows)beginx00=p1;  x01=p5;  x02=p9;  x03=p13;//1 no changex10=p6;  x11=p10; x12=p14; x13=p2;//2<<1x20=p11; x21=p15; x22=p3;  x23=p7;//3<<2x30=p16; x31=p4;  x32=p8;  x33=p12;//4<<3k=k+1;if(k<10)begini=5;endelsebegini=8;endend5://lie hun he(mixcolumns)begin//saves00<=x00;s01<=x01;s02<=x02;s03<=x03;s10<=x10;s11<=x11;s12<=x12;s13<=x13;s20<=x20;s21<=x21;s22<=x22;s23<=x23;s30<=x30;s31<=x31;s32<=x32;s33<=x33;s_2<={x00,x01,x02,x03,x10,x11,x12,x13,x20,x21,x22,x23,x30,x31,x32,x33};i<=6;i_2<=0;end6:beginwhile(i_2<16)beginif((s_2[8*i_2+7])==0)begins_2[8*i_2+7-:8]={s_2[8*i_2+6-:7],1'b0};endelsebegins_2[8*i_2+7-:8]=({s_2[8*i_2+6-:7],1'b0})^(8'b0001_1011);endi_2=i_2+1;ends00_2=s_2[127:120]; s01_2=s_2[119:112]; s02_2=s_2[111:104]; s03_2=s_2[103:96];s10_2=s_2[95:88];   s11_2=s_2[87:80];   s12_2=s_2[79:72];   s13_2=s_2[71:64];s20_2=s_2[63:56];   s21_2=s_2[55:48];   s22_2=s_2[47:40];   s23_2=s_2[39:32];s30_2=s_2[31:24];   s31_2=s_2[23:16];   s32_2=s_2[15:8];    s33_2=s_2[7:0];s00_3=s00_2^s00;    s01_3=s01_2^s01;    s02_3=s02_2^s02;    s03_3=s03_2^s03;s10_3=s10_2^s10;    s11_3=s11_2^s11;    s12_3=s12_2^s12;    s13_3=s13_2^s13;s20_3=s20_2^s20;    s21_3=s21_2^s21;    s22_3=s22_2^s22;    s23_3=s23_2^s23;s30_3=s30_2^s30;    s31_3=s31_2^s31;    s32_3=s32_2^s32;    s33_3=s33_2^s33;i=7;end7://lie hun he(mixcolumns)begin//calx00<=(s00_2)^(s10_3)^(s20)^(s30);x01<=(s01_2)^(s11_3)^(s21)^(s31);x02<=(s02_2)^(s12_3)^(s22)^(s32);x03<=(s03_2)^(s13_3)^(s23)^(s33);//row 0x10<=(s00)^(s10_2)^(s20_3)^(s30);x11<=(s01)^(s11_2)^(s21_3)^(s31);x12<=(s02)^(s12_2)^(s22_3)^(s32);x13<=(s03)^(s13_2)^(s23_3)^(s33);//row 1x20<=(s00)^(s10)^(s20_2)^(s30_3);x21<=(s01)^(s11)^(s21_2)^(s31_3);x22<=(s02)^(s12)^(s22_2)^(s32_3);x23<=(s03)^(s13)^(s23_2)^(s33_3);//row 2x30<=(s00_3)^(s10)^(s20)^(s30_2);x31<=(s01_3)^(s11)^(s21)^(s31_2);x32<=(s02_3)^(s12)^(s22)^(s32_2);x33<=(s03_3)^(s13)^(s23)^(s33_2);//row 3i<=8;end8://mi yao kuo zhanbegin//savem00<=miyaox00; m01<=miyaox01; m02<=miyaox02; m03<=miyaox03;m10<=miyaox10; m11<=miyaox11; m12<=miyaox12; m13<=miyaox13;m20<=miyaox20; m21<=miyaox21; m22<=miyaox22; m23<=miyaox23;m30<=miyaox30; m31<=miyaox31; m32<=miyaox32; m33<=miyaox33;i<=9;jj<=0;end9://mi yao kuo zhanbeginmm0=m13;mm1=m23;mm2=m33;mm3=m03;mm={mm0,mm1,mm2,mm3};while(jj<4)beginc = mm[8*jj+7-:8];case(c)8'h00: d=8'h63; 8'h01: d=8'h7c; 8'h02: d=8'h77; 8'h03: d=8'h7b; 8'h04: d=8'hf2; 8'h05: d=8'h6b; 8'h06: d=8'h6f; 8'h07: d=8'hc5; 8'h08: d=8'h30; 8'h09: d=8'h01; 8'h0a: d=8'h67; 8'h0b: d=8'h2b; 8'h0c: d=8'hfe; 8'h0d: d=8'hd7; 8'h0e: d=8'hab; 8'h0f: d=8'h76;8'h10: d=8'hca; 8'h11: d=8'h82; 8'h12: d=8'hc9; 8'h13: d=8'h7d; 8'h14: d=8'hfa; 8'h15: d=8'h59; 8'h16: d=8'h47; 8'h17: d=8'hf0; 8'h18: d=8'had; 8'h19: d=8'hd4; 8'h1a: d=8'ha2; 8'h1b: d=8'haf; 8'h1c: d=8'h9c; 8'h1d: d=8'ha4; 8'h1e: d=8'h72; 8'h1f: d=8'hc0;8'h20: d=8'hb7; 8'h21: d=8'hfd; 8'h22: d=8'h93; 8'h23: d=8'h26; 8'h24: d=8'h36; 8'h25: d=8'h3f; 8'h26: d=8'hf7; 8'h27: d=8'hcc; 8'h28: d=8'h34; 8'h29: d=8'ha5; 8'h2a: d=8'he5; 8'h2b: d=8'hf1; 8'h2c: d=8'h71; 8'h2d: d=8'hd8; 8'h2e: d=8'h31; 8'h2f: d=8'h15;8'h30: d=8'h04; 8'h31: d=8'hc7; 8'h32: d=8'h23; 8'h33: d=8'hc3; 8'h34: d=8'h18; 8'h35: d=8'h96; 8'h36: d=8'h05; 8'h37: d=8'h9a; 8'h38: d=8'h07; 8'h39: d=8'h12; 8'h3a: d=8'h80; 8'h3b: d=8'he2; 8'h3c: d=8'heb; 8'h3d: d=8'h27; 8'h3e: d=8'hb2; 8'h3f: d=8'h75;8'h40: d=8'h09; 8'h41: d=8'h83; 8'h42: d=8'h2c; 8'h43: d=8'h1a; 8'h44: d=8'h1b; 8'h45: d=8'h6e; 8'h46: d=8'h5a; 8'h47: d=8'ha0; 8'h48: d=8'h52; 8'h49: d=8'h3b; 8'h4a: d=8'hd6; 8'h4b: d=8'hb3; 8'h4c: d=8'h29; 8'h4d: d=8'he3; 8'h4e: d=8'h2f; 8'h4f: d=8'h84;8'h50: d=8'h53; 8'h51: d=8'hd1; 8'h52: d=8'h00; 8'h53: d=8'hed; 8'h54: d=8'h20; 8'h55: d=8'hfc; 8'h56: d=8'hb1; 8'h57: d=8'h5b; 8'h58: d=8'h6a; 8'h59: d=8'hcb; 8'h5a: d=8'hbe; 8'h5b: d=8'h39; 8'h5c: d=8'h4a; 8'h5d: d=8'h4c; 8'h5e: d=8'h58; 8'h5f: d=8'hcf;8'h60: d=8'hd0; 8'h61: d=8'hef; 8'h62: d=8'haa; 8'h63: d=8'hfb; 8'h64: d=8'h43; 8'h65: d=8'h4d; 8'h66: d=8'h33; 8'h67: d=8'h85; 8'h68: d=8'h45; 8'h69: d=8'hf9; 8'h6a: d=8'h02; 8'h6b: d=8'h7f; 8'h6c: d=8'h50; 8'h6d: d=8'h3c; 8'h6e: d=8'h9f; 8'h6f: d=8'ha8;8'h70: d=8'h51; 8'h71: d=8'ha3; 8'h72: d=8'h40; 8'h73: d=8'h8f; 8'h74: d=8'h92; 8'h75: d=8'h9d; 8'h76: d=8'h38; 8'h77: d=8'hf5; 8'h78: d=8'hbc; 8'h79: d=8'hb6; 8'h7a: d=8'hda; 8'h7b: d=8'h21; 8'h7c: d=8'h10; 8'h7d: d=8'hff; 8'h7e: d=8'hf3; 8'h7f: d=8'hd2;8'h80: d=8'hcd; 8'h81: d=8'h0c; 8'h82: d=8'h13; 8'h83: d=8'hec; 8'h84: d=8'h5f; 8'h85: d=8'h97; 8'h86: d=8'h44; 8'h87: d=8'h17; 8'h88: d=8'hc4; 8'h89: d=8'ha7; 8'h8a: d=8'h7e; 8'h8b: d=8'h3d; 8'h8c: d=8'h64; 8'h8d: d=8'h5d; 8'h8e: d=8'h19; 8'h8f: d=8'h73;8'h90: d=8'h60; 8'h91: d=8'h81; 8'h92: d=8'h4f; 8'h93: d=8'hdc; 8'h94: d=8'h22; 8'h95: d=8'h2a; 8'h96: d=8'h90; 8'h97: d=8'h88; 8'h98: d=8'h46; 8'h99: d=8'hee; 8'h9a: d=8'hb8; 8'h9b: d=8'h14; 8'h9c: d=8'hde; 8'h9d: d=8'h5e; 8'h9e: d=8'h0b; 8'h9f: d=8'hdb;8'ha0: d=8'he0; 8'ha1: d=8'h32; 8'ha2: d=8'h3a; 8'ha3: d=8'h0a; 8'ha4: d=8'h49; 8'ha5: d=8'h06; 8'ha6: d=8'h24; 8'ha7: d=8'h5c; 8'ha8: d=8'hc2; 8'ha9: d=8'hd3; 8'haa: d=8'hac; 8'hab: d=8'h62; 8'hac: d=8'h91; 8'had: d=8'h95; 8'hae: d=8'he4; 8'haf: d=8'h79;8'hb0: d=8'he7; 8'hb1: d=8'hc8; 8'hb2: d=8'h37; 8'hb3: d=8'h6d; 8'hb4: d=8'h8d; 8'hb5: d=8'hd5; 8'hb6: d=8'h4e; 8'hb7: d=8'ha9; 8'hb8: d=8'h6c; 8'hb9: d=8'h56; 8'hba: d=8'hf4; 8'hbb: d=8'hea; 8'hbc: d=8'h65; 8'hbd: d=8'h7a; 8'hbe: d=8'hae; 8'hbf: d=8'h08;8'hc0: d=8'hba; 8'hc1: d=8'h78; 8'hc2: d=8'h25; 8'hc3: d=8'h2e; 8'hc4: d=8'h1c; 8'hc5: d=8'ha6; 8'hc6: d=8'hb4; 8'hc7: d=8'hc6; 8'hc8: d=8'he8; 8'hc9: d=8'hdd; 8'hca: d=8'h74; 8'hcb: d=8'h1f; 8'hcc: d=8'h4b; 8'hcd: d=8'hbd; 8'hce: d=8'h8b; 8'hcf: d=8'h8a;8'hd0: d=8'h70; 8'hd1: d=8'h3e; 8'hd2: d=8'hb5; 8'hd3: d=8'h66; 8'hd4: d=8'h48; 8'hd5: d=8'h03; 8'hd6: d=8'hf6; 8'hd7: d=8'h0e; 8'hd8: d=8'h61; 8'hd9: d=8'h35; 8'hda: d=8'h57; 8'hdb: d=8'hb9; 8'hdc: d=8'h86; 8'hdd: d=8'hc1; 8'hde: d=8'h1d; 8'hdf: d=8'h9e;8'he0: d=8'he1; 8'he1: d=8'hf8; 8'he2: d=8'h98; 8'he3: d=8'h11; 8'he4: d=8'h69; 8'he5: d=8'hd9; 8'he6: d=8'h8e; 8'he7: d=8'h94; 8'he8: d=8'h9b; 8'he9: d=8'h1e; 8'hea: d=8'h87; 8'heb: d=8'he9; 8'hec: d=8'hce; 8'hed: d=8'h55; 8'hee: d=8'h28; 8'hef: d=8'hdf;8'hf0: d=8'h8c; 8'hf1: d=8'ha1; 8'hf2: d=8'h89; 8'hf3: d=8'h0d; 8'hf4: d=8'hbf; 8'hf5: d=8'he6; 8'hf6: d=8'h42; 8'hf7: d=8'h68; 8'hf8: d=8'h41; 8'hf9: d=8'h99; 8'hfa: d=8'h2d; 8'hfb: d=8'h0f; 8'hfc: d=8'hb0; 8'hfd: d=8'h54; 8'hfe: d=8'hbb; 8'hff: d=8'h16;endcasemm[8*jj+7-:8] = d;jj = jj+1;endcase(k)8'h01: rcon=8'h01;8'h02: rcon=8'h02;8'h03: rcon=8'h04;8'h04: rcon=8'h08;8'h05: rcon=8'h10;8'h06: rcon=8'h20;8'h07: rcon=8'h40;8'h08: rcon=8'h80;8'h09: rcon=8'h1b;8'h0a: rcon=8'h36;endcasemm0=mm[31:24];mm1=mm[23:16];mm2=mm[15:8];mm3=mm[7:0];miyaox00=(m00)^(mm0)^(rcon);miyaox10=(m10)^(mm1);miyaox20=(m20)^(mm2);miyaox30=(m30)^(mm3);miyaox01=(m01)^(miyaox00);miyaox11=(m11)^(miyaox10);miyaox21=(m21)^(miyaox20);miyaox31=(m31)^(miyaox30);miyaox02=(m02)^(miyaox01);miyaox12=(m12)^(miyaox11);miyaox22=(m22)^(miyaox21);miyaox32=(m32)^(miyaox31);miyaox03=(m03)^(miyaox02);miyaox13=(m13)^(miyaox12);miyaox23=(m23)^(miyaox22);miyaox33=(m33)^(miyaox32);i=10;end10://lun mi xiang jia(addroundkey)begin//saves00<=x00;s01<=x01;s02<=x02;s03<=x03;s10<=x10;s11<=x11;s12<=x12;s13<=x13;s20<=x20;s21<=x21;s22<=x22;s23<=x23;s30<=x30;s31<=x31;s32<=x32;s33<=x33;i<=11;end11://lun mi xiang jia(addroundkey)beginx00=(s00)^(miyaox00); x01=(s01)^(miyaox01); x02=(s02)^(miyaox02); x03=(s03)^(miyaox03);x10=(s10)^(miyaox10); x11=(s11)^(miyaox11); x12=(s12)^(miyaox12); x13=(s13)^(miyaox13);x20=(s20)^(miyaox20); x21=(s21)^(miyaox21); x22=(s22)^(miyaox22); x23=(s23)^(miyaox23);x30=(s30)^(miyaox30); x31=(s31)^(miyaox31); x32=(s32)^(miyaox32); x33=(s33)^(miyaox33);if(k<10)begini=1;endelsebegini=12;endend12:beginmiwen00<=x00;miwen01<=x01;miwen02<=x02;miwen03<=x03;miwen10<=x10;miwen11<=x11;miwen12<=x12;miwen13<=x13;miwen20<=x20;miwen21<=x21;miwen22<=x22;miwen23<=x23;miwen30<=x30;miwen31<=x31;miwen32<=x32;miwen33<=x33;endendcaseendend
end
endmodule

测试代码

`timescale 1ns/1ns
module tb();reg [7:0] mingwen00,mingwen01,mingwen02,mingwen03;reg [7:0] mingwen10,mingwen11,mingwen12,mingwen13;reg [7:0] mingwen20,mingwen21,mingwen22,mingwen23;reg [7:0] mingwen30,mingwen31,mingwen32,mingwen33;reg clk;reg rst_n;reg [7:0] miyao00,miyao01,miyao02,miyao03;reg [7:0] miyao10,miyao11,miyao12,miyao13;reg [7:0] miyao20,miyao21,miyao22,miyao23;reg [7:0] miyao30,miyao31,miyao32,miyao33;reg key;wire [7:0] miwen00,miwen01,miwen02,miwen03;wire [7:0] miwen10,miwen11,miwen12,miwen13;wire [7:0] miwen20,miwen21,miwen22,miwen23;wire [7:0] miwen30,miwen31,miwen32,miwen33;initial beginclk = 0;rst_n=0;key=0;#100rst_n=1;key=1;
/*   mingwen00<=8'h32; mingwen01<=8'h88; mingwen02<=8'h31; mingwen03<=8'he0;mingwen10<=8'h43; mingwen11<=8'h5a; mingwen12<=8'h31; mingwen13<=8'h37;mingwen20<=8'hf6; mingwen21<=8'h30; mingwen22<=8'h98; mingwen23<=8'h07;mingwen30<=8'ha8; mingwen31<=8'h8d; mingwen32<=8'ha2; mingwen33<=8'h34;miyao00<=8'h2b;miyao01<=8'h28;miyao02<=8'hab;miyao03<=8'h09;miyao10<=8'h7e;miyao11<=8'hae;miyao12<=8'hf7;miyao13<=8'hcf;miyao20<=8'h15;miyao21<=8'hd2;miyao22<=8'h15;miyao23<=8'h4f;miyao30<=8'h16;miyao31<=8'ha6;miyao32<=8'h88;miyao33<=8'h3c;*/mingwen00<=8'h00; mingwen01<=8'h12; mingwen02<=8'h0c; mingwen03<=8'h08;mingwen10<=8'h04; mingwen11<=8'h04; mingwen12<=8'h00; mingwen13<=8'h23;mingwen20<=8'h12; mingwen21<=8'h12; mingwen22<=8'h13; mingwen23<=8'h19;mingwen30<=8'h14; mingwen31<=8'h00; mingwen32<=8'h11; mingwen33<=8'h19;miyao00<=8'h24;miyao01<=8'h34;miyao02<=8'h31;miyao03<=8'h13;miyao10<=8'h75;miyao11<=8'h75;miyao12<=8'he2;miyao13<=8'haa;miyao20<=8'ha2;miyao21<=8'h56;miyao22<=8'h12;miyao23<=8'h54;miyao30<=8'hb3;miyao31<=8'h88;miyao32<=8'h00;miyao33<=8'h87;#10000$display("\tmiwen00=%h,miwen01=%h,miwen02=%h,miwen03=%h,",miwen00,miwen01,miwen02,miwen03);$display("\tmiwen10=%h,miwen11=%h,miwen12=%h,miwen13=%h,",miwen10,miwen11,miwen12,miwen13);//00 04 12 14 12 04 12 00 0c 00 13 11 08 23 19 19$display("\tmiwen20=%h,miwen21=%h,miwen22=%h,miwen23=%h,",miwen20,miwen21,miwen22,miwen23);//24 75 a2 b3 34 75 56 88 31 e2 12 00 13 aa 54 87$display("\tmiwen30=%h,miwen31=%h,miwen32=%h,miwen33=%h,",miwen30,miwen31,miwen32,miwen33);//bc 02 8b d3 e0 e3 b1 95 55 0d 6d f8 16 f1 82 41$stop;
endalways #10 clk = ~clk;AES U(mingwen00,mingwen01,mingwen02,mingwen03,mingwen10,mingwen11,mingwen12,mingwen13,mingwen20,mingwen21,mingwen22,mingwen23,mingwen30,mingwen31,mingwen32,mingwen33,clk,rst_n,miyao00,miyao01,miyao02,miyao03,miyao10,miyao11,miyao12,miyao13,miyao20,miyao21,miyao22,miyao23,miyao30,miyao31,miyao32,miyao33,key,miwen00,miwen01,miwen02,miwen03,miwen10,miwen11,miwen12,miwen13,miwen20,miwen21,miwen22,miwen23,miwen30,miwen31,miwen32,miwen33);endmodule

AES解码于2022.3.13完工,代码如下 

module AES_back(//CYXmiwen00,miwen01,miwen02,miwen03,miwen10,miwen11,miwen12,miwen13,miwen20,miwen21,miwen22,miwen23,miwen30,miwen31,miwen32,miwen33,clk,rst_n,miyao00,miyao01,miyao02,miyao03,miyao10,miyao11,miyao12,miyao13,miyao20,miyao21,miyao22,miyao23,miyao30,miyao31,miyao32,miyao33,key,mingwen00,mingwen01,mingwen02,mingwen03,mingwen10,mingwen11,mingwen12,mingwen13,mingwen20,mingwen21,mingwen22,mingwen23,mingwen30,mingwen31,mingwen32,mingwen33);
input [7:0] miwen00,miwen01,miwen02,miwen03;
input [7:0] miwen10,miwen11,miwen12,miwen13;
input [7:0] miwen20,miwen21,miwen22,miwen23;
input [7:0] miwen30,miwen31,miwen32,miwen33;
input clk;
input rst_n;
input [7:0] miyao00,miyao01,miyao02,miyao03;
input [7:0] miyao10,miyao11,miyao12,miyao13;
input [7:0] miyao20,miyao21,miyao22,miyao23;
input [7:0] miyao30,miyao31,miyao32,miyao33;
input key;
output reg [7:0] mingwen00,mingwen01,mingwen02,mingwen03;
output reg [7:0] mingwen10,mingwen11,mingwen12,mingwen13;
output reg [7:0] mingwen20,mingwen21,mingwen22,mingwen23;
output reg [7:0] mingwen30,mingwen31,mingwen32,mingwen33;
reg [7:0] miyaox00,miyaox01,miyaox02,miyaox03;
reg [7:0] miyaox10,miyaox11,miyaox12,miyaox13;
reg [7:0] miyaox20,miyaox21,miyaox22,miyaox23;
reg [7:0] miyaox30,miyaox31,miyaox32,miyaox33;
reg [7:0] x00, x01, x02, x03;
reg [7:0] x10, x11, x12, x13;
reg [7:0] x20, x21, x22, x23;
reg [7:0] x30, x31, x32, x33;
reg [127:0] x;
reg [127:0] s_2;
reg [7:0] i;
reg [7:0] i_2;
reg [7:0] j;
reg [7:0] c;
reg [7:0] d;
reg [7:0] k;
reg [7:0] p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16;
reg [7:0] s00,s01,s02,s03,s10,s11,s12,s13,s20,s21,s22,s23,s30,s31,s32,s33;
reg [7:0] s00_2,s01_2,s02_2,s03_2,s10_2,s11_2,s12_2,s13_2,s20_2,s21_2,s22_2,s23_2,s30_2,s31_2,s32_2,s33_2;
reg [7:0] s00_4,s01_4,s02_4,s03_4,s10_4,s11_4,s12_4,s13_4,s20_4,s21_4,s22_4,s23_4,s30_4,s31_4,s32_4,s33_4;
reg [7:0] s00_8,s01_8,s02_8,s03_8,s10_8,s11_8,s12_8,s13_8,s20_8,s21_8,s22_8,s23_8,s30_8,s31_8,s32_8,s33_8;
reg [7:0] s00_9,s01_9,s02_9,s03_9,s10_9,s11_9,s12_9,s13_9,s20_9,s21_9,s22_9,s23_9,s30_9,s31_9,s32_9,s33_9;
reg [7:0] s00_b,s01_b,s02_b,s03_b,s10_b,s11_b,s12_b,s13_b,s20_b,s21_b,s22_b,s23_b,s30_b,s31_b,s32_b,s33_b;
reg [7:0] s00_d,s01_d,s02_d,s03_d,s10_d,s11_d,s12_d,s13_d,s20_d,s21_d,s22_d,s23_d,s30_d,s31_d,s32_d,s33_d;
reg [7:0] s00_e,s01_e,s02_e,s03_e,s10_e,s11_e,s12_e,s13_e,s20_e,s21_e,s22_e,s23_e,s30_e,s31_e,s32_e,s33_e;
reg [7:0] m00, m01, m02, m03;
reg [7:0] m10, m11, m12, m13;
reg [7:0] m20, m21, m22, m23;
reg [7:0] m30, m31, m32, m33;
reg [7:0] mm0, mm1, mm2, mm3;
reg [31:0] mm;
reg [7:0] jj;
reg [7:0] rcon;
reg [7:0] y;
reg [7:0] kk;
always@(posedge clk or negedge rst_n)
beginif(!rst_n)begini<=0;i_2<=0;y<=0;mingwen00<=0; mingwen01<=0; mingwen02<=0; mingwen03<=0;mingwen10<=0; mingwen11<=0; mingwen12<=0; mingwen13<=0;mingwen20<=0; mingwen21<=0; mingwen22<=0; mingwen23<=0;mingwen30<=0; mingwen31<=0; mingwen32<=0; mingwen33<=0;miyaox00<=0;miyaox01<=0;miyaox02<=0;miyaox03<=0;miyaox10<=0;miyaox11<=0;miyaox12<=0;miyaox13<=0;miyaox20<=0;miyaox21<=0;miyaox22<=0;miyaox23<=0;miyaox30<=0;miyaox31<=0;miyaox32<=0;miyaox33<=0;x00<=0; x01<=0; x02<=0; x03<=0;x10<=0; x11<=0; x12<=0; x13<=0;x20<=0; x21<=0; x22<=0; x23<=0;x30<=0; x31<=0; x32<=0; x33<=0;p1<=0;  p2<=0;  p3<=0;  p4<=0;p5<=0;  p6<=0;  p7<=0;  p8<=0;p9<=0;  p10<=0; p11<=0; p12<=0;p13<=0; p14<=0; p15<=0; p16<=0;s00<=0; s01<=0; s02<=0; s03<=0;s10<=0; s11<=0; s12<=0; s13<=0;s20<=0; s21<=0; s22<=0; s23<=0;s30<=0; s31<=0; s32<=0; s33<=0;s00_2<=0; s01_2<=0; s02_2<=0; s03_2<=0;s10_2<=0; s11_2<=0; s12_2<=0; s13_2<=0;s20_2<=0; s21_2<=0; s22_2<=0; s23_2<=0;s30_2<=0; s31_2<=0; s32_2<=0; s33_2<=0;s00_9<=0; s01_9<=0; s02_9<=0; s03_9<=0;s10_9<=0; s11_9<=0; s12_9<=0; s13_9<=0;s20_9<=0; s21_9<=0; s22_9<=0; s23_9<=0;s30_9<=0; s31_9<=0; s32_9<=0; s33_9<=0;s00_4<=0; s01_4<=0; s02_4<=0; s03_4<=0;s10_4<=0; s11_4<=0; s12_4<=0; s13_4<=0;s20_4<=0; s21_4<=0; s22_4<=0; s23_4<=0;s30_4<=0; s31_4<=0; s32_4<=0; s33_4<=0;s00_8<=0; s01_8<=0; s02_8<=0; s03_8<=0;s10_8<=0; s11_8<=0; s12_8<=0; s13_8<=0;s20_8<=0; s21_8<=0; s22_9<=0; s23_8<=0;s30_8<=0; s31_8<=0; s32_8<=0; s33_8<=0;s00_b<=0; s01_b<=0; s02_b<=0; s03_b<=0;s10_b<=0; s11_b<=0; s12_b<=0; s13_b<=0;s20_b<=0; s21_b<=0; s22_b<=0; s23_b<=0;s30_b<=0; s31_b<=0; s32_b<=0; s33_b<=0;s00_d<=0; s01_d<=0; s02_d<=0; s03_d<=0;s10_d<=0; s11_d<=0; s12_d<=0; s13_d<=0;s20_d<=0; s21_d<=0; s22_d<=0; s23_d<=0;s30_d<=0; s31_d<=0; s32_d<=0; s33_d<=0;s00_e<=0; s01_e<=0; s02_e<=0; s03_e<=0;s10_e<=0; s11_e<=0; s12_e<=0; s13_e<=0;s20_e<=0; s21_e<=0; s22_e<=0; s23_e<=0;s30_e<=0; s31_e<=0; s32_e<=0; s33_e<=0;m00<=0; m01<=0; m02<=0; m03<=0;m10<=0; m11<=0; m12<=0; m13<=0;m20<=0; m21<=0; m22<=0; m23<=0;m30<=0; m31<=0; m32<=0; m33<=0;mm0<=0; mm1<=0; mm2<=0; mm3<=0;mm<=0;jj<=0;rcon<=0;c<=0;d<=0;k<=0;x<=0;s_2<=0;kk<=0;endelsebeginif(key==1)begincase(i)0:beginx00<=miwen00; x01<=miwen01; x02<=miwen02; x03<=miwen03;x10<=miwen10; x11<=miwen11; x12<=miwen12; x13<=miwen13;x20<=miwen20; x21<=miwen21; x22<=miwen22; x23<=miwen23;x30<=miwen30; x31<=miwen31; x32<=miwen32; x33<=miwen33;k<=10;i<=1;end1:beginmiyaox00=miyao00;miyaox01=miyao01;miyaox02=miyao02;miyaox03=miyao03;miyaox10=miyao10;miyaox11=miyao11;miyaox12=miyao12;miyaox13=miyao13;miyaox20=miyao20;miyaox21=miyao21;miyaox22=miyao22;miyaox23=miyao23;miyaox30=miyao30;miyaox31=miyao31;miyaox32=miyao32;miyaox33=miyao33;kk=0;while(kk<k)beginm00=miyaox00; m01=miyaox01; m02=miyaox02; m03=miyaox03;m10=miyaox10; m11=miyaox11; m12=miyaox12; m13=miyaox13;m20=miyaox20; m21=miyaox21; m22=miyaox22; m23=miyaox23;m30=miyaox30; m31=miyaox31; m32=miyaox32; m33=miyaox33;jj=0;mm0=m13;mm1=m23;mm2=m33;mm3=m03;mm={mm0,mm1,mm2,mm3};while(jj<4)beginc = mm[8*jj+7-:8];case(c)8'h00: d=8'h63; 8'h01: d=8'h7c; 8'h02: d=8'h77; 8'h03: d=8'h7b; 8'h04: d=8'hf2; 8'h05: d=8'h6b; 8'h06: d=8'h6f; 8'h07: d=8'hc5; 8'h08: d=8'h30; 8'h09: d=8'h01; 8'h0a: d=8'h67; 8'h0b: d=8'h2b; 8'h0c: d=8'hfe; 8'h0d: d=8'hd7; 8'h0e: d=8'hab; 8'h0f: d=8'h76;8'h10: d=8'hca; 8'h11: d=8'h82; 8'h12: d=8'hc9; 8'h13: d=8'h7d; 8'h14: d=8'hfa; 8'h15: d=8'h59; 8'h16: d=8'h47; 8'h17: d=8'hf0; 8'h18: d=8'had; 8'h19: d=8'hd4; 8'h1a: d=8'ha2; 8'h1b: d=8'haf; 8'h1c: d=8'h9c; 8'h1d: d=8'ha4; 8'h1e: d=8'h72; 8'h1f: d=8'hc0;8'h20: d=8'hb7; 8'h21: d=8'hfd; 8'h22: d=8'h93; 8'h23: d=8'h26; 8'h24: d=8'h36; 8'h25: d=8'h3f; 8'h26: d=8'hf7; 8'h27: d=8'hcc; 8'h28: d=8'h34; 8'h29: d=8'ha5; 8'h2a: d=8'he5; 8'h2b: d=8'hf1; 8'h2c: d=8'h71; 8'h2d: d=8'hd8; 8'h2e: d=8'h31; 8'h2f: d=8'h15;8'h30: d=8'h04; 8'h31: d=8'hc7; 8'h32: d=8'h23; 8'h33: d=8'hc3; 8'h34: d=8'h18; 8'h35: d=8'h96; 8'h36: d=8'h05; 8'h37: d=8'h9a; 8'h38: d=8'h07; 8'h39: d=8'h12; 8'h3a: d=8'h80; 8'h3b: d=8'he2; 8'h3c: d=8'heb; 8'h3d: d=8'h27; 8'h3e: d=8'hb2; 8'h3f: d=8'h75;8'h40: d=8'h09; 8'h41: d=8'h83; 8'h42: d=8'h2c; 8'h43: d=8'h1a; 8'h44: d=8'h1b; 8'h45: d=8'h6e; 8'h46: d=8'h5a; 8'h47: d=8'ha0; 8'h48: d=8'h52; 8'h49: d=8'h3b; 8'h4a: d=8'hd6; 8'h4b: d=8'hb3; 8'h4c: d=8'h29; 8'h4d: d=8'he3; 8'h4e: d=8'h2f; 8'h4f: d=8'h84;8'h50: d=8'h53; 8'h51: d=8'hd1; 8'h52: d=8'h00; 8'h53: d=8'hed; 8'h54: d=8'h20; 8'h55: d=8'hfc; 8'h56: d=8'hb1; 8'h57: d=8'h5b; 8'h58: d=8'h6a; 8'h59: d=8'hcb; 8'h5a: d=8'hbe; 8'h5b: d=8'h39; 8'h5c: d=8'h4a; 8'h5d: d=8'h4c; 8'h5e: d=8'h58; 8'h5f: d=8'hcf;8'h60: d=8'hd0; 8'h61: d=8'hef; 8'h62: d=8'haa; 8'h63: d=8'hfb; 8'h64: d=8'h43; 8'h65: d=8'h4d; 8'h66: d=8'h33; 8'h67: d=8'h85; 8'h68: d=8'h45; 8'h69: d=8'hf9; 8'h6a: d=8'h02; 8'h6b: d=8'h7f; 8'h6c: d=8'h50; 8'h6d: d=8'h3c; 8'h6e: d=8'h9f; 8'h6f: d=8'ha8;8'h70: d=8'h51; 8'h71: d=8'ha3; 8'h72: d=8'h40; 8'h73: d=8'h8f; 8'h74: d=8'h92; 8'h75: d=8'h9d; 8'h76: d=8'h38; 8'h77: d=8'hf5; 8'h78: d=8'hbc; 8'h79: d=8'hb6; 8'h7a: d=8'hda; 8'h7b: d=8'h21; 8'h7c: d=8'h10; 8'h7d: d=8'hff; 8'h7e: d=8'hf3; 8'h7f: d=8'hd2;8'h80: d=8'hcd; 8'h81: d=8'h0c; 8'h82: d=8'h13; 8'h83: d=8'hec; 8'h84: d=8'h5f; 8'h85: d=8'h97; 8'h86: d=8'h44; 8'h87: d=8'h17; 8'h88: d=8'hc4; 8'h89: d=8'ha7; 8'h8a: d=8'h7e; 8'h8b: d=8'h3d; 8'h8c: d=8'h64; 8'h8d: d=8'h5d; 8'h8e: d=8'h19; 8'h8f: d=8'h73;8'h90: d=8'h60; 8'h91: d=8'h81; 8'h92: d=8'h4f; 8'h93: d=8'hdc; 8'h94: d=8'h22; 8'h95: d=8'h2a; 8'h96: d=8'h90; 8'h97: d=8'h88; 8'h98: d=8'h46; 8'h99: d=8'hee; 8'h9a: d=8'hb8; 8'h9b: d=8'h14; 8'h9c: d=8'hde; 8'h9d: d=8'h5e; 8'h9e: d=8'h0b; 8'h9f: d=8'hdb;8'ha0: d=8'he0; 8'ha1: d=8'h32; 8'ha2: d=8'h3a; 8'ha3: d=8'h0a; 8'ha4: d=8'h49; 8'ha5: d=8'h06; 8'ha6: d=8'h24; 8'ha7: d=8'h5c; 8'ha8: d=8'hc2; 8'ha9: d=8'hd3; 8'haa: d=8'hac; 8'hab: d=8'h62; 8'hac: d=8'h91; 8'had: d=8'h95; 8'hae: d=8'he4; 8'haf: d=8'h79;8'hb0: d=8'he7; 8'hb1: d=8'hc8; 8'hb2: d=8'h37; 8'hb3: d=8'h6d; 8'hb4: d=8'h8d; 8'hb5: d=8'hd5; 8'hb6: d=8'h4e; 8'hb7: d=8'ha9; 8'hb8: d=8'h6c; 8'hb9: d=8'h56; 8'hba: d=8'hf4; 8'hbb: d=8'hea; 8'hbc: d=8'h65; 8'hbd: d=8'h7a; 8'hbe: d=8'hae; 8'hbf: d=8'h08;8'hc0: d=8'hba; 8'hc1: d=8'h78; 8'hc2: d=8'h25; 8'hc3: d=8'h2e; 8'hc4: d=8'h1c; 8'hc5: d=8'ha6; 8'hc6: d=8'hb4; 8'hc7: d=8'hc6; 8'hc8: d=8'he8; 8'hc9: d=8'hdd; 8'hca: d=8'h74; 8'hcb: d=8'h1f; 8'hcc: d=8'h4b; 8'hcd: d=8'hbd; 8'hce: d=8'h8b; 8'hcf: d=8'h8a;8'hd0: d=8'h70; 8'hd1: d=8'h3e; 8'hd2: d=8'hb5; 8'hd3: d=8'h66; 8'hd4: d=8'h48; 8'hd5: d=8'h03; 8'hd6: d=8'hf6; 8'hd7: d=8'h0e; 8'hd8: d=8'h61; 8'hd9: d=8'h35; 8'hda: d=8'h57; 8'hdb: d=8'hb9; 8'hdc: d=8'h86; 8'hdd: d=8'hc1; 8'hde: d=8'h1d; 8'hdf: d=8'h9e;8'he0: d=8'he1; 8'he1: d=8'hf8; 8'he2: d=8'h98; 8'he3: d=8'h11; 8'he4: d=8'h69; 8'he5: d=8'hd9; 8'he6: d=8'h8e; 8'he7: d=8'h94; 8'he8: d=8'h9b; 8'he9: d=8'h1e; 8'hea: d=8'h87; 8'heb: d=8'he9; 8'hec: d=8'hce; 8'hed: d=8'h55; 8'hee: d=8'h28; 8'hef: d=8'hdf;8'hf0: d=8'h8c; 8'hf1: d=8'ha1; 8'hf2: d=8'h89; 8'hf3: d=8'h0d; 8'hf4: d=8'hbf; 8'hf5: d=8'he6; 8'hf6: d=8'h42; 8'hf7: d=8'h68; 8'hf8: d=8'h41; 8'hf9: d=8'h99; 8'hfa: d=8'h2d; 8'hfb: d=8'h0f; 8'hfc: d=8'hb0; 8'hfd: d=8'h54; 8'hfe: d=8'hbb; 8'hff: d=8'h16;endcasemm[8*jj+7-:8] = d;jj = jj+1;endcase(kk+1)8'h01: rcon=8'h01;8'h02: rcon=8'h02;8'h03: rcon=8'h04;8'h04: rcon=8'h08;8'h05: rcon=8'h10;8'h06: rcon=8'h20;8'h07: rcon=8'h40;8'h08: rcon=8'h80;8'h09: rcon=8'h1b;8'h0a: rcon=8'h36;endcasemm0=mm[31:24];mm1=mm[23:16];mm2=mm[15:8];mm3=mm[7:0];miyaox00=(m00)^(mm0)^(rcon);miyaox10=(m10)^(mm1);miyaox20=(m20)^(mm2);miyaox30=(m30)^(mm3);miyaox01=(m01)^(miyaox00);miyaox11=(m11)^(miyaox10);miyaox21=(m21)^(miyaox20);miyaox31=(m31)^(miyaox30);miyaox02=(m02)^(miyaox01);miyaox12=(m12)^(miyaox11);miyaox22=(m22)^(miyaox21);miyaox32=(m32)^(miyaox31);miyaox03=(m03)^(miyaox02);miyaox13=(m13)^(miyaox12);miyaox23=(m23)^(miyaox22);miyaox33=(m33)^(miyaox32);kk=kk+1;endi=2;end2://lun mi xiang jia(addroundkey)begin//saves00<=x00;s01<=x01;s02<=x02;s03<=x03;s10<=x10;s11<=x11;s12<=x12;s13<=x13;s20<=x20;s21<=x21;s22<=x22;s23<=x23;s30<=x30;s31<=x31;s32<=x32;s33<=x33;i<=3;end3://lun mi xiang jia(addroundkey)beginx00=(s00)^(miyaox00); x01=(s01)^(miyaox01); x02=(s02)^(miyaox02); x03=(s03)^(miyaox03);x10=(s10)^(miyaox10); x11=(s11)^(miyaox11); x12=(s12)^(miyaox12); x13=(s13)^(miyaox13);x20=(s20)^(miyaox20); x21=(s21)^(miyaox21); x22=(s22)^(miyaox22); x23=(s23)^(miyaox23);x30=(s30)^(miyaox30); x31=(s31)^(miyaox31); x32=(s32)^(miyaox32); x33=(s33)^(miyaox33);k=k-1;if(k==9)begini=6;endelse if(k<9)begini=8;endelse begini=11;end end4://zi jie bian hua(subbytes)beginx = {x00, x01, x02, x03,x10, x11, x12, x13,x20, x21, x22, x23,x30, x31, x32, x33};j=0;i=5;end5:  beginwhile(j<16)beginc = x[8*j+7-:8];case(c)8'h00: d=8'h52; 8'h01: d=8'h09; 8'h02: d=8'h6a; 8'h03: d=8'hd5; 8'h04: d=8'h30; 8'h05: d=8'h36; 8'h06: d=8'ha5; 8'h07: d=8'h38; 8'h08: d=8'hbf; 8'h09: d=8'h40; 8'h0a: d=8'ha3; 8'h0b: d=8'h9e; 8'h0c: d=8'h81; 8'h0d: d=8'hf3; 8'h0e: d=8'hd7; 8'h0f: d=8'hfb;8'h10: d=8'h7c; 8'h11: d=8'he3; 8'h12: d=8'h39; 8'h13: d=8'h82; 8'h14: d=8'h9b; 8'h15: d=8'h2f; 8'h16: d=8'hff; 8'h17: d=8'h87; 8'h18: d=8'h34; 8'h19: d=8'h8e; 8'h1a: d=8'h43; 8'h1b: d=8'h44; 8'h1c: d=8'hc4; 8'h1d: d=8'hde; 8'h1e: d=8'he9; 8'h1f: d=8'hcb;8'h20: d=8'h54; 8'h21: d=8'h7b; 8'h22: d=8'h94; 8'h23: d=8'h32; 8'h24: d=8'ha6; 8'h25: d=8'hc2; 8'h26: d=8'h23; 8'h27: d=8'h3d; 8'h28: d=8'hee; 8'h29: d=8'h4c; 8'h2a: d=8'h95; 8'h2b: d=8'h0b; 8'h2c: d=8'h42; 8'h2d: d=8'hfa; 8'h2e: d=8'hc3; 8'h2f: d=8'h4e;8'h30: d=8'h08; 8'h31: d=8'h2e; 8'h32: d=8'ha1; 8'h33: d=8'h66; 8'h34: d=8'h28; 8'h35: d=8'hd9; 8'h36: d=8'h24; 8'h37: d=8'hb2; 8'h38: d=8'h76; 8'h39: d=8'h5b; 8'h3a: d=8'ha2; 8'h3b: d=8'h49; 8'h3c: d=8'h6d; 8'h3d: d=8'h8b; 8'h3e: d=8'hd1; 8'h3f: d=8'h25;8'h40: d=8'h72; 8'h41: d=8'hf8; 8'h42: d=8'hf6; 8'h43: d=8'h64; 8'h44: d=8'h86; 8'h45: d=8'h68; 8'h46: d=8'h98; 8'h47: d=8'h16; 8'h48: d=8'hd4; 8'h49: d=8'ha4; 8'h4a: d=8'h5c; 8'h4b: d=8'hcc; 8'h4c: d=8'h5d; 8'h4d: d=8'h65; 8'h4e: d=8'hb6; 8'h4f: d=8'h92;8'h50: d=8'h6c; 8'h51: d=8'h70; 8'h52: d=8'h48; 8'h53: d=8'h50; 8'h54: d=8'hfd; 8'h55: d=8'hed; 8'h56: d=8'hb9; 8'h57: d=8'hda; 8'h58: d=8'h5e; 8'h59: d=8'h15; 8'h5a: d=8'h46; 8'h5b: d=8'h57; 8'h5c: d=8'ha7; 8'h5d: d=8'h8d; 8'h5e: d=8'h9d; 8'h5f: d=8'h84;8'h60: d=8'h90; 8'h61: d=8'hd8; 8'h62: d=8'hab; 8'h63: d=8'h00; 8'h64: d=8'h8c; 8'h65: d=8'hbc; 8'h66: d=8'hd3; 8'h67: d=8'h0a; 8'h68: d=8'hf7; 8'h69: d=8'he4; 8'h6a: d=8'h58; 8'h6b: d=8'h05; 8'h6c: d=8'hb8; 8'h6d: d=8'hb3; 8'h6e: d=8'h45; 8'h6f: d=8'h06;8'h70: d=8'hd0; 8'h71: d=8'h2c; 8'h72: d=8'h1e; 8'h73: d=8'h8f; 8'h74: d=8'hca; 8'h75: d=8'h3f; 8'h76: d=8'h0f; 8'h77: d=8'h02; 8'h78: d=8'hc1; 8'h79: d=8'haf; 8'h7a: d=8'hbd; 8'h7b: d=8'h03; 8'h7c: d=8'h01; 8'h7d: d=8'h13; 8'h7e: d=8'h8a; 8'h7f: d=8'h6b;8'h80: d=8'h3a; 8'h81: d=8'h91; 8'h82: d=8'h11; 8'h83: d=8'h41; 8'h84: d=8'h4f; 8'h85: d=8'h67; 8'h86: d=8'hdc; 8'h87: d=8'hea; 8'h88: d=8'h97; 8'h89: d=8'hf2; 8'h8a: d=8'hcf; 8'h8b: d=8'hce; 8'h8c: d=8'hf0; 8'h8d: d=8'hb4; 8'h8e: d=8'he6; 8'h8f: d=8'h73;8'h90: d=8'h96; 8'h91: d=8'hac; 8'h92: d=8'h74; 8'h93: d=8'h22; 8'h94: d=8'he7; 8'h95: d=8'had; 8'h96: d=8'h35; 8'h97: d=8'h85; 8'h98: d=8'he2; 8'h99: d=8'hf9; 8'h9a: d=8'h37; 8'h9b: d=8'he8; 8'h9c: d=8'h1c; 8'h9d: d=8'h75; 8'h9e: d=8'hdf; 8'h9f: d=8'h6e;8'ha0: d=8'h47; 8'ha1: d=8'hf1; 8'ha2: d=8'h1a; 8'ha3: d=8'h71; 8'ha4: d=8'h1d; 8'ha5: d=8'h29; 8'ha6: d=8'hc5; 8'ha7: d=8'h89; 8'ha8: d=8'h6f; 8'ha9: d=8'hb7; 8'haa: d=8'h62; 8'hab: d=8'h0e; 8'hac: d=8'haa; 8'had: d=8'h18; 8'hae: d=8'hbe; 8'haf: d=8'h1b;8'hb0: d=8'hfc; 8'hb1: d=8'h56; 8'hb2: d=8'h3e; 8'hb3: d=8'h4b; 8'hb4: d=8'hc6; 8'hb5: d=8'hd2; 8'hb6: d=8'h79; 8'hb7: d=8'h20; 8'hb8: d=8'h9a; 8'hb9: d=8'hdb; 8'hba: d=8'hc0; 8'hbb: d=8'hfe; 8'hbc: d=8'h78; 8'hbd: d=8'hcd; 8'hbe: d=8'h5a; 8'hbf: d=8'hf4;8'hc0: d=8'h1f; 8'hc1: d=8'hdd; 8'hc2: d=8'ha8; 8'hc3: d=8'h33; 8'hc4: d=8'h88; 8'hc5: d=8'h07; 8'hc6: d=8'hc7; 8'hc7: d=8'h31; 8'hc8: d=8'hb1; 8'hc9: d=8'h12; 8'hca: d=8'h10; 8'hcb: d=8'h59; 8'hcc: d=8'h27; 8'hcd: d=8'h80; 8'hce: d=8'hec; 8'hcf: d=8'h5f;8'hd0: d=8'h60; 8'hd1: d=8'h51; 8'hd2: d=8'h7f; 8'hd3: d=8'ha9; 8'hd4: d=8'h19; 8'hd5: d=8'hb5; 8'hd6: d=8'h4a; 8'hd7: d=8'h0d; 8'hd8: d=8'h2d; 8'hd9: d=8'he5; 8'hda: d=8'h7a; 8'hdb: d=8'h9f; 8'hdc: d=8'h93; 8'hdd: d=8'hc9; 8'hde: d=8'h9c; 8'hdf: d=8'hef;8'he0: d=8'ha0; 8'he1: d=8'he0; 8'he2: d=8'h3b; 8'he3: d=8'h4d; 8'he4: d=8'hae; 8'he5: d=8'h2a; 8'he6: d=8'hf5; 8'he7: d=8'hb0; 8'he8: d=8'hc8; 8'he9: d=8'heb; 8'hea: d=8'hbb; 8'heb: d=8'h3c; 8'hec: d=8'h83; 8'hed: d=8'h53; 8'hee: d=8'h99; 8'hef: d=8'h61;8'hf0: d=8'h17; 8'hf1: d=8'h2b; 8'hf2: d=8'h04; 8'hf3: d=8'h7e; 8'hf4: d=8'hba; 8'hf5: d=8'h77; 8'hf6: d=8'hd6; 8'hf7: d=8'h26; 8'hf8: d=8'he1; 8'hf9: d=8'h69; 8'hfa: d=8'h14; 8'hfb: d=8'h63; 8'hfc: d=8'h55; 8'hfd: d=8'h21; 8'hfe: d=8'h0c; 8'hff: d=8'h7d;endcasex[8*j+7-:8] = d;j=j+1;endx00=x[127:120]; x01=x[119:112]; x02=x[111:104]; x03=x[103:96];x10=x[95:88];   x11=x[87:80];   x12=x[79:72];   x13=x[71:64];x20=x[63:56];   x21=x[55:48];   x22=x[47:40];   x23=x[39:32];x30=x[31:24];   x31=x[23:16];   x32=x[15:8];    x33=x[7:0];i=1;end6://hang yi wei(shiftrows)begin//savep1<=x00; p5<=x01; p9<=x02;  p13<=x03;p2<=x10; p6<=x11; p10<=x12; p14<=x13;p3<=x20; p7<=x21; p11<=x22; p15<=x23;p4<=x30; p8<=x31; p12<=x32; p16<=x33;i<=7;end7://hang yi wei(shiftrows)beginx00<=p1;  x01<=p5;  x02<=p9;  x03<=p13;//1 no changex10<=p14; x11<=p2;  x12<=p6;  x13<=p10;//2>>1x20<=p11; x21<=p15; x22<=p3;  x23<=p7;//3>>2x30<=p8;  x31<=p12; x32<=p16; x33<=p4;//4>>3i<=4;end8://lie hun he(mixcolumns)begin//saves00<=x00;s01<=x01;s02<=x02;s03<=x03;s10<=x10;s11<=x11;s12<=x12;s13<=x13;s20<=x20;s21<=x21;s22<=x22;s23<=x23;s30<=x30;s31<=x31;s32<=x32;s33<=x33;s_2<={x00,x01,x02,x03,x10,x11,x12,x13,x20,x21,x22,x23,x30,x31,x32,x33};i<=9;i_2<=0;y<=0;end9:beginwhile(y<3)beginwhile(i_2<16)beginif((s_2[8*i_2+7])==0)begins_2[8*i_2+7-:8]={s_2[8*i_2+6-:7],1'b0};endelsebegins_2[8*i_2+7-:8]=({s_2[8*i_2+6-:7],1'b0})^(8'b0001_1011);endi_2=i_2+1;endif(y==0)begins00_2=s_2[127:120]; s01_2=s_2[119:112]; s02_2=s_2[111:104]; s03_2=s_2[103:96];s10_2=s_2[95:88];   s11_2=s_2[87:80];   s12_2=s_2[79:72];   s13_2=s_2[71:64];s20_2=s_2[63:56];   s21_2=s_2[55:48];   s22_2=s_2[47:40];   s23_2=s_2[39:32];s30_2=s_2[31:24];   s31_2=s_2[23:16];   s32_2=s_2[15:8];    s33_2=s_2[7:0]; endelse if(y==1)begins00_4=s_2[127:120]; s01_4=s_2[119:112]; s02_4=s_2[111:104]; s03_4=s_2[103:96];s10_4=s_2[95:88];   s11_4=s_2[87:80];   s12_4=s_2[79:72];   s13_4=s_2[71:64];s20_4=s_2[63:56];   s21_4=s_2[55:48];   s22_4=s_2[47:40];   s23_4=s_2[39:32];s30_4=s_2[31:24];   s31_4=s_2[23:16];   s32_4=s_2[15:8];    s33_4=s_2[7:0];endelse if(y==2)begins00_8=s_2[127:120]; s01_8=s_2[119:112]; s02_8=s_2[111:104]; s03_8=s_2[103:96];s10_8=s_2[95:88];   s11_8=s_2[87:80];   s12_8=s_2[79:72];   s13_8=s_2[71:64];s20_8=s_2[63:56];   s21_8=s_2[55:48];   s22_8=s_2[47:40];   s23_8=s_2[39:32];s30_8=s_2[31:24];   s31_8=s_2[23:16];   s32_8=s_2[15:8];    s33_8=s_2[7:0];endy=y+1;i_2=0;ends00_9=s00_8^s00;    s01_9=s01_8^s01;    s02_9=s02_8^s02;    s03_9=s03_8^s03;s10_9=s10_8^s10;    s11_9=s11_8^s11;    s12_9=s12_8^s12;    s13_9=s13_8^s13;s20_9=s20_8^s20;    s21_9=s21_8^s21;    s22_9=s22_8^s22;    s23_9=s23_8^s23;s30_9=s30_8^s30;    s31_9=s31_8^s31;    s32_9=s32_8^s32;    s33_9=s33_8^s33;s00_b=s00_2^s00_9;    s01_b=s01_2^s01_9;    s02_b=s02_2^s02_9;    s03_b=s03_2^s03_9;s10_b=s10_2^s10_9;    s11_b=s11_2^s11_9;    s12_b=s12_2^s12_9;    s13_b=s13_2^s13_9;s20_b=s20_2^s20_9;    s21_b=s21_2^s21_9;    s22_b=s22_2^s22_9;    s23_b=s23_2^s23_9;s30_b=s30_2^s30_9;    s31_b=s31_2^s31_9;    s32_b=s32_2^s32_9;    s33_b=s33_2^s33_9;s00_d=s00_4^s00_9;    s01_d=s01_4^s01_9;    s02_d=s02_4^s02_9;    s03_d=s03_4^s03_9;s10_d=s10_4^s10_9;    s11_d=s11_4^s11_9;    s12_d=s12_4^s12_9;    s13_d=s13_4^s13_9;s20_d=s20_4^s20_9;    s21_d=s21_4^s21_9;    s22_d=s22_4^s22_9;    s23_d=s23_4^s23_9;s30_d=s30_4^s30_9;    s31_d=s31_4^s31_9;    s32_d=s32_4^s32_9;    s33_d=s33_4^s33_9;s00_e=s00_2^s00_4^s00_8;   s01_e=s01_2^s01_4^s01_8;   s02_e=s02_2^s02_4^s02_8;   s03_e=s03_2^s03_4^s03_8;s10_e=s10_2^s10_4^s10_8;   s11_e=s11_2^s11_4^s11_8;   s12_e=s12_2^s12_4^s12_8;   s13_e=s13_2^s13_4^s13_8;s20_e=s20_2^s20_4^s20_8;   s21_e=s21_2^s21_4^s21_8;   s22_e=s22_2^s22_4^s22_8;   s23_e=s23_2^s23_4^s23_8;s30_e=s30_2^s30_4^s30_8;   s31_e=s31_2^s31_4^s31_8;   s32_e=s32_2^s32_4^s32_8;   s33_e=s33_2^s33_4^s33_8;i=10;end10://lie hun he(mixcolumns)begin//calx00<=(s00_e)^(s10_b)^(s20_d)^(s30_9);x01<=(s01_e)^(s11_b)^(s21_d)^(s31_9);x02<=(s02_e)^(s12_b)^(s22_d)^(s32_9);x03<=(s03_e)^(s13_b)^(s23_d)^(s33_9);//row 0x10<=(s00_9)^(s10_e)^(s20_b)^(s30_d);x11<=(s01_9)^(s11_e)^(s21_b)^(s31_d);x12<=(s02_9)^(s12_e)^(s22_b)^(s32_d);x13<=(s03_9)^(s13_e)^(s23_b)^(s33_d);//row 1x20<=(s00_d)^(s10_9)^(s20_e)^(s30_b);x21<=(s01_d)^(s11_9)^(s21_e)^(s31_b);x22<=(s02_d)^(s12_9)^(s22_e)^(s32_b);x23<=(s03_d)^(s13_9)^(s23_e)^(s33_b);//row 2x30<=(s00_b)^(s10_d)^(s20_9)^(s30_e);x31<=(s01_b)^(s11_d)^(s21_9)^(s31_e);x32<=(s02_b)^(s12_d)^(s22_9)^(s32_e);x33<=(s03_b)^(s13_d)^(s23_9)^(s33_e);//row 3i<=6;end11://beginmingwen00<=x00;mingwen01<=x01;mingwen02<=x02;mingwen03<=x03;mingwen10<=x10;mingwen11<=x11;mingwen12<=x12;mingwen13<=x13;mingwen20<=x20;mingwen21<=x21;mingwen22<=x22;mingwen23<=x23;mingwen30<=x30;mingwen31<=x31;mingwen32<=x32;mingwen33<=x33;endendcaseendend
end
endmodule

AES解码的测试代码 

`timescale 1ns/1ns
module tb();reg [7:0] mingwen00,mingwen01,mingwen02,mingwen03;reg [7:0] mingwen10,mingwen11,mingwen12,mingwen13;reg [7:0] mingwen20,mingwen21,mingwen22,mingwen23;reg [7:0] mingwen30,mingwen31,mingwen32,mingwen33;reg clk;reg rst_n;reg [7:0] miyao00,miyao01,miyao02,miyao03;reg [7:0] miyao10,miyao11,miyao12,miyao13;reg [7:0] miyao20,miyao21,miyao22,miyao23;reg [7:0] miyao30,miyao31,miyao32,miyao33;reg key;wire [7:0] miwen00,miwen01,miwen02,miwen03;wire [7:0] miwen10,miwen11,miwen12,miwen13;wire [7:0] miwen20,miwen21,miwen22,miwen23;wire [7:0] miwen30,miwen31,miwen32,miwen33;initial beginclk = 0;rst_n=0;key=0;#100rst_n=1;key=1;mingwen00<=8'hbc; mingwen01<=8'he0; mingwen02<=8'h55; mingwen03<=8'he6;mingwen10<=8'h02; mingwen11<=8'he3; mingwen12<=8'h0d; mingwen13<=8'hf1;mingwen20<=8'h8b; mingwen21<=8'hb1; mingwen22<=8'h6d; mingwen23<=8'h82;mingwen30<=8'hd3; mingwen31<=8'h95; mingwen32<=8'hf8; mingwen33<=8'h41;miyao00<=8'h24;miyao01<=8'h34;miyao02<=8'h31;miyao03<=8'h13;miyao10<=8'h75;miyao11<=8'h75;miyao12<=8'he2;miyao13<=8'haa;miyao20<=8'ha2;miyao21<=8'h56;miyao22<=8'h12;miyao23<=8'h54;miyao30<=8'hb3;miyao31<=8'h88;miyao32<=8'h00;miyao33<=8'h87;#10000$display("\tmingwen00=%h,mingwen01=%h,mingwen02=%h,mingwen03=%h,",miwen00,miwen01,miwen02,miwen03);$display("\tmingwen10=%h,mingwen11=%h,mingwen12=%h,mingwen13=%h,",miwen10,miwen11,miwen12,miwen13);//00 04 12 14 12 04 12 00 0c 00 13 11 08 23 19 19$display("\tmingwen20=%h,mingwen21=%h,mingwen22=%h,mingwen23=%h,",miwen20,miwen21,miwen22,miwen23);//24 75 a2 b3 34 75 56 88 31 e2 12 00 13 aa 54 87$display("\tmingwen30=%h,mingwen31=%h,mingwen32=%h,mingwen33=%h,",miwen30,miwen31,miwen32,miwen33);//bc 02 8b d3 e0 e3 b1 95 55 0d 6d f8 e6 f1 82 41$stop;
endalways #10 clk = ~clk;AES_back U(mingwen00,mingwen01,mingwen02,mingwen03,mingwen10,mingwen11,mingwen12,mingwen13,mingwen20,mingwen21,mingwen22,mingwen23,mingwen30,mingwen31,mingwen32,mingwen33,clk,rst_n,miyao00,miyao01,miyao02,miyao03,miyao10,miyao11,miyao12,miyao13,miyao20,miyao21,miyao22,miyao23,miyao30,miyao31,miyao32,miyao33,key,miwen00,miwen01,miwen02,miwen03,miwen10,miwen11,miwen12,miwen13,miwen20,miwen21,miwen22,miwen23,miwen30,miwen31,miwen32,miwen33);endmodule

敲代码挺快乐的,哈哈

 

原理补充(仅借鉴)

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkBYWFhBTEVYQU4,size_20,color_FFFFFF,t_70,g_se,x_16

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkBYWFhBTEVYQU4,size_20,color_FFFFFF,t_70,g_se,x_16 

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkBYWFhBTEVYQU4,size_20,color_FFFFFF,t_70,g_se,x_16 

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETkBYWFhBTEVYQU4,size_20,color_FFFFFF,t_70,g_se,x_16 

 


http://www.ppmy.cn/news/162752.html

相关文章

SM4分组密码算法的verilog实现(附免费可用代码)

SM4算法是一个分组加密算法&#xff0c;消息分组和密钥长度均为 128 bit&#xff0c;主要包括密钥扩展算法、加密算法和解密算法。算法采用32轮非线性迭代结构&#xff0c;加密和解密算法结构相同&#xff0c;只是轮密钥使用顺序相反。针对SM4密码算法的硬件设计&#xff0c;分…

【Python C扩展】零基础也能轻松掌握的学习路线与参考资料

Python C扩展是将Python语言与C语言相结合&#xff0c;最大限度地利用C语言的高性能和Python语言的灵活性&#xff0c;使Python程序获得更高的运行效率。Python C扩展的学习路线涵盖了C语言基础、Python语言、Python C API等多个方面。下面将详细介绍Python C扩展的学习路线&am…

rx590 黑苹果 无货_黑苹果10.14免驱显卡表

免驱动的显卡涵盖的范围比较广&#xff0c;主要有Vega 64、RX系列、R9系列和HD7系列等消费级显卡产品&#xff0c;Radeon Pro和FirePro专业显卡产品等AMD显卡的产品。 黑苹果10.14免驱显卡表 1、消费级显卡&#xff1a;Vega 64、Vega 56&#xff1b;RX 560、RX 560D、RX 570、R…

Hbase手动split、compact、merge、批量合并分区

Hbase手动split、compact、merge、批量合并分区 hbase shell命令手动Split: // 手动 split region split TABLENAME split REGIONNAME split ENCODED_REGIONNAME split TABLENAME,splitKey split REGIONNAME,splitKey split ENCODED_REGIONNAME,splitKeyhbase shell命令合并&…

Modbus通信协议应用——风速传感器HS-FS01(串口显示)

风速传感器HS-FS01 485型采用Modbus-Rtu通信协议&#xff0c;本代码部分基于正点原子f1战舰V3。 首先&#xff0c;了解一下什么是Modbus协议。 Modbus是一种串行通信协议&#xff0c;是Modicon公司&#xff08;现在的施耐德电气 Schneider Electric&#xff09;于1979年为使用…

转-HD7 刷机教程 硬起 进三色屏详解教程

转-HD7 刷机教程 硬起 进三色屏详解教程 前言、 1、由于本帖中含有大量刷机基础和术语&#xff0c;因此对于没有任何刷机经验的人请先在论坛多多学习后再刷机 2、刷机步骤目录&#xff1a; 1&#xff09;选择、下载ROM&#xff1b;手机充电至50%以上 2&#xff09;开始刷机&…

MODBUS通信协议学习(二):通信方式

目录 前言MODBUS通信模式串行链路Modbus ASCII通信格式数据格式LRC Modbus RTU通信格式数据格式CRC 网络链路通信格式TCPModbus TCP/IP 数据格式MBAP报头文&#xff1a; 前言 初步了解了链接: MODBUS协议.现在具体学习通信模式。 这篇文章在学习过程中作为总结&#xff0c;如有…

【存储数据恢复】HP EVA存储误删除VDISK的数据恢复案例

存储数据恢复环境&#xff1a; 一台HP EVA某型号存储&#xff0c;2组扩展柜&#xff1b; 12块FATA磁盘10个FC磁盘&#xff0c;不确定LUN数量&#xff1b; WINDOWS操作系统&#xff0c;存储历史案例审理材料。 存储故障原因不明。 存储故障初检&分析&#xff1a; 1、通过和管…