-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecryption.v
More file actions
53 lines (43 loc) · 1.32 KB
/
decryption.v
File metadata and controls
53 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
`include "invSbox.v"
`include "inverseSubBytes.v"
`include "invShiftRows.v"
`include "invMixColumns.v"
`include "decryptEachRound.v"
module decryption
#(parameter N=256,parameter NumRounds=14,parameter Numkeys=8)(
input clk,
input rst,
input wire [127:0] in,
input wire [N-1:0] key,
output wire [127:0] out,
input wire [N-1:0] sbox_seed
);
reg [127:0] out_reg;
wire [(128*(NumRounds+1))-1 :0] expandedkeys;
wire [127:0] ShiftRowsOut;
wire [127:0] stages [NumRounds+1:0] ;
wire [127:0] SubBytesOut;
wire [127:0] MixColsOut;
keyExpansion #(Numkeys,NumRounds) ke (key,expandedkeys);
addRoundKey addrk1 (in,stages[0],expandedkeys[127:0]);
genvar i;
generate
for(i=1; i<NumRounds ;i=i+1)begin
decryptRound dr(
stages[i-1],
expandedkeys[i*128+:128],
stages[i],
sbox_seed,
NumRounds-i+1);
end
endgenerate
inverseMixColumns invmixcols(stages[NumRounds-1], MixColsOut);
inverseShiftRows sr(MixColsOut,ShiftRowsOut);
inverseSubBytes sb(ShiftRowsOut,SubBytesOut,sbox_seed,1);
addRoundKey addrk2(SubBytesOut,stages[NumRounds],expandedkeys[((128*(NumRounds+1))-1)-:128]);
always@(posedge clk) begin
if(rst) out_reg <= 0;
else out_reg <= stages[NumRounds];
end
assign out=out_reg;
endmodule