OpenCores
URL https://opencores.org/ocsvn/3des_vhdl/3des_vhdl/trunk

Subversion Repositories 3des_vhdl

[/] [3des_vhdl/] [trunk/] [VHDL/] [tdes_top.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dsocek
---------------------------------------------------------------------
2
--                              (c) Copyright 2006, CoreTex Systems, LLC                                         --
3
--                                 www.coretexsys.com                        --    
4
--                                                                       --
5
--              This source file may be used and distributed without         --
6
--              restriction provided that this copyright statement is not    --
7
--              removed from the file and that any derivative work contains  --
8
--              the original copyright notice and the associated disclaimer. --
9
--                                                                       --
10
--                  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY      --
11
--              EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED    --
12
--              TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    --
13
--              FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR       --
14
--              OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          --
15
--              INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES     --
16
--              (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE    --
17
--              GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR         --
18
--              BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
19
--              LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT   --
20
--              (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT   --
21
--              OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          --
22
--              POSSIBILITY OF SUCH DAMAGE.                                  --
23
--                                                                                                                                                                               --
24
---------------------------------------------------------------------
25
 
26
----------------------------------------------------------------------
27
 
28
-- Poject structure: 
29
 
30
--  |- tdes_top.vhd
31
--  |
32
--    |- des_cipher_top.vhd
33
--    |- des_top.vhd
34
--      |- block_top.vhd
35
--        |- add_key.vhd
36
--        |
37
--        |- add_left.vhd
38
--        |
39
--                              |- e_expansion_function.vhd
40
--                              |
41
--                              |- p_box.vhd
42
--                              |
43
--                              |- s_box.vhd
44
--            |- s1_box.vhd
45
--            |- s2_box.vhd
46
--            |- s3_box.vhd
47
--            |- s4_box.vhd
48
--            |- s5_box.vhd
49
--            |- s6_box.vhd
50
--            |- s7_box.vhd
51
--            |- s8_box.vhd
52
--    |- key_schedule.vhd
53
 
54
----------------------------------------------------------------------
55
----------------------------------------------------------------------
56
--
57
-- Title       : tdes_top
58
-- Company     : CoreTex Systems, LLC
59
--
60
----------------------------------------------------------------------
61
 
62
library IEEE;
63
use IEEE.STD_LOGIC_1164.ALL;
64
use IEEE.STD_LOGIC_ARITH.ALL;
65
use IEEE.STD_LOGIC_UNSIGNED.ALL;
66
 
67
entity tdes_top is
68
port(
69
                --
70
                -- inputs for key expander
71
                --
72
                key1_in:                in std_logic_vector(0 to 63);
73
                key2_in:                in std_logic_vector(0 to 63);
74
                key3_in:                in std_logic_vector(0 to 63);
75
 
76
                -- 
77
                -- function     select
78
                --
79
                function_select:        in      std_logic; -- active when encryption, inactive when decryption
80
 
81
                --
82
                -- input into des_cipher_top 
83
                --              
84
                data_in:                in std_logic_vector(0 to 63);
85
 
86
                --
87
                -- input into des_cipher_top 
88
                --              
89
                data_out:       out std_logic_vector(0 to 63);
90
 
91
                --
92
                -- data interface to MCU
93
                --
94
                lddata:                 in      std_logic;      -- active when data for loading is ready
95
                ldkey:                  in      std_logic;      -- active when key for loading is ready
96
                out_ready:      out     std_logic;      -- active when encryption of data is done       
97
 
98
                --
99
                -- General clock and reset
100
                --
101
                reset: in std_logic;
102
                clock: in std_logic
103
        );
104
end tdes_top;
105
 
106
architecture Behavioral of tdes_top is
107
 
108
component des_cipher_top is
109
port(
110
                --
111
                -- inputs for key expander
112
                --
113
                key_in:         in std_logic_vector(0 to 63);    -- interface to MCU
114
                --ldkey:                in std_logic;                                           -- active signal for loading keys
115
 
116
                -- 
117
                -- function     select
118
                --
119
                function_select:        in      std_logic; -- active when encryption, inactive when decryption
120
 
121
                --
122
                -- input into des_cipher_top 
123
                --              
124
                data_in:                in std_logic_vector(0 to 63);
125
 
126
                --
127
                -- input into des_cipher_top 
128
                --              
129
                data_out:       out std_logic_vector(0 to 63);
130
 
131
                --
132
                -- data interface to MCU
133
                --
134
                lddata:                 in      std_logic;      -- active when data for loading is ready
135
                des_out_rdy:    out     std_logic;      -- active when encryption of data is done       
136
 
137
                --
138
                -- General clock and reset
139
                --
140
                reset: in std_logic;
141
                clock: in std_logic
142
        );
143
end component;
144
 
145
type statetype is (WaitKeyState, WaitDataState);
146
signal nextstate: statetype;
147
signal key1_in_internal: std_logic_vector(0 to 63);
148
signal key2_in_internal: std_logic_vector(0 to 63);
149
signal key3_in_internal: std_logic_vector(0 to 63);
150
signal memkey1: std_logic_vector(0 to 63);
151
signal memkey3: std_logic_vector(0 to 63);
152
signal fsel_internal: std_logic;
153
signal fsel_internal_inv: std_logic;
154
signal des_out_rdy_internal: std_logic;
155
signal des_out_rdy_internal1: std_logic;
156
signal des_out_rdy_internal2: std_logic;
157
signal data_in_internal: std_logic_vector(0 to 63);
158
signal data_out_internal: std_logic_vector(0 to 63);
159
signal data_out_internal1: std_logic_vector(0 to 63);
160
signal data_out_internal2: std_logic_vector(0 to 63);
161
signal lddata_internal: std_logic;
162
 
163
begin
164
 
165
process (clock)
166
begin
167
if rising_edge(clock) then
168
        if reset = '1' then
169
                nextstate               <= WaitKeyState;
170
                lddata_internal         <= '0';
171
                out_ready               <= '0';
172
                fsel_internal           <= function_select;
173
                fsel_internal_inv       <= not function_select;
174
        else
175
                data_out                                <= data_out_internal;
176
                out_ready                               <= des_out_rdy_internal;
177
 
178
                case nextstate is
179
                        --
180
                        -- wait key state
181
                        --
182
                        when WaitKeyState =>
183
                                -- wait until key is ready (as well as the function_select)
184
                                if ldkey = '0' then
185
                                        nextstate               <= WaitKeyState;
186
                                else
187
                                        key1_in_internal        <= key1_in;
188
                                        key2_in_internal        <= key2_in;
189
                                        key3_in_internal        <= key3_in;
190
                                        memkey1                 <= key1_in;
191
                                        memkey3                 <= key3_in;
192
                                        nextstate               <= WaitDataState;
193
                                end if;
194
                        --
195
                        -- wait data state
196
                        --
197
                        when WaitDataState =>
198
                                -- wait until data is ready to be loaded
199
                                if lddata = '0' then
200
                                        nextstate       <= WaitDataState;
201
                                        lddata_internal         <= '0';
202
                                else
203
                                        lddata_internal         <= '1';
204
                                        if fsel_internal = '0' then
205
                                                key1_in_internal <= memkey3;
206
                                                key3_in_internal <= memkey1;
207
                                        end if;
208
                                        data_in_internal        <= data_in;
209
                                        nextstate               <= WaitDataState;
210
                                end if;
211
 
212
                end case;
213
        end if;
214
end if;
215
end process;
216
 
217
 
218
DESCIPHERTOP1: des_cipher_top
219
port map (
220
                key_in => key1_in_internal, -- interface to MCU
221
 
222
                function_select => fsel_internal, -- active when encryption, inactive when decryption
223
 
224
                data_in => data_in_internal,
225
 
226
                data_out => data_out_internal1,
227
 
228
                lddata => lddata_internal,      -- active when data for loading is ready
229
                des_out_rdy => des_out_rdy_internal1,   -- active when encryption of data is done       
230
 
231
                reset => reset,
232
                clock =>        clock
233
);
234
 
235
DESCIPHERTOP2: des_cipher_top
236
port map (
237
                key_in => key2_in_internal, --subkey_in_internal,       -- interface to MCU
238
 
239
                function_select => fsel_internal_inv, -- active when encryption, inactive when decryption
240
 
241
                data_in => data_out_internal1,
242
 
243
                data_out => data_out_internal2,
244
 
245
                lddata => des_out_rdy_internal1,        -- active when data for loading is ready
246
                des_out_rdy => des_out_rdy_internal2,   -- active when encryption of data is done       
247
 
248
                reset => reset,
249
                clock =>        clock
250
);
251
 
252
DESCIPHERTOP3: des_cipher_top
253
port map (
254
                key_in => key3_in_internal, -- subkey_in_internal,      -- interface to MCU
255
 
256
                function_select => fsel_internal, -- active when encryption, inactive when decryption
257
 
258
                data_in => data_out_internal2,
259
 
260
                data_out => data_out_internal,
261
 
262
                lddata => des_out_rdy_internal2,        -- active when data for loading is ready
263
                des_out_rdy => des_out_rdy_internal,    -- active when encryption of data is done       
264
 
265
                reset => reset,
266
                clock =>        clock
267
);
268
 
269
end Behavioral;

powered by: WebSVN 2.1.0

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