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

Subversion Repositories des

[/] [des/] [trunk/] [rtl/] [verilog/] [perf_opt/] [des.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 rudi
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  DES                                                        ////
4
////  DES Top Level module                                       ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
/////////////////////////////////////////////////////////////////////
10
////                                                             ////
11
//// Copyright (C) 2001 Rudolf Usselmann                         ////
12
////                    rudi@asics.ws                            ////
13
////                                                             ////
14
//// This source file may be used and distributed without        ////
15
//// restriction provided that this copyright statement is not   ////
16
//// removed from the file and that any derivative work contains ////
17
//// the original copyright notice and the associated disclaimer.////
18
////                                                             ////
19
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
20
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
21
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
22
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
23
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
24
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
25
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
26
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
27
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
28
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
29
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
30
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
31
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
32
////                                                             ////
33
/////////////////////////////////////////////////////////////////////
34
 
35
module des(desOut, desIn, key, decrypt, clk);
36
output  [63:0]   desOut;
37
input   [63:0]   desIn;
38
input   [55:0]   key;
39
input           decrypt;
40
input           clk;
41
 
42
wire    [1:64]  IP, FP;
43
reg     [63:0]   desIn_r;
44
reg     [55:0]   key_r;
45
reg     [63:0]   desOut;
46
reg     [1:32]  L0, L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15;
47
reg     [1:32]  R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15;
48
wire    [1:32]  out0, out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12, out13, out14, out15;
49
wire    [1:48]  K1, K2, K3, K4, K5, K6, K7, K8, K9;
50
wire    [1:48]  K10, K11, K12, K13, K14, K15, K16;
51
 
52
// Register the 56 bit key
53
always @(posedge clk)
54
        key_r <= #1 key;
55
 
56
// Register the 64 bit input
57
always @(posedge clk)
58
        desIn_r <= #1 desIn;
59
 
60
// XOR 32 bit out15 with 32 bit L14         ( FP  1:32 )
61
//    then concatinate the 32 bit R14 value ( FP 33:64 )
62
//       This value ( FP 1:64 ) is then registered by the desOut[63:0] register 
63
assign FP = { (out15 ^ L14), R14};
64
 
65
// Key schedule provides a linear means of intermixing the 56 bit key to form a
66
//   different 48 bit key for each of the 16 bit rounds
67
key_sel uk(
68
        .clk(           clk             ),
69
        .K(             key_r           ),
70
        .decrypt(       decrypt         ),
71
        .K1(            K1              ),
72
        .K2(            K2              ),
73
        .K3(            K3              ),
74
        .K4(            K4              ),
75
        .K5(            K5              ),
76
        .K6(            K6              ),
77
        .K7(            K7              ),
78
        .K8(            K8              ),
79
        .K9(            K9              ),
80
        .K10(           K10             ),
81
        .K11(           K11             ),
82
        .K12(           K12             ),
83
        .K13(           K13             ),
84
        .K14(           K14             ),
85
        .K15(           K15             ),
86
        .K16(           K16             )
87
        );
88
 
89
// 16 CRP blocks 
90
crp u0( .P(out0), .R(IP[33:64]), .K_sub(K1) );
91
crp u1( .P(out1), .R(R0), .K_sub(K2) );
92
crp u2( .P(out2), .R(R1), .K_sub(K3) );
93
crp u3( .P(out3), .R(R2), .K_sub(K4) );
94
crp u4( .P(out4), .R(R3), .K_sub(K5) );
95
crp u5( .P(out5), .R(R4), .K_sub(K6) );
96
crp u6( .P(out6), .R(R5), .K_sub(K7) );
97
crp u7( .P(out7), .R(R6), .K_sub(K8) );
98
crp u8( .P(out8), .R(R7), .K_sub(K9) );
99
crp u9( .P(out9), .R(R8), .K_sub(K10) );
100
crp u10( .P(out10), .R(R9), .K_sub(K11) );
101
crp u11( .P(out11), .R(R10), .K_sub(K12) );
102
crp u12( .P(out12), .R(R11), .K_sub(K13) );
103
crp u13( .P(out13), .R(R12), .K_sub(K14) );
104
crp u14( .P(out14), .R(R13), .K_sub(K15) );
105
crp u15( .P(out15), .R(R14), .K_sub(K16) );
106
 
107
// 32 bit L0 get upper 32 bits of IP
108
always @(posedge clk)
109
        L0 <= #1 IP[33:64];
110
 
111
// 32 bit R0 gets lower 32 bits of IP XOR'd with 32 bit out0
112
always @(posedge clk)
113
        R0 <= #1  IP[01:32] ^ out0;
114
 
115
// 32 bit L1 gets 32 bit R0
116
always @(posedge clk)
117
        L1 <= #1 R0;
118
 
119
// 32 bit R1 gets 32 bit L0 XOR'd with 32 bit out1
120
always @(posedge clk)
121
        R1 <= #1 L0 ^ out1;
122
 
123
// 32 bit L2 gets 32 bit R1
124
always @(posedge clk)
125
        L2 <= #1 R1;
126
 
127
// 32 bit R2 gets 32 bit L1 XOR'd with 32 bit out2
128
always @(posedge clk)
129
        R2 <= #1 L1 ^ out2;
130
 
131
always @(posedge clk)
132
        L3 <= #1 R2;
133
 
134
always @(posedge clk)
135
        R3 <= #1 L2 ^ out3;
136
 
137
always @(posedge clk)
138
        L4 <= #1 R3;
139
 
140
always @(posedge clk)
141
        R4 <= #1 L3 ^ out4;
142
 
143
always @(posedge clk)
144
        L5 <= #1 R4;
145
 
146
always @(posedge clk)
147
        R5 <= #1 L4 ^ out5;
148
 
149
always @(posedge clk)
150
        L6 <= #1 R5;
151
 
152
always @(posedge clk)
153
        R6 <= #1 L5 ^ out6;
154
 
155
always @(posedge clk)
156
        L7 <= #1 R6;
157
 
158
always @(posedge clk)
159
        R7 <= #1 L6 ^ out7;
160
 
161
always @(posedge clk)
162
        L8 <= #1 R7;
163
 
164
always @(posedge clk)
165
        R8 <= #1 L7 ^ out8;
166
 
167
always @(posedge clk)
168
        L9 <= #1 R8;
169
 
170
always @(posedge clk)
171
        R9 <= #1 L8 ^ out9;
172
 
173
always @(posedge clk)
174
        L10 <= #1 R9;
175
 
176
always @(posedge clk)
177
        R10 <= #1 L9 ^ out10;
178
 
179
always @(posedge clk)
180
        L11 <= #1 R10;
181
 
182
always @(posedge clk)
183
        R11 <= #1 L10 ^ out11;
184
 
185
always @(posedge clk)
186
        L12 <= #1 R11;
187
 
188
always @(posedge clk)
189
        R12 <= #1 L11 ^ out12;
190
 
191
always @(posedge clk)
192
        L13 <= #1 R12;
193
 
194
always @(posedge clk)
195
        R13 <= #1 L12 ^ out13;
196
 
197
always @(posedge clk)
198
        L14 <= #1 R13;
199
 
200
always @(posedge clk)
201
        R14 <= #1 L13 ^ out14;
202
 
203
// 32 bit L15 gets 32 bit R14
204
always @(posedge clk)
205
        L15 <= #1 R14;
206
 
207
// 32 bit R15 gets 32 bit L14 XOR'd with 32 bit out15
208
always @(posedge clk)
209
        R15 <= #1 L14 ^ out15;
210
 
211
// Perform the initial permutationi with the registerd desIn
212
assign IP[1:64] = {     desIn_r[06], desIn_r[14], desIn_r[22], desIn_r[30], desIn_r[38], desIn_r[46],
213
                        desIn_r[54], desIn_r[62], desIn_r[04], desIn_r[12], desIn_r[20], desIn_r[28],
214
                        desIn_r[36], desIn_r[44], desIn_r[52], desIn_r[60], desIn_r[02], desIn_r[10],
215
                        desIn_r[18], desIn_r[26], desIn_r[34], desIn_r[42], desIn_r[50], desIn_r[58],
216
                        desIn_r[00], desIn_r[08], desIn_r[16], desIn_r[24], desIn_r[32], desIn_r[40],
217
                        desIn_r[48], desIn_r[56], desIn_r[07], desIn_r[15], desIn_r[23], desIn_r[31],
218
                        desIn_r[39], desIn_r[47], desIn_r[55], desIn_r[63], desIn_r[05], desIn_r[13],
219
                        desIn_r[21], desIn_r[29], desIn_r[37], desIn_r[45], desIn_r[53], desIn_r[61],
220
                        desIn_r[03], desIn_r[11], desIn_r[19], desIn_r[27], desIn_r[35], desIn_r[43],
221
                        desIn_r[51], desIn_r[59], desIn_r[01], desIn_r[09], desIn_r[17], desIn_r[25],
222
                        desIn_r[33], desIn_r[41], desIn_r[49], desIn_r[57] };
223
 
224
// Perform the final permutation
225
always @(posedge clk)
226
        desOut <= #1 {  FP[40], FP[08], FP[48], FP[16], FP[56], FP[24], FP[64], FP[32],
227
                        FP[39], FP[07], FP[47], FP[15], FP[55], FP[23], FP[63], FP[31],
228
                        FP[38], FP[06], FP[46], FP[14], FP[54], FP[22], FP[62], FP[30],
229
                        FP[37], FP[05], FP[45], FP[13], FP[53], FP[21], FP[61], FP[29],
230
                        FP[36], FP[04], FP[44], FP[12], FP[52], FP[20], FP[60], FP[28],
231
                        FP[35], FP[03], FP[43], FP[11], FP[51], FP[19], FP[59], FP[27],
232
                        FP[34], FP[02], FP[42], FP[10], FP[50], FP[18], FP[58], FP[26],
233
                        FP[33], FP[01], FP[41], FP[09], FP[49], FP[17], FP[57], FP[25] };
234
 
235
 
236
endmodule

powered by: WebSVN 2.1.0

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