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 f_fun is
|
21 |
|
|
port(clk : in std_logic;
|
22 |
|
|
r_in : in std_logic_vector(31 downto 0);
|
23 |
|
|
k_in : in std_logic_vector(47 downto 0);
|
24 |
|
|
r_out : out std_logic_vector(31 downto 0));
|
25 |
|
|
end f_fun;
|
26 |
|
|
|
27 |
|
|
architecture Behavioral of f_fun is
|
28 |
|
|
|
29 |
|
|
component dsp_xor is
|
30 |
|
|
port (clk : in std_logic;
|
31 |
|
|
op_1 : in std_logic_vector(31 downto 0);
|
32 |
|
|
op_2 : in std_logic_vector(31 downto 0);
|
33 |
|
|
op_3 : out std_logic_vector(31 downto 0));
|
34 |
|
|
end component;
|
35 |
|
|
|
36 |
|
|
component dsp_xor_48 is
|
37 |
|
|
port (clk : in std_logic;
|
38 |
|
|
op_1 : in std_logic_vector(47 downto 0);
|
39 |
|
|
op_2 : in std_logic_vector(47 downto 0);
|
40 |
|
|
op_3 : out std_logic_vector(47 downto 0));
|
41 |
|
|
end component;
|
42 |
|
|
|
43 |
|
|
COMPONENT s_box_dram_1
|
44 |
|
|
PORT (
|
45 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
46 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
47 |
|
|
END COMPONENT;
|
48 |
|
|
|
49 |
|
|
COMPONENT s_box_dram_2
|
50 |
|
|
PORT (
|
51 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
52 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
53 |
|
|
END COMPONENT;
|
54 |
|
|
|
55 |
|
|
COMPONENT s_box_dram_3
|
56 |
|
|
PORT (
|
57 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
58 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
59 |
|
|
END COMPONENT;
|
60 |
|
|
|
61 |
|
|
COMPONENT s_box_dram_4
|
62 |
|
|
PORT (
|
63 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
64 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
65 |
|
|
END COMPONENT;
|
66 |
|
|
|
67 |
|
|
COMPONENT s_box_dram_5
|
68 |
|
|
PORT (
|
69 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
70 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
71 |
|
|
END COMPONENT;
|
72 |
|
|
|
73 |
|
|
COMPONENT s_box_dram_6
|
74 |
|
|
PORT (
|
75 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
76 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
77 |
|
|
END COMPONENT;
|
78 |
|
|
|
79 |
|
|
COMPONENT s_box_dram_7
|
80 |
|
|
PORT (
|
81 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
82 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
83 |
|
|
END COMPONENT;
|
84 |
|
|
|
85 |
|
|
COMPONENT s_box_dram_8
|
86 |
|
|
PORT (
|
87 |
|
|
a : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
|
88 |
|
|
spo : OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
|
89 |
|
|
END COMPONENT;
|
90 |
|
|
|
91 |
|
|
signal blk_exp_s : std_logic_vector(47 downto 0);
|
92 |
|
|
signal post_exp_key_add_s : std_logic_vector(47 downto 0);
|
93 |
|
|
|
94 |
|
|
signal post_s_box_s : std_logic_vector(31 downto 0);
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
begin
|
98 |
|
|
|
99 |
|
|
-- E
|
100 |
|
|
|
101 |
|
|
blk_exp_s <= r_in(0) & r_in(31) & r_in(30) & r_in(29) & r_in(28) & r_in(27) &
|
102 |
|
|
r_in(28) & r_in(27) & r_in(26) & r_in(25) & r_in(24) & r_in(23) &
|
103 |
|
|
r_in(24) & r_in(23) & r_in(22) & r_in(21) & r_in(20) & r_in(19) &
|
104 |
|
|
r_in(20) & r_in(19) & r_in(18) & r_in(17) & r_in(16) & r_in(15) &
|
105 |
|
|
r_in(16) & r_in(15) & r_in(14) & r_in(13) & r_in(12) & r_in(11) &
|
106 |
|
|
r_in(12) & r_in(11) & r_in(10) & r_in(9) & r_in(8) & r_in(7) &
|
107 |
|
|
r_in(8) & r_in(7) & r_in(6) & r_in(5) & r_in(4) & r_in(3) &
|
108 |
|
|
r_in(4) & r_in(3) & r_in(2) & r_in(1) & r_in(0) & r_in(31);
|
109 |
|
|
|
110 |
|
|
post_exp_key_add_s <= blk_exp_s xor k_in;
|
111 |
|
|
|
112 |
|
|
S_BOX_0 : s_box_dram_1 port map (post_exp_key_add_s(47 downto 42), post_s_box_s(31 downto 28));
|
113 |
|
|
S_BOX_1 : s_box_dram_2 port map (post_exp_key_add_s(41 downto 36), post_s_box_s(27 downto 24));
|
114 |
|
|
S_BOX_2 : s_box_dram_3 port map (post_exp_key_add_s(35 downto 30), post_s_box_s(23 downto 20));
|
115 |
|
|
S_BOX_3 : s_box_dram_4 port map (post_exp_key_add_s(29 downto 24), post_s_box_s(19 downto 16));
|
116 |
|
|
S_BOX_4 : s_box_dram_5 port map (post_exp_key_add_s(23 downto 18), post_s_box_s(15 downto 12));
|
117 |
|
|
S_BOX_5 : s_box_dram_6 port map (post_exp_key_add_s(17 downto 12), post_s_box_s(11 downto 8));
|
118 |
|
|
S_BOX_6 : s_box_dram_7 port map (post_exp_key_add_s(11 downto 6), post_s_box_s(7 downto 4));
|
119 |
|
|
S_BOX_7 : s_box_dram_8 port map (post_exp_key_add_s(5 downto 0), post_s_box_s(3 downto 0));
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
r_out <= post_s_box_s(16) & post_s_box_s(25) & post_s_box_s(12) & post_s_box_s(11) & post_s_box_s(3) & post_s_box_s(20) & post_s_box_s(4) & post_s_box_s(15) &
|
123 |
|
|
post_s_box_s(31) & post_s_box_s(17) & post_s_box_s(9) & post_s_box_s(6) & post_s_box_s(27) & post_s_box_s(14) & post_s_box_s(1) & post_s_box_s(22) &
|
124 |
|
|
post_s_box_s(30) & post_s_box_s(24) & post_s_box_s(8) & post_s_box_s(18) & post_s_box_s(0) & post_s_box_s(5) & post_s_box_s(29) & post_s_box_s(23) &
|
125 |
|
|
post_s_box_s(13) & post_s_box_s(19) & post_s_box_s(2) & post_s_box_s(26) & post_s_box_s(10) & post_s_box_s(21) & post_s_box_s(28) & post_s_box_s(7);
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
end Behavioral;
|
129 |
|
|
|