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

Subversion Repositories xteacore

[/] [xteacore/] [trunk/] [rtl/] [xtea.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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
library IEEE;
18
use IEEE.STD_LOGIC_1164.ALL;
19
use IEEE.NUMERIC_STD.ALL;
20
entity xtea is
21
        port(clk : in std_logic;
22
             rst : in std_logic;
23
             enc : in std_logic;
24
             block_in : in std_logic_vector(63 downto 0);
25
             key : in std_logic_vector(127 downto 0);
26
             v_0_out : out std_logic_vector(31 downto 0);
27
             v_1_out : out std_logic_vector(31 downto 0));
28
end xtea;
29
 
30
architecture Behavioral of xtea is
31
 
32
        signal delta_s : unsigned(31 downto 0);
33
 
34
        component round_f is
35
        port(v_in : in std_logic_vector(31 downto 0);
36
                  last_val : in std_logic_vector(31 downto 0);
37
        v_out : out std_logic_vector(31 downto 0));
38
        end component;
39
 
40
        component key_schedule is
41
        port(clk : in std_logic;
42
                  rst : in std_logic;
43
                  enc : in std_logic; -- (0, enc) (1, dec)
44
                  val : in std_logic_vector(1 downto 0);
45
                  key : in std_logic_vector(127 downto 0);
46
                  subkey : out std_logic_vector(31 downto 0));
47
        end component;
48
 
49
        signal subkey_s : std_logic_vector(31 downto 0);
50
        signal cnt_s : unsigned(1 downto 0);
51
 
52
        signal v_0_s, v_1_s : unsigned(31 downto 0);
53
        signal output_s : std_logic_vector(31 downto 0);
54
        signal input_a_s : std_logic_vector(31 downto 0);
55
begin
56
 
57
        KEY_SCHEDULE_0 : key_schedule port map (clk, rst, enc, std_logic_vector(cnt_s), key, subkey_s);
58
 
59
        pr_cnt : process(clk, rst)
60
        begin
61
                if rising_edge(clk) then
62
                        if rst = '1' then
63
                                cnt_s <= (others => '0');
64
                        else
65
                                cnt_s <= cnt_s + 1;
66
                        end if;
67
                end if;
68
        end process;
69
 
70
        ROUND_F_0 : round_f port map (input_a_s, subkey_s, output_s);
71
 
72
        pr_macc : process(clk, rst, enc, block_in, output_s, cnt_s)
73
        begin
74
                if rising_edge(clk) then
75
                        if rst = '1' then
76
                                if enc = '0' then
77
                                        v_1_s <= unsigned(block_in(63 downto 32));
78
                                        v_0_s <= unsigned(block_in(31 downto 0));
79
                                else
80
                                        v_0_s <= unsigned(block_in(63 downto 32));
81
                                        v_1_s <= unsigned(block_in(31 downto 0));
82
                                end if;
83
                        else
84
                                if cnt_s = "00" then -- v_0
85
                                        input_a_s <= std_logic_vector(v_1_s);
86
                                elsif cnt_s = "01" then -- v_0
87
                                        if enc = '0' then
88
                                                v_0_s <= v_0_s + unsigned(output_s);
89
                                        else
90
                                                v_0_s <= v_0_s - unsigned(output_s);
91
                                        end if;
92
                                elsif cnt_s = "10" then -- v_1
93
                                        input_a_s <= std_logic_vector(v_0_s);
94
                                else -- v_1
95
                                        if enc = '0' then
96
                                                v_1_s <= v_1_s + unsigned(output_s);
97
                                        else
98
                                                v_1_s <= v_1_s - unsigned(output_s);
99
                                        end if;
100
                                end if;
101
                        end if;
102
                end if;
103
        end process;
104
 
105
        v_0_out <= std_logic_vector(v_0_s);
106
        v_1_out <= std_logic_vector(v_1_s);
107
 
108
end Behavioral;
109
 

powered by: WebSVN 2.1.0

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