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 sbox is
|
35 |
|
|
port (
|
36 |
|
|
x7 : in bit_vector ( 6 downto 0);
|
37 |
|
|
x9 : in bit_vector ( 8 downto 0);
|
38 |
|
|
y7 : out bit_vector ( 6 downto 0);
|
39 |
|
|
y9 : out bit_vector ( 8 downto 0)
|
40 |
|
|
);
|
41 |
|
|
end sbox;
|
42 |
|
|
|
43 |
|
|
architecture phy of sbox is
|
44 |
|
|
begin
|
45 |
|
|
--S7
|
46 |
|
|
y7(0) <= (x7(1) and x7(3)) xor x7(4) xor (x7(0) and x7(1) and x7(4)) xor x7(5) xor
|
47 |
|
|
(x7(2) and x7(5)) xor
|
48 |
|
|
(x7(3) and x7(4) and x7(5)) xor x7(6) xor (x7(0) and x7(6)) xor (x7(1) and x7(6)) xor
|
49 |
|
|
(x7(3) and x7(6)) xor (x7(2) and x7(4) and x7(6)) xor (x7(1) and x7(5) and x7(6)) xor (x7(4) and x7(5) and x7(6));
|
50 |
|
|
y7(1) <= (x7(0) and x7(1)) xor (x7(0) and x7(4)) xor (x7(2) and x7(4)) xor x7(5) xor
|
51 |
|
|
(x7(1) and x7(2) and x7(5)) xor (x7(0) and x7(3) and x7(5)) xor x7(6) xor (x7(0) and x7(2) and x7(6)) xor
|
52 |
|
|
(x7(3) and x7(6)) xor (x7(4) and x7(5) and x7(6)) xor '1';
|
53 |
|
|
y7(2) <= x7(0) xor (x7(0) and x7(3)) xor (x7(2) and x7(3)) xor (x7(1) and x7(2) and x7(4)) xor
|
54 |
|
|
(x7(0) and x7(3) and x7(4)) xor (x7(1) and x7(5)) xor (x7(0) and x7(2) and x7(5)) xor (x7(0) and x7(6)) xor
|
55 |
|
|
(x7(0) and x7(1) and x7(6)) xor (x7(2) and x7(6)) xor (x7(4) and x7(6)) xor '1';
|
56 |
|
|
y7(3) <= x7(1) xor (x7(0) and x7(1) and x7(2)) xor (x7(1) and x7(4)) xor
|
57 |
|
|
(x7(3) and x7(4)) xor (x7(0) and x7(5)) xor (x7(0) and x7(1) and x7(5)) xor (x7(2) and x7(3) and x7(5)) xor
|
58 |
|
|
(x7(1) and x7(4) and x7(5)) xor (x7(2) and x7(6)) xor (x7(1) and x7(3) and x7(6));
|
59 |
|
|
y7(4) <= (x7(0) and x7(2)) xor x7(3) xor (x7(1) and x7(3)) xor (x7(1) and x7(4)) xor
|
60 |
|
|
(x7(0) and x7(1) and x7(4)) xor (x7(2) and x7(3) and x7(4)) xor (x7(0) and x7(5)) xor (x7(1) and x7(3) and x7(5)) xor
|
61 |
|
|
(x7(0) and x7(4) and x7(5)) xor (x7(1) and x7(6)) xor (x7(3) and x7(6)) xor (x7(0) and x7(3) and x7(6)) xor
|
62 |
|
|
(x7(5) and x7(6)) xor '1';
|
63 |
|
|
y7(5) <= x7(2) xor (x7(0) and x7(2)) xor (x7(0) and x7(3)) xor (x7(1) and x7(2) and x7(3)) xor
|
64 |
|
|
(x7(0) and x7(2) and x7(4)) xor (x7(0) and x7(5)) xor (x7(2) and x7(5)) xor (x7(4) and x7(5)) xor
|
65 |
|
|
(x7(1) and x7(6)) xor (x7(1) and x7(2) and x7(6)) xor (x7(0) and x7(3) and x7(6)) xor (x7(3) and x7(4) and x7(6)) xor
|
66 |
|
|
(x7(2) and x7(5) and x7(6)) xor '1';
|
67 |
|
|
y7(6) <= (x7(1) and x7(2)) xor (x7(0) and x7(1) and x7(3)) xor (x7(0) and x7(4)) xor (x7(1) and x7(5)) xor
|
68 |
|
|
(x7(3) and x7(5)) xor x7(6) xor (x7(0) and x7(1) and x7(6)) xor (x7(2) and x7(3) and x7(6)) xor
|
69 |
|
|
(x7(1) and x7(4) and x7(6)) xor (x7(0) and x7(5) and x7(6));
|
70 |
|
|
--S7
|
71 |
|
|
--S9
|
72 |
|
|
y9(0) <= (x9(0) and x9(2)) xor x9(3) xor (x9(2) and x9(5)) xor (x9(5) and x9(6)) xor
|
73 |
|
|
(x9(0) and x9(7)) xor (x9(1) and x9(7)) xor (x9(2) and x9(7)) xor (x9(4) and x9(8)) xor
|
74 |
|
|
(x9(5) and x9(8)) xor (x9(7) and x9(8)) xor '1';
|
75 |
|
|
y9(1) <= x9(1) xor (x9(0) and x9(1)) xor (x9(2) and x9(3)) xor (x9(0) and x9(4)) xor
|
76 |
|
|
(x9(1) and x9(4)) xor (x9(0) and x9(5)) xor (x9(3) and x9(5)) xor x9(6) xor
|
77 |
|
|
(x9(1) and x9(7)) xor (x9(2) and x9(7)) xor (x9(5) and x9(8)) xor '1';
|
78 |
|
|
y9(2) <= x9(1) xor (x9(0) and x9(3)) xor (x9(3) and x9(4)) xor (x9(0) and x9(5)) xor
|
79 |
|
|
(x9(2) and x9(6)) xor (x9(3) and x9(6)) xor (x9(5) and x9(6)) xor (x9(4) and x9(7)) xor
|
80 |
|
|
(x9(5) and x9(7)) xor (x9(6) and x9(7)) xor x9(8) xor (x9(0) and x9(8)) xor
|
81 |
|
|
'1';
|
82 |
|
|
y9(3) <= x9(0) xor (x9(1) and x9(2)) xor (x9(0) and x9(3)) xor (x9(2) and x9(4)) xor
|
83 |
|
|
x9(5) xor (x9(0) and x9(6)) xor (x9(1) and x9(6)) xor (x9(4) and x9(7)) xor
|
84 |
|
|
(x9(0) and x9(8)) xor (x9(1) and x9(8)) xor (x9(7) and x9(8));
|
85 |
|
|
y9(4) <= (x9(0) and x9(1)) xor (x9(1) and x9(3)) xor x9(4) xor (x9(0) and x9(5)) xor
|
86 |
|
|
(x9(3) and x9(6)) xor (x9(0) and x9(7)) xor (x9(6) and x9(7)) xor (x9(1) and x9(8)) xor
|
87 |
|
|
(x9(2) and x9(8)) xor (x9(3) and x9(8));
|
88 |
|
|
y9(5) <= x9(2) xor (x9(1) and x9(4)) xor (x9(4) and x9(5)) xor (x9(0) and x9(6)) xor
|
89 |
|
|
(x9(1) and x9(6)) xor (x9(3) and x9(7)) xor (x9(4) and x9(7)) xor (x9(6) and x9(7)) xor
|
90 |
|
|
(x9(5) and x9(8)) xor (x9(6) and x9(8)) xor (x9(7) and x9(8)) xor '1';
|
91 |
|
|
y9(6) <= x9(0) xor (x9(2) and x9(3)) xor (x9(1) and x9(5)) xor (x9(2) and x9(5)) xor
|
92 |
|
|
(x9(4) and x9(5)) xor (x9(3) and x9(6)) xor (x9(4) and x9(6)) xor (x9(5) and x9(6)) xor
|
93 |
|
|
x9(7) xor (x9(1) and x9(8)) xor (x9(3) and x9(8)) xor (x9(5) and x9(8)) xor
|
94 |
|
|
(x9(7) and x9(8));
|
95 |
|
|
y9(7) <= (x9(0) and x9(1)) xor (x9(0) and x9(2)) xor (x9(1) and x9(2)) xor x9(3) xor
|
96 |
|
|
(x9(0) and x9(3)) xor (x9(2) and x9(3)) xor (x9(4) and x9(5)) xor (x9(2) and x9(6)) xor
|
97 |
|
|
(x9(3) and x9(6)) xor (x9(2) and x9(7)) xor (x9(5) and x9(7)) xor x9(8) xor
|
98 |
|
|
'1';
|
99 |
|
|
y9(8) <= (x9(0) and x9(1)) xor x9(2) xor (x9(1) and x9(2)) xor (x9(3) and x9(4)) xor
|
100 |
|
|
(x9(1) and x9(5)) xor (x9(2) and x9(5)) xor (x9(1) and x9(6)) xor (x9(4) and x9(6)) xor
|
101 |
|
|
x9(7) xor (x9(2) and x9(8)) xor (x9(3) and x9(8));
|
102 |
|
|
--S9
|
103 |
|
|
end phy;
|