OpenCores
URL https://opencores.org/ocsvn/mini_aes/mini_aes/trunk

Subversion Repositories mini_aes

[/] [mini_aes/] [trunk/] [source/] [mix_column.vhdl] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 2 arif_endro
-- 
15 21 arif_endro
-- 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 2 arif_endro
-- 
27 21 arif_endro
-- End Of License.
28
-- ------------------------------------------------------------------------
29 2 arif_endro
 
30
library ieee;
31
use ieee.std_logic_1164.all;
32
use work.xtime_pkg.all;
33
 
34
entity mix_column is
35
 
36
  port (
37
    s0          : in  std_logic_vector (07 downto 00);
38
    s1          : in  std_logic_vector (07 downto 00);
39
    s2          : in  std_logic_vector (07 downto 00);
40
    s3          : in  std_logic_vector (07 downto 00);
41
    mix_col     : out std_logic_vector (31 downto 00);
42
    inv_mix_col : out std_logic_vector (31 downto 00)
43
    );
44
 
45
end mix_column;
46
 
47
architecture data_flow of mix_column is
48
 
49
  type state is array (03 downto 00) of std_logic_vector (07 downto 00);
50
 
51
  signal mc : state :=
52
    ( X"00", X"00", X"00", X"00" );
53
 
54
begin
55
 
56
  --
57
  -- MixColumn   : a(x)  = {03}x^3 + {01}x^2 + {01}x + {02}
58
  --
59
  -- s'0c = | 02 03 01 01 | s0c
60
  -- s'1c = | 01 02 03 01 | s1c
61
  -- s'2c = | 01 01 02 03 | s2c
62
  -- s'3c = | 03 01 01 02 | s3c
63
  --
64
  -- InvMixColumn: a'(x) = {0B}x^3 + {0D}x^2 + {09}x + {0E}
65
  --               a'(x) = {03}x^3 + {01}x^2 + {01}x + {02} +
66
  --                       {08}x^3 + {08}x^2 + {08}x + {08} +
67
  --                                 {04}x^2 + {04}x
68
  --  a(x) * a'(x)     = {01}
69
  --  a(x) * {a'(x)}^2 = {01} * a'(x) = a'(x)
70
  --         {a'(x)}^2 = {04}x^2 + {05}
71
  --
72
  --              | 05 00 04 00 |          | 0E 0B 0D 09 |   E = 14 = 1110 = 8 xor 4 xor 2 = 1000 xor 0100 xor 0010
73
  --  {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
74
  --              | 04 00 05 00 |          | 0D 09 0E 0B |   B = 11 = 1011 = 8 xor 2 xor 1 = 1000 xor 0010 xor 0001
75
  --              | 00 04 00 05 |          | 0B 0D 09 0E |   9 = 09 = 1001 = 8 xor 0 xor 1 = 1000 xor 0000 xor 0001
76
  --
77
 
78
  mc (3) <= xtime_2(s0) xor xtime_2(s1) xor s1 xor s2 xor s3;
79
  mc (2) <= s0 xor xtime_2(s1) xor xtime_2(s2) xor s2 xor s3;
80
  mc (1) <= s0 xor s1 xor xtime_2(s2) xor xtime_2(s3) xor s3;
81
  mc (0) <= xtime_2(s0) xor s0 xor s1 xor s2 xor xtime_2(s3);
82
--
83
  mix_col <= (mc(3) & mc(2) & mc(1) & mc(0));
84
-- 
85
  inv_mix_col (31 downto 24) <= xtime_4(mc(3)) xor mc(3) xor xtime_4(mc(1));
86
  inv_mix_col (23 downto 16) <= xtime_4(mc(2)) xor mc(2) xor xtime_4(mc(0));
87
  inv_mix_col (15 downto 08) <= xtime_4(mc(1)) xor mc(1) xor xtime_4(mc(3));
88
  inv_mix_col (07 downto 00) <= xtime_4(mc(0)) xor mc(0) xor xtime_4(mc(2));
89
--
90
--   inv_mix_col (31 downto 24) <= 
91
--                                 xtime_8(mc(3)) xor xtime_4(mc(3)) xor xtime_2(mc(3)) xor 
92
--                                 xtime_8(mc(2)) xor xtime_2(mc(2)) xor mc(2) xor
93
--                                 xtime_8(mc(1)) xor xtime_4(mc(1)) xor mc(1) xor
94
--                                 xtime_8(mc(0)) xor mc(0);
95
--   inv_mix_col (23 downto 16) <= 
96
--                                 xtime_8(mc(3)) xor mc(3) xor
97
--                                 xtime_8(mc(2)) xor xtime_4(mc(2)) xor xtime_2(mc(2)) xor 
98
--                                 xtime_8(mc(1)) xor xtime_2(mc(1)) xor mc(1) xor
99
--                                 xtime_8(mc(0)) xor xtime_4(mc(0)) xor mc(0);
100
--   inv_mix_col (15 downto 08) <= 
101
--                                 xtime_8(mc(3)) xor xtime_4(mc(3)) xor mc(3) xor
102
--                                 xtime_8(mc(2)) xor mc(2) xor
103
--                                 xtime_8(mc(1)) xor xtime_4(mc(1)) xor xtime_2(mc(1)) xor 
104
--                                 xtime_8(mc(0)) xor xtime_2(mc(0)) xor mc(0);
105
--   inv_mix_col (07 downto 00) <= 
106
--                                 xtime_8(mc(3)) xor xtime_2(mc(3)) xor mc(3) xor
107
--                                 xtime_8(mc(2)) xor xtime_4(mc(2)) xor mc(2) xor
108
--                                 xtime_8(mc(1)) xor mc(1) xor
109
--                                 xtime_8(mc(0)) xor xtime_4(mc(0)) xor xtime_2(mc(0));
110
 
111
end data_flow;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.