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

Subversion Repositories desxcore

[/] [desxcore/] [trunk/] [rtl/] [key_schedule.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 key_schedule is
21
        port(clk : in std_logic;
22
                  rst : in std_logic;
23
                  mode : in std_logic; -- 0 encrypt, 1 decrypt
24
             key : in std_logic_vector(63 downto 0);
25
                  key_out : out std_logic_vector(47 downto 0));
26
end key_schedule;
27
 
28
architecture Behavioral of key_schedule is
29
        signal init_key_s : std_logic_vector(55 downto 0);
30
        signal c_0_s : std_logic_vector(27 downto 0);
31
        signal d_0_s : std_logic_vector(27 downto 0);
32
 
33
        signal shift_s : std_logic_vector(15 downto 0);
34
        signal key_pre_s : std_logic_vector(55 downto 0);
35
        signal key_pre_delay_s : std_logic_vector(55 downto 0);
36
 
37
begin
38
 
39
        pr_seq: process(clk, rst, key, shift_s(15), mode)
40
        begin
41
                if rst = '1' then
42
                        c_0_s <=  key(7)   & key (15) & key (23) & key (31) & key (39) & key (47) & key (55) &
43
                                            key (63) & key(6)   & key (14) & key (22) & key (30) & key (38) & key (46) &
44
                                                 key (54) & key (62) & key(5)   & key (13) & key (21) & key (29) & key (37) &
45
                                                 key (45) & key (53) & key (61) & key(4)   & key (12) & key (20) & key (28);
46
 
47
                        d_0_s <=  key (1)  & key (9)  & key (17) & key (25) & key(33)  & key (41) & key (49) &
48
                                       key (57) & key (2)  & key (10) & key (18) & key (26) & key(34)  & key (42) &
49
                                                 key (50) & key (58) & key (3)  & key (11) & key (19) & key (27) & key(35)  &
50
                                                 key (43) & key (51) & key (59) & key (36) & key (44) & key (52) & key (60);
51
                elsif rising_edge(clk) then
52
                        if shift_s(15) = '0' then
53
                                if mode = '0' then
54
                                        c_0_s <= c_0_s(26 downto 0) & c_0_s(27);
55
                                        d_0_s <= d_0_s(26 downto 0) & d_0_s(27);
56
                                else
57
                                        c_0_s <= c_0_s(0) & c_0_s(27 downto 1);
58
                                        d_0_s <= d_0_s(0) & d_0_s(27 downto 1);
59
                                end if;
60
                        else
61
                                if mode = '0' then
62
                                        c_0_s <= c_0_s(25 downto 0) & c_0_s(27 downto 26);
63
                                        d_0_s <= d_0_s(25 downto 0) & d_0_s(27 downto 26);
64
                                else
65
                                        c_0_s <= c_0_s(1 downto 0) & c_0_s(27 downto 2);
66
                                        d_0_s <= d_0_s(1 downto 0) & d_0_s(27 downto 2);
67
                                end if;
68
                        end if;
69
                end if;
70
        end process;
71
 
72
        pr_shr: process(clk, rst, mode)
73
        begin
74
                if rst = '1' then
75
                        if mode = '0' then
76
                                shift_s <= "0011111101111110";
77
                        else
78
                                shift_s <= "0111111011111100";
79
                        end if;
80
                elsif rising_edge(clk) then
81
                        shift_s <= shift_s(14 downto 0) & shift_s(15);
82
                end if;
83
        end process;
84
 
85
        key_pre_s <= c_0_s & d_0_s;
86
 
87
        pr_delay: process(clk, mode, key_pre_s)
88
        begin
89
                if rising_edge(clk) then
90
                        if mode = '1' then
91
                                key_pre_delay_s <= key_pre_s;
92
                        end if;
93
                end if;
94
        end process;
95
 
96
 
97
        key_out <= (key_pre_s (42)  & key_pre_s (39) & key_pre_s (45) & key_pre_s (32) & key_pre_s (55) & key_pre_s (51) & key_pre_s (53) & key_pre_s (28) &
98
                                  key_pre_s (41) & key_pre_s (50)  & key_pre_s (35) & key_pre_s (46) & key_pre_s (33) & key_pre_s (37) & key_pre_s (44) & key_pre_s (52) &
99
                                  key_pre_s (30) & key_pre_s (48) & key_pre_s (40)  & key_pre_s (49) & key_pre_s (29) & key_pre_s (36) & key_pre_s (43) & key_pre_s (54) &
100
                                  key_pre_s (15)  & key_pre_s (4) & key_pre_s (25) & key_pre_s (19) & key_pre_s (9) & key_pre_s (1) & key_pre_s (26) & key_pre_s (16) &
101
                                  key_pre_s (5) & key_pre_s (11)  & key_pre_s (23) & key_pre_s (8) & key_pre_s (12) & key_pre_s (7) & key_pre_s (17) & key_pre_s (0) &
102
                                  key_pre_s (22) & key_pre_s (3) & key_pre_s (10)  & key_pre_s (14) & key_pre_s (6) & key_pre_s (20) & key_pre_s (27) & key_pre_s (24))
103
                                  when mode = '0' else
104
                                  (key_pre_delay_s (42)  & key_pre_delay_s (39) & key_pre_delay_s (45) & key_pre_delay_s (32) & key_pre_delay_s (55) & key_pre_delay_s (51) & key_pre_delay_s (53) & key_pre_delay_s (28) &
105
                                  key_pre_delay_s (41) & key_pre_delay_s (50)  & key_pre_delay_s (35) & key_pre_delay_s (46) & key_pre_delay_s (33) & key_pre_delay_s (37) & key_pre_delay_s (44) & key_pre_delay_s (52) &
106
                                  key_pre_delay_s (30) & key_pre_delay_s (48) & key_pre_delay_s (40)  & key_pre_delay_s (49) & key_pre_delay_s (29) & key_pre_delay_s (36) & key_pre_delay_s (43) & key_pre_delay_s (54) &
107
                                  key_pre_delay_s (15)  & key_pre_delay_s (4) & key_pre_delay_s (25) & key_pre_delay_s (19) & key_pre_delay_s (9) & key_pre_delay_s (1) & key_pre_delay_s (26) & key_pre_delay_s (16) &
108
                                  key_pre_delay_s (5) & key_pre_delay_s (11)  & key_pre_delay_s (23) & key_pre_delay_s (8) & key_pre_delay_s (12) & key_pre_delay_s (7) & key_pre_delay_s (17) & key_pre_delay_s (0) &
109
                                  key_pre_delay_s (22) & key_pre_delay_s (3) & key_pre_delay_s (10)  & key_pre_delay_s (14) & key_pre_delay_s (6) & key_pre_delay_s (20) & key_pre_delay_s (27) & key_pre_delay_s (24));
110
 
111
end Behavioral;
112
 

powered by: WebSVN 2.1.0

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