1 |
2 |
arif_endro |
-- ------------------------------------------------------------------------
|
2 |
|
|
-- Copyright (C) 2010 Arif Endro Nugroho
|
3 |
|
|
-- All rights reserved.
|
4 |
|
|
--
|
5 |
|
|
-- Redistribution and use in source and binary forms, with or without
|
6 |
|
|
-- modification, are permitted provided that the following conditions
|
7 |
|
|
-- are met:
|
8 |
|
|
--
|
9 |
|
|
-- 1. Redistributions of source code must retain the above copyright
|
10 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
11 |
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
12 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
13 |
|
|
-- documentation and/or other materials provided with the distribution.
|
14 |
|
|
--
|
15 |
|
|
-- THIS SOFTWARE IS PROVIDED BY ARIF ENDRO NUGROHO "AS IS" AND ANY EXPRESS
|
16 |
|
|
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17 |
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18 |
|
|
-- DISCLAIMED. IN NO EVENT SHALL ARIF ENDRO NUGROHO BE LIABLE FOR ANY
|
19 |
|
|
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20 |
|
|
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
21 |
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
22 |
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
23 |
|
|
-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
24 |
|
|
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
25 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
26 |
|
|
--
|
27 |
|
|
-- End Of License.
|
28 |
|
|
-- ------------------------------------------------------------------------
|
29 |
|
|
|
30 |
|
|
library ieee;
|
31 |
|
|
use ieee.std_logic_1164.all;
|
32 |
|
|
use ieee.std_logic_unsigned.all;
|
33 |
|
|
|
34 |
|
|
entity sboxs1 is
|
35 |
|
|
port (
|
36 |
|
|
w : in bit_vector ( 31 downto 0);
|
37 |
|
|
r : out bit_vector ( 31 downto 0)
|
38 |
|
|
);
|
39 |
|
|
end sboxs1;
|
40 |
|
|
|
41 |
|
|
architecture phy of sboxs1 is
|
42 |
|
|
signal w0 : bit_vector ( 7 downto 0);
|
43 |
|
|
signal w1 : bit_vector ( 7 downto 0);
|
44 |
|
|
signal w2 : bit_vector ( 7 downto 0);
|
45 |
|
|
signal w3 : bit_vector ( 7 downto 0);
|
46 |
|
|
signal r0 : bit_vector ( 7 downto 0);
|
47 |
|
|
signal r1 : bit_vector ( 7 downto 0);
|
48 |
|
|
signal r2 : bit_vector ( 7 downto 0);
|
49 |
|
|
signal r3 : bit_vector ( 7 downto 0);
|
50 |
|
|
signal sr0i : bit_vector ( 7 downto 0);
|
51 |
|
|
signal sr1i : bit_vector ( 7 downto 0);
|
52 |
|
|
signal sr2i : bit_vector ( 7 downto 0);
|
53 |
|
|
signal sr3i : bit_vector ( 7 downto 0);
|
54 |
|
|
signal sr0o : bit_vector ( 7 downto 0);
|
55 |
|
|
signal sr1o : bit_vector ( 7 downto 0);
|
56 |
|
|
signal sr2o : bit_vector ( 7 downto 0);
|
57 |
|
|
signal sr3o : bit_vector ( 7 downto 0);
|
58 |
|
|
signal mlx0vi : bit_vector ( 7 downto 0);
|
59 |
|
|
signal mlx0ci : bit_vector ( 7 downto 0);
|
60 |
|
|
signal mlx0wo : bit_vector ( 7 downto 0);
|
61 |
|
|
signal mlx1vi : bit_vector ( 7 downto 0);
|
62 |
|
|
signal mlx1ci : bit_vector ( 7 downto 0);
|
63 |
|
|
signal mlx1wo : bit_vector ( 7 downto 0);
|
64 |
|
|
signal mlx2vi : bit_vector ( 7 downto 0);
|
65 |
|
|
signal mlx2ci : bit_vector ( 7 downto 0);
|
66 |
|
|
signal mlx2wo : bit_vector ( 7 downto 0);
|
67 |
|
|
signal mlx3vi : bit_vector ( 7 downto 0);
|
68 |
|
|
signal mlx3ci : bit_vector ( 7 downto 0);
|
69 |
|
|
signal mlx3wo : bit_vector ( 7 downto 0);
|
70 |
|
|
component sboxr
|
71 |
|
|
port (
|
72 |
|
|
di : in bit_vector ( 7 downto 0);
|
73 |
|
|
do : out bit_vector ( 7 downto 0)
|
74 |
|
|
);
|
75 |
|
|
end component;
|
76 |
|
|
component mulx
|
77 |
|
|
port (
|
78 |
|
|
V : in bit_vector ( 7 downto 0);
|
79 |
|
|
c : in bit_vector ( 7 downto 0);
|
80 |
|
|
w : out bit_Vector ( 7 downto 0)
|
81 |
|
|
);
|
82 |
|
|
end component;
|
83 |
|
|
begin
|
84 |
|
|
sr0 : sboxr
|
85 |
|
|
port map (
|
86 |
|
|
di => sr0i,
|
87 |
|
|
do => sr0o
|
88 |
|
|
);
|
89 |
|
|
sr1 : sboxr
|
90 |
|
|
port map (
|
91 |
|
|
di => sr1i,
|
92 |
|
|
do => sr1o
|
93 |
|
|
);
|
94 |
|
|
sr2 : sboxr
|
95 |
|
|
port map (
|
96 |
|
|
di => sr2i,
|
97 |
|
|
do => sr2o
|
98 |
|
|
);
|
99 |
|
|
sr3 : sboxr
|
100 |
|
|
port map (
|
101 |
|
|
di => sr3i,
|
102 |
|
|
do => sr3o
|
103 |
|
|
);
|
104 |
|
|
mlx0 : mulx
|
105 |
|
|
port map (
|
106 |
|
|
V => mlx0vi,
|
107 |
|
|
c => mlx0ci,
|
108 |
|
|
w => mlx0wo
|
109 |
|
|
);
|
110 |
|
|
mlx1 : mulx
|
111 |
|
|
port map (
|
112 |
|
|
V => mlx1vi,
|
113 |
|
|
c => mlx1ci,
|
114 |
|
|
w => mlx1wo
|
115 |
|
|
);
|
116 |
|
|
mlx2 : mulx
|
117 |
|
|
port map (
|
118 |
|
|
V => mlx2vi,
|
119 |
|
|
c => mlx2ci,
|
120 |
|
|
w => mlx2wo
|
121 |
|
|
);
|
122 |
|
|
mlx3 : mulx
|
123 |
|
|
port map (
|
124 |
|
|
V => mlx3vi,
|
125 |
|
|
c => mlx3ci,
|
126 |
|
|
w => mlx3wo
|
127 |
|
|
);
|
128 |
|
|
--persistent connection
|
129 |
|
|
w0 <= w ( 31 downto 24);
|
130 |
|
|
w1 <= w ( 23 downto 16);
|
131 |
|
|
w2 <= w ( 15 downto 8);
|
132 |
|
|
w3 <= w ( 7 downto 0);
|
133 |
|
|
sr0i <= w0;
|
134 |
|
|
sr1i <= w1;
|
135 |
|
|
sr2i <= w2;
|
136 |
|
|
sr3i <= w3;
|
137 |
|
|
mlx0vi <= sr0o; --SR(w0)
|
138 |
|
|
mlx1vi <= sr1o; --SR(w1)
|
139 |
|
|
mlx2vi <= sr2o; --SR(w2)
|
140 |
|
|
mlx3vi <= sr3o; --SR(w3)
|
141 |
|
|
mlx0ci <= X"1b";
|
142 |
|
|
mlx1ci <= X"1b";
|
143 |
|
|
mlx2ci <= X"1b";
|
144 |
|
|
mlx3ci <= X"1b";
|
145 |
|
|
r0 <= mlx0wo xor sr1o xor sr2o xor mlx3wo xor sr3o;
|
146 |
|
|
r1 <= mlx0wo xor sr0o xor mlx1wo xor sr2o xor sr3o;
|
147 |
|
|
r2 <= sr0o xor mlx1wo xor sr1o xor mlx2wo xor sr3o;
|
148 |
|
|
r3 <= sr0o xor sr1o xor mlx2wo xor sr2o xor mlx3wo;
|
149 |
|
|
r ( 31 downto 24)<= r0;
|
150 |
|
|
r ( 23 downto 16)<= r1;
|
151 |
|
|
r ( 15 downto 8)<= r2;
|
152 |
|
|
r ( 7 downto 0)<= r3;
|
153 |
|
|
--persistent connection
|
154 |
|
|
end phy;
|