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

Subversion Repositories xteacore

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 entactogen
 
2
 
3
-- Copyright (c) 2013 Antonio de la Piedra
4
 
5
-- This program is free software: you can redistribute it and/or modify
6
-- it under the terms of the GNU General Public License as published by
7
-- the Free Software Foundation, either version 3 of the License, or
8
-- (at your option) any later version.
9
 
10
-- This program is distributed in the hope that it will be useful,
11
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
-- GNU General Public License for more details.
14
 
15
-- You should have received a copy of the GNU General Public License
16
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
library IEEE;
19
use IEEE.STD_LOGIC_1164.ALL;
20
use IEEE.NUMERIC_STD.ALL;
21
 
22
entity key_schedule is
23
            port (clk : in std_logic;
24
                  rst : in std_logic;
25
                  enc : in std_logic; -- (0, enc) (1, dec)
26
                  val : in std_logic_vector(1 downto 0);
27
                  key : in std_logic_vector(127 downto 0);
28
                  subkey : out std_logic_vector(31 downto 0));
29
end key_schedule;
30
 
31
architecture Behavioral of key_schedule is
32
 
33
        type key_t is array (0 to 3) of unsigned(31 downto 0);
34
 
35
        signal k : key_t;
36
        signal sum_s : unsigned(31 downto 0);
37
        signal sum_delay_s : unsigned(31 downto 0);
38
 
39
        signal key_0_s : unsigned(31 downto 0);
40
        signal key_1_s : unsigned(31 downto 0);
41
 
42
        signal delta_s : unsigned(31 downto 0);
43
 
44
begin
45
 
46
        delta_s <= X"9E3779B9";
47
 
48
        k(3) <= unsigned(key(127 downto 96));
49
   k(2) <= unsigned(key(95 downto 64));
50
   k(1) <= unsigned(key(63 downto 32));
51
   k(0) <= unsigned(key(31 downto 0));
52
 
53
        gen_key : process(clk, rst, val, enc, k, sum_s, delta_s)
54
        begin
55
                if rising_edge(clk) then
56
                        if rst = '1' then
57
                                if enc = '1' then
58
                                        sum_s <= X"8dde6e40";
59
                                else
60
                                        sum_s <= (others => '0');
61
                                end if;
62
                                subkey <= (others => '0');
63
                        else
64
                                if val = "00" then
65
                                        if enc = '1' then
66
                                                subkey <= std_logic_vector(sum_s + k(to_integer(("00000000000" & sum_s(31 downto 11)) and x"00000003")));
67
                                                sum_s <= sum_s - delta_s;
68
                                        else
69
                                                subkey <= std_logic_vector(sum_s + k(to_integer(sum_s and x"00000003")));
70
                                                sum_s <= sum_s + delta_s;
71
                                        end if;
72
                                elsif val = "10" then
73
                                        if enc = '1' then
74
                                                subkey <= std_logic_vector(sum_s + k(to_integer(sum_s and x"00000003")));
75
                                        else
76
                                                subkey <= std_logic_vector(sum_s + k(to_integer(("00000000000" & sum_s(31 downto 11)) and x"00000003")));
77
                                        end if;
78
                                end if;
79
                        end if;
80
                end if;
81
        end process;
82
 
83
end Behavioral;
84
 
85
 
86
 

powered by: WebSVN 2.1.0

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