OpenCores
URL https://opencores.org/ocsvn/simon_core/simon_core/trunk

Subversion Repositories simon_core

[/] [simon_core/] [codes/] [Simon_bit_serial_key_expansion_FPGA.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 aydinay
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Team: Virginia Tech Secure Embedded Systems (SES) Lab 
4
// Implementer: Ege Gulcan
5
// 
6
// Create Date:    16:55:06 11/12/2013 
7
// Design Name: 
8
// Module Name:    simon_key_expansion_shiftreg 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
 
22
module simon_key_expansion_shiftreg(clk,data_in,key_out,data_rdy,bit_counter,round_counter_out);
23
 
24
input clk;
25
input data_in;
26
input [1:0] data_rdy;
27
input [5:0] bit_counter;
28
output key_out;
29
output round_counter_out;
30
 
31
 
32
reg [59:0] shifter1;
33
reg [63:0] shifter2;
34
reg shift_in1,shift_in2;
35
wire shift_out1,shift_out2;
36
reg shifter_enable1,shifter_enable2;
37
 
38
reg lut_ff_enable,fifo_ff_enable;
39
wire lut_out;
40
reg lut_in3;
41
reg s2,s3;
42
reg [1:0] s1;
43
reg [6:0] round_counter;
44
reg z_value;
45
 
46
reg fifo_ff0,fifo_ff1,fifo_ff2,fifo_ff3;
47
 
48
//(* shreg_extract = "no" *)
49
reg lut_ff0,lut_ff1,lut_ff2,lut_ff3;
50
//Constant value Z ROM
51
reg [0:67] Z = 68'b10101111011100000011010010011000101000010001111110010110110011101011;
52
reg c;
53
 
54
 
55
/////////////////////////////////////////
56
//// BEGIN CODE ////////////////////////
57
///////////////////////////////////////
58
 
59
// Least bit of the round counter is sent to the datapath to check if it is even or odd
60
assign round_counter_out = round_counter[0];
61
 
62
// Shift Register1 FIFO 60x1 Begin
63
// 60x1 shift register storing the 60 most significant bits of the upper word of the key
64
always @(posedge clk)
65
begin
66
        if(shifter_enable1)
67
        begin
68
                shifter1 <= {shift_in1, shifter1[59:1]};
69
        end
70
end
71
 
72
assign shift_out1 = shifter1[0];
73
// Shift Register1 End
74
 
75
// Shift Register2 FIFO 64x1 Begin
76
// 64x1 shift register storing the lower word of the key
77
always @(posedge clk)
78
begin
79
        if(shifter_enable2)
80
        begin
81
                shifter2 <= {shift_in2, shifter2[63:1]};
82
        end
83
end
84
 
85
assign shift_out2 = shifter2[0];
86
// Shift Register2 End
87
 
88
// 4 flip-flops storing the least significant 4 bits of the upper word in the first round
89
always @(posedge clk)
90
begin
91
        if(fifo_ff_enable)
92
        begin
93
                fifo_ff3 <= shift_out1;
94
                fifo_ff2 <= fifo_ff3;
95
                fifo_ff1 <= fifo_ff2;
96
                fifo_ff0 <= fifo_ff1;
97
        end
98
end
99
 
100
// 4 flip-flops storing the least significant 4 bits of the upper word after the first round
101
always@(posedge clk)
102
begin
103
        if(lut_ff_enable)
104
        begin
105
                lut_ff3 <= lut_out;
106
                lut_ff2 <= lut_ff3;
107
                lut_ff1 <= lut_ff2;
108
                lut_ff0 <= lut_ff1;
109
        end
110
end
111
 
112
//FIFO 64x1 Input MUX
113
always@(*)
114
begin
115
        if(data_rdy==2)
116
                shift_in2 = fifo_ff0;
117
        else if(data_rdy==3 && (round_counter<1 || bit_counter>3))
118
                shift_in2 = fifo_ff0;
119
        else if(data_rdy==3 && bit_counter<4 && round_counter>0)
120
                shift_in2 = lut_ff0;
121
        else
122
                shift_in2 = 1'bx;
123
end
124
 
125
//LUT >>3 Input MUX
126
always@(*)
127
begin
128
        if(s2==0)
129
                lut_in3 = fifo_ff3;
130
        else
131
                lut_in3 = lut_ff3;
132
end
133
 
134
//FIFO 60x1 Input MUX
135
always@(*)
136
begin
137
        if(s1==0)
138
                shift_in1 = fifo_ff0;
139
        else if(s1==1)
140
                shift_in1 = data_in;
141
        else if(s1==2)
142
                shift_in1 = lut_out;
143
        else if(s1==3)
144
                shift_in1 = lut_ff0;
145
        else
146
                shift_in1 = 1'bx;
147
end
148
 
149
//S2 MUX
150
always@(*)
151
begin
152
        if(bit_counter==0 && round_counter!=0)
153
                s2 = 1;
154
        else
155
                s2 = 0;
156
end
157
 
158
//S1 MUX
159
always@(*)
160
begin
161
        if(data_rdy==2)
162
                s1 = 1;
163
        else if(data_rdy==3 && bit_counter<4 && round_counter==0)
164
                s1 = 0;
165
        else if(data_rdy==3 && bit_counter<4 && round_counter>0)
166
                s1 = 3;
167
        else
168
                s1 = 2;
169
end
170
 
171
// LUT FF ENABLE MUX
172
// LUT FFs are used only at the first four clock cycles of each round
173
always@(*)
174
begin
175
        if(data_rdy==3 && bit_counter<4)
176
                lut_ff_enable = 1;
177
        else
178
                lut_ff_enable = 0;
179
end
180
 
181
//FIFO FF ENABLE MUX
182
always@(*)
183
begin
184
        if(data_rdy==2 || data_rdy==3)
185
                fifo_ff_enable = 1;
186
        else
187
                fifo_ff_enable = 0;
188
end
189
 
190
//SHIFTER ENABLES
191
// Shifters are enabled when the key is loaded or block cipher is running
192
always@(*)
193
begin
194
        if(data_rdy==2 || data_rdy==3)
195
                shifter_enable1 = 1;
196
        else
197
                shifter_enable1 = 0;
198
 
199
        if(data_rdy==2 || data_rdy==3)
200
                shifter_enable2 = 1;
201
        else
202
                shifter_enable2 = 0;
203
 
204
end
205
 
206
//Round Counter
207
always@(posedge clk)
208
begin
209
        if(data_rdy==3 && bit_counter==63)
210
                round_counter <= round_counter + 1;
211
        else if(data_rdy==0)
212
                round_counter <= 0;
213
        else
214
                round_counter <= round_counter;
215
end
216
 
217
// The necessary bit of the constant Z is selected by the round counter
218
always @(*)
219
begin
220
        if(bit_counter==0)
221
                z_value = Z[round_counter];
222
        else
223
                z_value = 0;
224
end
225
 
226
// The value of c is 1 at the first two cycles of each round only
227
always @(*)
228
begin
229
        if(bit_counter==0 || bit_counter==1)
230
                c = 0;
231
        else
232
                c = 1;
233
end
234
 
235
// New computed key bit
236
assign lut_out = shift_out2 ^ lut_in3 ^ shift_out1 ^ z_value ^ c;
237
 
238
// Output key bit that is connected to the datapath     
239
assign key_out = shift_out2;
240
 
241
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.