always @ (posedge clk or negedge rst_n) begin if(!rst_n) S10 <= 8'h00; else if(en_row_shift) S10 <= S11; else if(en_horizontalshift) S10 <= S11; end
复制代码
这个是线性反馈移位寄存器的描述:
reg [4:0] lfsr;
always @(negedge clk or negedge reset_n)if(!reset_n) lfsr <= 5'b00010;else begin lfsr[4:1] <= lfsr[3:0]; lfsr[0] <= lfsr[4]^lfsr[0]; end
复制代码
控制单元是组合逻辑:
case(lfsr) //be aware the LFSR will run right after the second posedge of clk //so... also we can one signal to make the lfsr not run until all the 5'h02: //data has been put, and secure the LFSR module. begin en_horizontalshift_keyarray <=1'b0; //KeyArray w[i] (i mod 4 = 0) generation en_vertical_shift <=1'b1; //take four clocks,1st KeyGeneration en_k00_xor <=8'h00;// loadkey <=1'b0; // en_row_shift <=1'b1; // Row Shift is done en_horizontalshift_statearray<=1'b0; // en_addroundkey <=1'b0; //do not care anymore. end