1 |
21 |
arif_endro |
-- ------------------------------------------------------------------------
|
2 |
15 |
arif_endro |
-- Copyright (C) 2005 Arif Endro Nugroho
|
3 |
21 |
arif_endro |
-- All rights reserved.
|
4 |
2 |
arif_endro |
--
|
5 |
21 |
arif_endro |
-- Redistribution and use in source and binary forms, with or without
|
6 |
|
|
-- modification, are permitted provided that the following conditions
|
7 |
|
|
-- are met:
|
8 |
2 |
arif_endro |
--
|
9 |
21 |
arif_endro |
-- 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 |
|
|
-- 3. The name of Arif Endro Nugroho may not be used to endorse or promote
|
15 |
|
|
-- products derived from this software without specific prior written
|
16 |
|
|
-- permission.
|
17 |
2 |
arif_endro |
--
|
18 |
21 |
arif_endro |
-- THIS SOFTWARE IS PROVIDED BY ARIF ENDRO NUGROHO "AS IS" AND ANY EXPRESS
|
19 |
|
|
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20 |
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21 |
|
|
-- DISCLAIMED. IN NO EVENT SHALL ARIF ENDRO NUGROHO BE LIABLE FOR ANY
|
22 |
|
|
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23 |
|
|
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
24 |
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
25 |
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
26 |
|
|
-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 |
|
|
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
29 |
2 |
arif_endro |
--
|
30 |
21 |
arif_endro |
-- End Of License.
|
31 |
|
|
-- ------------------------------------------------------------------------
|
32 |
2 |
arif_endro |
|
33 |
|
|
library ieee;
|
34 |
|
|
use ieee.std_logic_1164.all;
|
35 |
|
|
use work.xtime_pkg.all;
|
36 |
|
|
|
37 |
|
|
entity mix_column is
|
38 |
|
|
|
39 |
|
|
port (
|
40 |
|
|
s0 : in std_logic_vector (07 downto 00);
|
41 |
|
|
s1 : in std_logic_vector (07 downto 00);
|
42 |
|
|
s2 : in std_logic_vector (07 downto 00);
|
43 |
|
|
s3 : in std_logic_vector (07 downto 00);
|
44 |
|
|
mix_col : out std_logic_vector (31 downto 00);
|
45 |
|
|
inv_mix_col : out std_logic_vector (31 downto 00)
|
46 |
|
|
);
|
47 |
|
|
|
48 |
|
|
end mix_column;
|
49 |
|
|
|
50 |
|
|
architecture data_flow of mix_column is
|
51 |
|
|
|
52 |
|
|
type state is array (03 downto 00) of std_logic_vector (07 downto 00);
|
53 |
|
|
|
54 |
|
|
signal mc : state :=
|
55 |
|
|
( X"00", X"00", X"00", X"00" );
|
56 |
|
|
|
57 |
|
|
begin
|
58 |
|
|
|
59 |
|
|
--
|
60 |
|
|
-- MixColumn : a(x) = {03}x^3 + {01}x^2 + {01}x + {02}
|
61 |
|
|
--
|
62 |
|
|
-- s'0c = | 02 03 01 01 | s0c
|
63 |
|
|
-- s'1c = | 01 02 03 01 | s1c
|
64 |
|
|
-- s'2c = | 01 01 02 03 | s2c
|
65 |
|
|
-- s'3c = | 03 01 01 02 | s3c
|
66 |
|
|
--
|
67 |
|
|
-- InvMixColumn: a'(x) = {0B}x^3 + {0D}x^2 + {09}x + {0E}
|
68 |
|
|
-- a'(x) = {03}x^3 + {01}x^2 + {01}x + {02} +
|
69 |
|
|
-- {08}x^3 + {08}x^2 + {08}x + {08} +
|
70 |
|
|
-- {04}x^2 + {04}x
|
71 |
|
|
-- a(x) * a'(x) = {01}
|
72 |
|
|
-- a(x) * {a'(x)}^2 = {01} * a'(x) = a'(x)
|
73 |
|
|
-- {a'(x)}^2 = {04}x^2 + {05}
|
74 |
|
|
--
|
75 |
|
|
-- | 05 00 04 00 | | 0E 0B 0D 09 | E = 14 = 1110 = 8 xor 4 xor 2 = 1000 xor 0100 xor 0010
|
76 |
|
|
-- {a'(x)}^2 = | 00 05 00 04 | a'(x) = | 09 0E 0B 0D | D = 13 = 1101 = 8 xor 4 xor 1 = 1000 xor 0100 xor 0001
|
77 |
|
|
-- | 04 00 05 00 | | 0D 09 0E 0B | B = 11 = 1011 = 8 xor 2 xor 1 = 1000 xor 0010 xor 0001
|
78 |
|
|
-- | 00 04 00 05 | | 0B 0D 09 0E | 9 = 09 = 1001 = 8 xor 0 xor 1 = 1000 xor 0000 xor 0001
|
79 |
|
|
--
|
80 |
|
|
|
81 |
|
|
mc (3) <= xtime_2(s0) xor xtime_2(s1) xor s1 xor s2 xor s3;
|
82 |
|
|
mc (2) <= s0 xor xtime_2(s1) xor xtime_2(s2) xor s2 xor s3;
|
83 |
|
|
mc (1) <= s0 xor s1 xor xtime_2(s2) xor xtime_2(s3) xor s3;
|
84 |
|
|
mc (0) <= xtime_2(s0) xor s0 xor s1 xor s2 xor xtime_2(s3);
|
85 |
|
|
--
|
86 |
|
|
mix_col <= (mc(3) & mc(2) & mc(1) & mc(0));
|
87 |
|
|
--
|
88 |
|
|
inv_mix_col (31 downto 24) <= xtime_4(mc(3)) xor mc(3) xor xtime_4(mc(1));
|
89 |
|
|
inv_mix_col (23 downto 16) <= xtime_4(mc(2)) xor mc(2) xor xtime_4(mc(0));
|
90 |
|
|
inv_mix_col (15 downto 08) <= xtime_4(mc(1)) xor mc(1) xor xtime_4(mc(3));
|
91 |
|
|
inv_mix_col (07 downto 00) <= xtime_4(mc(0)) xor mc(0) xor xtime_4(mc(2));
|
92 |
|
|
--
|
93 |
|
|
-- inv_mix_col (31 downto 24) <=
|
94 |
|
|
-- xtime_8(mc(3)) xor xtime_4(mc(3)) xor xtime_2(mc(3)) xor
|
95 |
|
|
-- xtime_8(mc(2)) xor xtime_2(mc(2)) xor mc(2) xor
|
96 |
|
|
-- xtime_8(mc(1)) xor xtime_4(mc(1)) xor mc(1) xor
|
97 |
|
|
-- xtime_8(mc(0)) xor mc(0);
|
98 |
|
|
-- inv_mix_col (23 downto 16) <=
|
99 |
|
|
-- xtime_8(mc(3)) xor mc(3) xor
|
100 |
|
|
-- xtime_8(mc(2)) xor xtime_4(mc(2)) xor xtime_2(mc(2)) xor
|
101 |
|
|
-- xtime_8(mc(1)) xor xtime_2(mc(1)) xor mc(1) xor
|
102 |
|
|
-- xtime_8(mc(0)) xor xtime_4(mc(0)) xor mc(0);
|
103 |
|
|
-- inv_mix_col (15 downto 08) <=
|
104 |
|
|
-- xtime_8(mc(3)) xor xtime_4(mc(3)) xor mc(3) xor
|
105 |
|
|
-- xtime_8(mc(2)) xor mc(2) xor
|
106 |
|
|
-- xtime_8(mc(1)) xor xtime_4(mc(1)) xor xtime_2(mc(1)) xor
|
107 |
|
|
-- xtime_8(mc(0)) xor xtime_2(mc(0)) xor mc(0);
|
108 |
|
|
-- inv_mix_col (07 downto 00) <=
|
109 |
|
|
-- xtime_8(mc(3)) xor xtime_2(mc(3)) xor mc(3) xor
|
110 |
|
|
-- xtime_8(mc(2)) xor xtime_4(mc(2)) xor mc(2) xor
|
111 |
|
|
-- xtime_8(mc(1)) xor mc(1) xor
|
112 |
|
|
-- xtime_8(mc(0)) xor xtime_4(mc(0)) xor xtime_2(mc(0));
|
113 |
|
|
|
114 |
|
|
end data_flow;
|