1 |
2 |
arif_endro |
-- $Id: mix_column.vhdl,v 1.1.1.1 2005-12-06 02:48:33 arif_endro Exp $
|
2 |
|
|
-------------------------------------------------------------------------------
|
3 |
|
|
-- Title :
|
4 |
|
|
-- Project : Mini AES 128
|
5 |
|
|
-------------------------------------------------------------------------------
|
6 |
|
|
-- File :
|
7 |
|
|
-- Author : "Arif E. Nugroho" <arif_endro@yahoo.com>
|
8 |
|
|
-- Created : 2005/12/03
|
9 |
|
|
-- Last update :
|
10 |
|
|
-- Simulators : ModelSim SE PLUS 6.0
|
11 |
|
|
-- Synthesizers: ISE Xilinx 6.3i
|
12 |
|
|
-- Target :
|
13 |
|
|
-------------------------------------------------------------------------------
|
14 |
|
|
-- Description :
|
15 |
|
|
-------------------------------------------------------------------------------
|
16 |
15 |
arif_endro |
-- Copyright (C) 2005 Arif Endro Nugroho
|
17 |
2 |
arif_endro |
-------------------------------------------------------------------------------
|
18 |
|
|
--
|
19 |
|
|
-- THIS SOURCE FILE MAY BE USED AND DISTRIBUTED WITHOUT RESTRICTION
|
20 |
|
|
-- PROVIDED THAT THIS COPYRIGHT STATEMENT IS NOT REMOVED FROM THE FILE AND THAT
|
21 |
|
|
-- ANY DERIVATIVE WORK CONTAINS THE ORIGINAL COPYRIGHT NOTICE AND THE
|
22 |
|
|
-- ASSOCIATED DISCLAIMER.
|
23 |
|
|
--
|
24 |
|
|
-------------------------------------------------------------------------------
|
25 |
|
|
--
|
26 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
27 |
|
|
-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
28 |
|
|
-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
29 |
|
|
-- EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
30 |
|
|
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
31 |
|
|
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
32 |
|
|
-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
33 |
|
|
-- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
34 |
|
|
-- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
35 |
|
|
-- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36 |
|
|
--
|
37 |
|
|
-------------------------------------------------------------------------------
|
38 |
|
|
|
39 |
|
|
library ieee;
|
40 |
|
|
use ieee.std_logic_1164.all;
|
41 |
|
|
use work.xtime_pkg.all;
|
42 |
|
|
|
43 |
|
|
entity mix_column is
|
44 |
|
|
|
45 |
|
|
port (
|
46 |
|
|
s0 : in std_logic_vector (07 downto 00);
|
47 |
|
|
s1 : in std_logic_vector (07 downto 00);
|
48 |
|
|
s2 : in std_logic_vector (07 downto 00);
|
49 |
|
|
s3 : in std_logic_vector (07 downto 00);
|
50 |
|
|
mix_col : out std_logic_vector (31 downto 00);
|
51 |
|
|
inv_mix_col : out std_logic_vector (31 downto 00)
|
52 |
|
|
);
|
53 |
|
|
|
54 |
|
|
end mix_column;
|
55 |
|
|
|
56 |
|
|
architecture data_flow of mix_column is
|
57 |
|
|
|
58 |
|
|
type state is array (03 downto 00) of std_logic_vector (07 downto 00);
|
59 |
|
|
|
60 |
|
|
signal mc : state :=
|
61 |
|
|
( X"00", X"00", X"00", X"00" );
|
62 |
|
|
|
63 |
|
|
begin
|
64 |
|
|
|
65 |
|
|
--
|
66 |
|
|
-- MixColumn : a(x) = {03}x^3 + {01}x^2 + {01}x + {02}
|
67 |
|
|
--
|
68 |
|
|
-- s'0c = | 02 03 01 01 | s0c
|
69 |
|
|
-- s'1c = | 01 02 03 01 | s1c
|
70 |
|
|
-- s'2c = | 01 01 02 03 | s2c
|
71 |
|
|
-- s'3c = | 03 01 01 02 | s3c
|
72 |
|
|
--
|
73 |
|
|
-- InvMixColumn: a'(x) = {0B}x^3 + {0D}x^2 + {09}x + {0E}
|
74 |
|
|
-- a'(x) = {03}x^3 + {01}x^2 + {01}x + {02} +
|
75 |
|
|
-- {08}x^3 + {08}x^2 + {08}x + {08} +
|
76 |
|
|
-- {04}x^2 + {04}x
|
77 |
|
|
-- a(x) * a'(x) = {01}
|
78 |
|
|
-- a(x) * {a'(x)}^2 = {01} * a'(x) = a'(x)
|
79 |
|
|
-- {a'(x)}^2 = {04}x^2 + {05}
|
80 |
|
|
--
|
81 |
|
|
-- | 05 00 04 00 | | 0E 0B 0D 09 | E = 14 = 1110 = 8 xor 4 xor 2 = 1000 xor 0100 xor 0010
|
82 |
|
|
-- {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
|
83 |
|
|
-- | 04 00 05 00 | | 0D 09 0E 0B | B = 11 = 1011 = 8 xor 2 xor 1 = 1000 xor 0010 xor 0001
|
84 |
|
|
-- | 00 04 00 05 | | 0B 0D 09 0E | 9 = 09 = 1001 = 8 xor 0 xor 1 = 1000 xor 0000 xor 0001
|
85 |
|
|
--
|
86 |
|
|
|
87 |
|
|
mc (3) <= xtime_2(s0) xor xtime_2(s1) xor s1 xor s2 xor s3;
|
88 |
|
|
mc (2) <= s0 xor xtime_2(s1) xor xtime_2(s2) xor s2 xor s3;
|
89 |
|
|
mc (1) <= s0 xor s1 xor xtime_2(s2) xor xtime_2(s3) xor s3;
|
90 |
|
|
mc (0) <= xtime_2(s0) xor s0 xor s1 xor s2 xor xtime_2(s3);
|
91 |
|
|
--
|
92 |
|
|
mix_col <= (mc(3) & mc(2) & mc(1) & mc(0));
|
93 |
|
|
--
|
94 |
|
|
inv_mix_col (31 downto 24) <= xtime_4(mc(3)) xor mc(3) xor xtime_4(mc(1));
|
95 |
|
|
inv_mix_col (23 downto 16) <= xtime_4(mc(2)) xor mc(2) xor xtime_4(mc(0));
|
96 |
|
|
inv_mix_col (15 downto 08) <= xtime_4(mc(1)) xor mc(1) xor xtime_4(mc(3));
|
97 |
|
|
inv_mix_col (07 downto 00) <= xtime_4(mc(0)) xor mc(0) xor xtime_4(mc(2));
|
98 |
|
|
--
|
99 |
|
|
-- inv_mix_col (31 downto 24) <=
|
100 |
|
|
-- xtime_8(mc(3)) xor xtime_4(mc(3)) xor xtime_2(mc(3)) xor
|
101 |
|
|
-- xtime_8(mc(2)) xor xtime_2(mc(2)) xor mc(2) xor
|
102 |
|
|
-- xtime_8(mc(1)) xor xtime_4(mc(1)) xor mc(1) xor
|
103 |
|
|
-- xtime_8(mc(0)) xor mc(0);
|
104 |
|
|
-- inv_mix_col (23 downto 16) <=
|
105 |
|
|
-- xtime_8(mc(3)) xor mc(3) xor
|
106 |
|
|
-- xtime_8(mc(2)) xor xtime_4(mc(2)) xor xtime_2(mc(2)) xor
|
107 |
|
|
-- xtime_8(mc(1)) xor xtime_2(mc(1)) xor mc(1) xor
|
108 |
|
|
-- xtime_8(mc(0)) xor xtime_4(mc(0)) xor mc(0);
|
109 |
|
|
-- inv_mix_col (15 downto 08) <=
|
110 |
|
|
-- xtime_8(mc(3)) xor xtime_4(mc(3)) xor mc(3) xor
|
111 |
|
|
-- xtime_8(mc(2)) xor mc(2) xor
|
112 |
|
|
-- xtime_8(mc(1)) xor xtime_4(mc(1)) xor xtime_2(mc(1)) xor
|
113 |
|
|
-- xtime_8(mc(0)) xor xtime_2(mc(0)) xor mc(0);
|
114 |
|
|
-- inv_mix_col (07 downto 00) <=
|
115 |
|
|
-- xtime_8(mc(3)) xor xtime_2(mc(3)) xor mc(3) xor
|
116 |
|
|
-- xtime_8(mc(2)) xor xtime_4(mc(2)) xor mc(2) xor
|
117 |
|
|
-- xtime_8(mc(1)) xor mc(1) xor
|
118 |
|
|
-- xtime_8(mc(0)) xor xtime_4(mc(0)) xor xtime_2(mc(0));
|
119 |
|
|
|
120 |
|
|
end data_flow;
|