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