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

Subversion Repositories deslxcore

[/] [deslxcore/] [trunk/] [rtl/] [des_loop.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 entactogen
 
2
-- Copyright (c) 2013 Antonio de la Piedra
3
 
4
-- This program is free software: you can redistribute it and/or modify
5
-- it under the terms of the GNU General Public License as published by
6
-- the Free Software Foundation, either version 3 of the License, or
7
-- (at your option) any later version.
8
 
9
-- This program is distributed in the hope that it will be useful,
10
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
-- GNU General Public License for more details.
13
 
14
-- You should have received a copy of the GNU General Public License
15
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
17 2 entactogen
library IEEE;
18
use IEEE.STD_LOGIC_1164.ALL;
19
 
20
entity des_loop is
21
        port(clk :  in std_logic;
22
                  rst : in std_logic;
23
                  mode : in std_logic; -- 0 encrypt, 1 decrypt
24
                  key_in : in std_logic_vector(55 downto 0);
25
                  key_pre_w_in : in std_logic_vector(63 downto 0);
26
                  key_pos_w_in : in std_logic_vector(63 downto 0);
27
                  blk_in : in std_logic_vector(63 downto 0);
28
                  blk_out : out std_logic_vector(63 downto 0));
29
end des_loop;
30
 
31
architecture Behavioral of des_loop is
32
 
33
        signal after_ip_s : std_logic_vector(63 downto 0);
34
        signal after_ip_minus_one_s : std_logic_vector(63 downto 0);
35
        signal after_f_s : std_logic_vector(31 downto 0);
36
        signal final_s : std_logic_vector(63 downto 0);
37
 
38
        component des_round is
39
                port(clk : in std_logic;
40
                          l_0 : in std_logic_vector(31 downto 0);
41
                     r_0 : in std_logic_vector(31 downto 0);
42
                     k_i : in std_logic_vector(47 downto 0);
43
                     l_1 : out std_logic_vector(31 downto 0);
44
                     r_1 : out std_logic_vector(31 downto 0));
45
        end component;
46
 
47
        component key_schedule is
48
                port(clk : in std_logic;
49
                          rst : in std_logic;
50
                     mode : in std_logic; -- 0 encrypt, 1 decrypt
51
                key : in std_logic_vector(55 downto 0);
52
                     key_out : out std_logic_vector(47 downto 0));
53
        end component;
54
 
55
        signal key_s : std_logic_vector(47 downto 0);
56
 
57
        signal l_0_s : std_logic_vector(31 downto 0);
58
        signal l_1_s : std_logic_vector(31 downto 0);
59
        signal r_0_s : std_logic_vector(31 downto 0);
60
        signal r_1_s : std_logic_vector(31 downto 0);
61
 
62
        signal rst_s : std_logic;
63
 
64
        signal blk_in_s  : std_logic_vector(63 downto 0);
65
        signal blk_out_s : std_logic_vector(63 downto 0);
66
 
67
begin
68
 
69
        pr_rst_delay : process(clk, rst)
70
        begin
71
                if rising_edge(clk) then
72
                        rst_s <= rst;
73
                end if;
74
        end process;
75
 
76
        blk_in_s <= (blk_in xor key_pre_w_in) when mode = '0' else (blk_in xor key_pos_w_in);
77
 
78
        pr_seq: process(clk, rst_s, blk_in)
79
        begin
80
                if rst_s = '1' then
81
                        l_0_s <= blk_in_s(63 downto 32);
82
                        r_0_s <= blk_in_s(31 downto 0);
83
                elsif rising_edge(clk) then
84
                        l_0_s <= l_1_s;
85
                        r_0_s <= r_1_s;
86
                end if;
87
        end process;
88
 
89
        DES_ROUND_0 :  des_round port map (clk, l_0_s, r_0_s, key_s, l_1_s, r_1_s);
90
 
91
        blk_out_s <= r_1_s & l_1_s;
92
 
93
        blk_out <= (blk_out_s xor key_pre_w_in) when mode = '1' else (blk_out_s xor key_pos_w_in);
94
 
95
        KEY_SCHEDULE_0 : key_schedule port map (clk, rst, mode, key_in, key_s);
96
 
97
end Behavioral;
98
 

powered by: WebSVN 2.1.0

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