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

Subversion Repositories simon_core

[/] [simon_core/] [codes/] [Simon_bit_serial_datapath_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:    17:21:26 11/13/2013 
7
// Design Name: 
8
// Module Name:    simon_datapath_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
module simon_datapath_shiftreg(clk,data_in,data_rdy,key_in,cipher_out,round_counter,bit_counter);
22
 
23
input clk,data_in,key_in;
24
input [1:0] data_rdy;
25
input round_counter;
26
output cipher_out;
27
output [5:0] bit_counter;
28
 
29
reg [55:0] shifter1;
30
reg [63:0] shifter2;
31
reg shift_in1,shift_in2;
32
wire shift_out1,shift_out2;
33
reg shifter_enable1,shifter_enable2;
34
 
35
reg fifo_ff63,fifo_ff62,fifo_ff61,fifo_ff60,fifo_ff59,fifo_ff58,fifo_ff57,fifo_ff56;
36
reg lut_ff63,lut_ff62,lut_ff61,lut_ff60,lut_ff59,lut_ff58,lut_ff57,lut_ff56;
37
 
38
reg lut_ff_input,fifo_ff_input;
39
reg lut_rol1,lut_rol2,lut_rol8;
40
reg s1,s4,s5,s6,s7;
41
reg [1:0] s3;
42
reg [5:0] bit_counter;
43
wire lut_out;
44
 
45
 
46
 
47
// Shift Register1 FIFO 56x1 Begin
48
// 56x1 Shift register to store the upper word
49
always @(posedge clk)
50
begin
51
        if(shifter_enable1)
52
        begin
53
                shifter1 <= {shift_in1, shifter1[55:1]};
54
        end
55
end
56
 
57
assign shift_out1 = shifter1[0];
58
// Shift Register1 End
59
 
60
// Shift Register2 FIFO 64x1 Begin
61
// 64x1 Shift register to store the lower word
62
always @(posedge clk)
63
begin
64
        if(shifter_enable2)
65
        begin
66
                shifter2 <= {shift_in2, shifter2[63:1]};
67
        end
68
end
69
 
70
assign shift_out2 = shifter2[0];
71
// Shift Register2 End
72
 
73
 
74
// 8 Flip-Flops to store the most significant 8 bits of the upper word at even rounds
75
// Denoted as Shift Register Up (SRU) in Figure 5
76
always@(posedge clk)
77
begin
78
        if(shifter_enable1)
79
        begin
80
                fifo_ff63 <= fifo_ff_input;
81
                fifo_ff62 <= fifo_ff63;
82
                fifo_ff61 <= fifo_ff62;
83
                fifo_ff60 <= fifo_ff61;
84
                fifo_ff59 <= fifo_ff60;
85
                fifo_ff58 <= fifo_ff59;
86
                fifo_ff57 <= fifo_ff58;
87
                fifo_ff56 <= fifo_ff57;
88
        end
89
end
90
 
91
// 8 Flip-Flops to store the most significant 8 bits of the upper word at odd rounds
92
// Denoted as Shift Register Down (SRD) in Figure 5
93
always@(posedge clk)
94
begin
95
        lut_ff63 <= lut_ff_input;
96
        lut_ff62 <= lut_ff63;
97
        lut_ff61 <= lut_ff62;
98
        lut_ff60 <= lut_ff61;
99
        lut_ff59 <= lut_ff60;
100
        lut_ff58 <= lut_ff59;
101
        lut_ff57 <= lut_ff58;
102
        lut_ff56 <= lut_ff57;
103
end
104
 
105
// FIFO 64x1 Input MUX
106
// Input of the lower FIFO is always the output of the upper FIFO
107
always@(*)
108
begin
109
                shift_in2 = shift_out1;
110
end
111
 
112
// FIFO 56x1 Input MUX
113
// Input of the upper FIFO depends on the select line S1
114
always@(*)
115
begin
116
        if(s1==0)
117
                shift_in1 = lut_ff56;
118
        else
119
                shift_in1 = fifo_ff56;
120
end
121
 
122
// FIFO FF Input MUX
123
// The input of FIFO_FF can be the input plaintext, output of 56x1 FIFO or the output of LUT
124
always@(*)
125
begin
126
        if(s3==0)
127
                fifo_ff_input = data_in;
128
        else if(s3==1)
129
                fifo_ff_input = shift_out1;
130
        else if(s3==2)
131
                fifo_ff_input = lut_out;
132
        else
133
                fifo_ff_input = 1'bx; // Debugging
134
end
135
 
136
// LUT FF Input MUX
137
// The input of the LUT_FF is either the output of 56x1 FIFO or the output of LUT
138
always@(*)
139
begin
140
        if(s5==0)
141
                lut_ff_input = shift_out1;
142
        else
143
                lut_ff_input = lut_out;
144
end
145
 
146
// LUT Input MUX
147
always@(*)
148
begin
149
        if(s7==0)
150
                lut_rol1 = fifo_ff63;
151
        else
152
                lut_rol1 = lut_ff63;
153
 
154
        if(s4==0)
155
                lut_rol2 = fifo_ff62;
156
        else
157
                lut_rol2 = lut_ff62;
158
 
159
        if(s6==0)
160
                lut_rol8 = fifo_ff56;
161
        else
162
                lut_rol8 = lut_ff56;
163
end
164
 
165
//Selection MUX
166
always@(*)
167
begin
168
        // For the first 8 bits of each even round OR for all the bits after the first 8 bits in odd rounds OR loading the plaintext  
169
        if((round_counter==0 && bit_counter<8)||(round_counter==1 && bit_counter>7)||(data_rdy==1))
170
                s1 = 1;
171
        else
172
                s1 = 0;
173
 
174
        if(data_rdy==1) // Loading plaintext
175
                s3 = 0;
176
        else if(round_counter==0) // Even rounds
177
                s3 = 1;
178
        else if(round_counter==1) // Odd rounds
179
                s3 = 2;
180
        else
181
                s3 = 1'bx; // For debugging
182
 
183
        if(round_counter==0) // Even rounds
184
                s6 = 0;
185
        else
186
                s6 = 1;
187
 
188
        s4 = s6;
189
        s7 = s6;
190
        s5 = ~s6;
191
end
192
 
193
// SHIFTER ENABLES
194
// Two shift registers are enabled when the plaintext is being loaded (1) or when the block cipher is running (3)
195
always@(*)
196
begin
197
        if(data_rdy==1 || data_rdy==3)
198
        begin
199
                shifter_enable1 = 1;
200
                shifter_enable2 = 1;
201
        end
202
        else
203
        begin
204
                shifter_enable1 = 0;
205
                shifter_enable2 = 0;
206
        end
207
end
208
 
209
// The bit_counter value is incremented in each clock cycle when the block cipher is running
210
always@(posedge clk)
211
begin
212
        if(data_rdy==0)
213
                bit_counter <= 0;
214
        else if(data_rdy==3)
215
                bit_counter <= bit_counter + 1;
216
        else
217
                bit_counter <= bit_counter;
218
end
219
 
220
// The new computed value
221
assign lut_out = (lut_rol1 & lut_rol8) ^ shift_out2 ^ lut_rol2 ^ key_in;
222
 
223
// The global output that gives the ciphertext value
224
assign cipher_out = lut_out;
225
endmodule

powered by: WebSVN 2.1.0

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