kexp_d.v
2.48 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// This confidential and propriety software may be used
// only as authorized by a licensing agreement from
// Ocean Logic Pty Ltd http://www.ocean-logic.com
//
// In the event of publication, the following notice is
// applicable
//
// (C) COPYRIGHT 2001 Ocean Logic Pty Ltd
// ALL RIGHTS RESERVED
//
// the entire notice must be reproduced on all
// authorized copies
//
// File : kexp_d.vhd
// Author : Vincenzo Liguori
// Date : 01-03-02
// Version 1.0
// Abstract :
// Decryption key expander top module
//
// Modification history :
// Date by Version Change description
// -------------------------------------------------
// 01-03-02 VL 1.0 Original
module kexp_d(
clk,
rstn,
go,
en,
ksize,
kin,
key,
addr,
key_req,
key_last
);
// Inputs
input clk, rstn;
input go, en;
input[1:0] ksize;
input[31:0] kin;
// Outputs
output[31:0] key;
output[5:0] addr;
output key_req;
output key_last;
wire clk;
wire rstn;
wire go;
wire en;
wire [1:0] ksize;
wire [31:0] kin;
wire [31:0] key;
wire [5:0] addr;
wire key_req;
wire key_last;
wire [31:0] keye;
wire [31:0] keyd;
wire first;
wire final;
wire [7:0] ke0;
wire [7:0] kb0;
wire [7:0] kd0;
wire [7:0] k90;
wire [7:0] ke1;
wire [7:0] kb1;
wire [7:0] kd1;
wire [7:0] k91;
wire [7:0] ke2;
wire [7:0] kb2;
wire [7:0] kd2;
wire [7:0] k92;
wire [7:0] ke3;
wire [7:0] kb3;
wire [7:0] kd3;
wire [7:0] k93;
// Instantiate the AES key expander
kexp kx(
// Inputs
.clk(clk),
.rstn(rstn),
.go(go),
.en(en),
.ksize(ksize),
.kin(kin),
// Outputs
.key(keye),
.addr(addr),
.first(first),
.final(final),
.key_req(key_req),
.key_last(key_last));
// Perform the mixcol operation
mixcol mx0(
.x(keye[31:24] ),
.do0(ke0),
.do1(kb0),
.do2(kd0),
.do3(k90));
mixcol mx1(
.x(keye[23:16] ),
.do0(ke1),
.do1(kb1),
.do2(kd1),
.do3(k91));
mixcol mx2(
.x(keye[15:8] ),
.do0(ke2),
.do1(kb2),
.do2(kd2),
.do3(k92));
mixcol mx3(
.x(keye[7:0] ),
.do0(ke3),
.do1(kb3),
.do2(kd3),
.do3(k93));
assign keyd[31:24] = ke0 ^ kb1 ^ kd2 ^ k93;
assign keyd[23:16] = k90 ^ ke1 ^ kb2 ^ kd3;
assign keyd[15:8] = kd0 ^ k91 ^ ke2 ^ kb3;
assign keyd[7:0] = kb0 ^ kd1 ^ k92 ^ ke3;
// Select the appropriate expanded key
assign key = (first | final) == 1'b 1 ? keye : keyd;
endmodule