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

Subversion Repositories desxcore

[/] [desxcore/] [trunk/] [rtl/] [des_loop.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 entactogen
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    09:30:59 02/20/2013 
6
-- Design Name: 
7
-- Module Name:    des - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
 
23
-- Uncomment the following library declaration if using
24
-- arithmetic functions with Signed or Unsigned values
25
--use IEEE.NUMERIC_STD.ALL;
26
 
27
-- Uncomment the following library declaration if instantiating
28
-- any Xilinx primitives in this code.
29
--library UNISIM;
30
--use UNISIM.VComponents.all;
31
 
32
entity des_loop is
33
        port(clk :  in std_logic;
34
                  rst : in std_logic;
35
                  mode : in std_logic; -- 0 encrypt, 1 decrypt
36
                  key_in : in std_logic_vector(63 downto 0);
37
                  key_pre_w_in : in std_logic_vector(63 downto 0);
38
                  key_pos_w_in : in std_logic_vector(63 downto 0);
39
                  blk_in : in std_logic_vector(63 downto 0);
40
                  blk_out : out std_logic_vector(63 downto 0));
41
end des_loop;
42
 
43
architecture Behavioral of des_loop is
44
 
45
        signal after_ip_s : std_logic_vector(63 downto 0);
46
        signal after_ip_minus_one_s : std_logic_vector(63 downto 0);
47
        signal after_f_s : std_logic_vector(31 downto 0);
48
        signal final_s : std_logic_vector(63 downto 0);
49
 
50
        component des_round is
51
                port(clk : in std_logic;
52
                          l_0 : in std_logic_vector(31 downto 0);
53
                     r_0 : in std_logic_vector(31 downto 0);
54
                     k_i : in std_logic_vector(47 downto 0);
55
                     l_1 : out std_logic_vector(31 downto 0);
56
                     r_1 : out std_logic_vector(31 downto 0));
57
        end component;
58
 
59
        component key_schedule is
60
                port(clk : in std_logic;
61
                          rst : in std_logic;
62
                     mode : in std_logic; -- 0 encrypt, 1 decrypt
63
                key : in std_logic_vector(63 downto 0);
64
                     key_out : out std_logic_vector(47 downto 0));
65
        end component;
66
 
67
        signal key_s : std_logic_vector(47 downto 0);
68
 
69
        signal l_0_s : std_logic_vector(31 downto 0);
70
        signal l_1_s : std_logic_vector(31 downto 0);
71
        signal l_2_s : std_logic_vector(31 downto 0);
72
        signal l_3_s : std_logic_vector(31 downto 0);
73
        signal l_4_s : std_logic_vector(31 downto 0);
74
        signal l_5_s : std_logic_vector(31 downto 0);
75
        signal l_6_s : std_logic_vector(31 downto 0);
76
        signal l_7_s : std_logic_vector(31 downto 0);
77
        signal l_8_s : std_logic_vector(31 downto 0);
78
        signal l_9_s : std_logic_vector(31 downto 0);
79
        signal l_10_s : std_logic_vector(31 downto 0);
80
        signal l_11_s : std_logic_vector(31 downto 0);
81
        signal l_12_s : std_logic_vector(31 downto 0);
82
        signal l_13_s : std_logic_vector(31 downto 0);
83
        signal l_14_s : std_logic_vector(31 downto 0);
84
        signal l_15_s : std_logic_vector(31 downto 0);
85
        signal l_16_s : std_logic_vector(31 downto 0);
86
 
87
        signal r_0_s : std_logic_vector(31 downto 0);
88
        signal r_1_s : std_logic_vector(31 downto 0);
89
        signal r_2_s : std_logic_vector(31 downto 0);
90
        signal r_3_s : std_logic_vector(31 downto 0);
91
        signal r_4_s : std_logic_vector(31 downto 0);
92
        signal r_5_s : std_logic_vector(31 downto 0);
93
        signal r_6_s : std_logic_vector(31 downto 0);
94
        signal r_7_s : std_logic_vector(31 downto 0);
95
        signal r_8_s : std_logic_vector(31 downto 0);
96
        signal r_9_s : std_logic_vector(31 downto 0);
97
        signal r_10_s : std_logic_vector(31 downto 0);
98
        signal r_11_s : std_logic_vector(31 downto 0);
99
        signal r_12_s : std_logic_vector(31 downto 0);
100
        signal r_13_s : std_logic_vector(31 downto 0);
101
        signal r_14_s : std_logic_vector(31 downto 0);
102
        signal r_15_s : std_logic_vector(31 downto 0);
103
        signal r_16_s : std_logic_vector(31 downto 0);
104
 
105
        signal k_0_s : std_logic_vector(47 downto 0);
106
        signal k_1_s : std_logic_vector(47 downto 0);
107
        signal k_2_s : std_logic_vector(47 downto 0);
108
        signal k_3_s : std_logic_vector(47 downto 0);
109
        signal k_4_s : std_logic_vector(47 downto 0);
110
        signal k_5_s : std_logic_vector(47 downto 0);
111
        signal k_6_s : std_logic_vector(47 downto 0);
112
        signal k_7_s : std_logic_vector(47 downto 0);
113
        signal k_8_s : std_logic_vector(47 downto 0);
114
        signal k_9_s : std_logic_vector(47 downto 0);
115
        signal k_10_s : std_logic_vector(47 downto 0);
116
        signal k_11_s : std_logic_vector(47 downto 0);
117
        signal k_12_s : std_logic_vector(47 downto 0);
118
        signal k_13_s : std_logic_vector(47 downto 0);
119
        signal k_14_s : std_logic_vector(47 downto 0);
120
        signal k_15_s : std_logic_vector(47 downto 0);
121
 
122
        signal rst_s : std_logic;
123
 
124
        signal blk_in_s : std_logic_vector(63 downto 0);
125
        signal blk_out_s : std_logic_vector(63 downto 0);
126
 
127
begin
128
 
129
        pr_rst_delay : process(clk, rst)
130
        begin
131
                if rising_edge(clk) then
132
                        rst_s <= rst;
133
                end if;
134
        end process;
135
 
136
        -- IP
137
 
138
        blk_in_s <= (blk_in xor key_pre_w_in) when mode = '0' else (blk_in xor key_pos_w_in);
139
 
140
        pr_seq: process(clk, rst_s, blk_in_s)
141
        begin
142
                if rst_s = '1' then
143
                        l_0_s <= blk_in_s(6) & blk_in_s(14) & blk_in_s(22) & blk_in_s(30) & blk_in_s(38) & blk_in_s(46) & blk_in_s(54)  & blk_in_s(62) &
144
                                                          blk_in_s(4) & blk_in_s(12) & blk_in_s(20) & blk_in_s(28) & blk_in_s(36) & blk_in_s(44) & blk_in_s(52)  & blk_in_s(60) &
145
                                                          blk_in_s(2) & blk_in_s(10) & blk_in_s(18) & blk_in_s(26) & blk_in_s(34) & blk_in_s(42) & blk_in_s(50)  & blk_in_s(58) &
146
                                                          blk_in_s(0) & blk_in_s(8)  & blk_in_s(16) & blk_in_s(24) & blk_in_s(32) & blk_in_s(40) & blk_in_s(48)  & blk_in_s(56);
147
 
148
                        r_0_s <= blk_in_s(7) & blk_in_s(15) & blk_in_s(23) & blk_in_s(31) & blk_in_s(39) & blk_in_s(47) & blk_in_s(55)  & blk_in_s(63) &
149
                                                          blk_in_s(5) & blk_in_s(13) & blk_in_s(21) & blk_in_s(29) & blk_in_s(37) & blk_in_s(45) & blk_in_s(53)  & blk_in_s(61) &
150
                                                          blk_in_s(3) & blk_in_s(11) & blk_in_s(19) & blk_in_s(27) & blk_in_s(35) & blk_in_s(43) & blk_in_s(51)  & blk_in_s(59) &
151
                                                          blk_in_s(1) & blk_in_s(9)  & blk_in_s(17) & blk_in_s(25) & blk_in_s(33) & blk_in_s(41) & blk_in_s(49)  & blk_in_s(57);
152
                elsif rising_edge(clk) then
153
                        l_0_s <= l_1_s;
154
                        r_0_s <= r_1_s;
155
                end if;
156
        end process;
157
 
158
        DES_ROUND_0 :  des_round port map (clk, l_0_s, r_0_s, k_0_s, l_1_s, r_1_s);
159
 
160
        final_s <= r_1_s & l_1_s;
161
 
162
        blk_out_s  <= final_s(24) & final_s(56) & final_s(16) & final_s(48) & final_s(8) & final_s(40) & final_s(0)  & final_s(32) &
163
                                          final_s(25) & final_s(57) & final_s(17) & final_s(49) & final_s(9) & final_s(41) & final_s(1) & final_s(33) &
164
                                          final_s(26) & final_s(58) & final_s(18) & final_s(50) & final_s(10) & final_s(42) & final_s(2) & final_s(34) &
165
                                          final_s(27) & final_s(59) & final_s(19) & final_s(51) & final_s(11) & final_s(43) & final_s(3) & final_s(35) &
166
                                          final_s(28) & final_s(60) & final_s(20) & final_s(52) & final_s(12) & final_s(44) & final_s(4)  & final_s(36) &
167
                                          final_s(29) & final_s(61) & final_s(21) & final_s(53) & final_s(13) & final_s(45) & final_s(5) & final_s(37) &
168
                                          final_s(30) & final_s(62) & final_s(22) & final_s(54) & final_s(14) & final_s(46) & final_s(6) & final_s(38) &
169
                                          final_s(31) & final_s(63) & final_s(23) & final_s(55) & final_s(15) & final_s(47) & final_s(7) & final_s(39);
170
 
171
        blk_out <= (blk_out_s xor key_pos_w_in) when mode = '0' else (blk_out_s xor key_pre_w_in);
172
 
173
 
174
        KEY_SCHEDULE_0 : key_schedule port map (clk, rst, mode, key_in, k_0_s);
175
 
176
end Behavioral;
177
 

powered by: WebSVN 2.1.0

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