1 |
2 |
subhasis25 |
----------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
5 |
subhasis25 |
---- Pipelined Aes IP Core ----
|
4 |
|
|
---- ----
|
5 |
|
|
---- This file is part of the Pipelined AES project ----
|
6 |
|
|
---- http://www.opencores.org/cores/aes_pipe/ ----
|
7 |
|
|
---- ----
|
8 |
|
|
---- Description ----
|
9 |
|
|
---- Implementation of AES IP core according to ----
|
10 |
|
|
---- FIPS PUB 197 specification document. ----
|
11 |
|
|
---- ----
|
12 |
|
|
---- To Do: ----
|
13 |
|
|
---- - ----
|
14 |
|
|
---- ----
|
15 |
|
|
---- Author: ----
|
16 |
|
|
---- - Subhasis Das, subhasis256@gmail.com ----
|
17 |
|
|
---- ----
|
18 |
|
|
----------------------------------------------------------------------
|
19 |
|
|
---- ----
|
20 |
|
|
---- Copyright (C) 2009 Authors and OPENCORES.ORG ----
|
21 |
|
|
---- ----
|
22 |
2 |
subhasis25 |
---- This source file may be used and distributed without ----
|
23 |
|
|
---- restriction provided that this copyright statement is not ----
|
24 |
5 |
subhasis25 |
---- removed from the file and that any derivative work contains ----
|
25 |
2 |
subhasis25 |
---- the original copyright notice and the associated disclaimer. ----
|
26 |
|
|
---- ----
|
27 |
|
|
---- This source file is free software; you can redistribute it ----
|
28 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
29 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
30 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
31 |
|
|
---- later version. ----
|
32 |
|
|
---- ----
|
33 |
|
|
---- This source is distributed in the hope that it will be ----
|
34 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
35 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
36 |
5 |
subhasis25 |
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
37 |
2 |
subhasis25 |
---- details. ----
|
38 |
|
|
---- ----
|
39 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
40 |
|
|
---- Public License along with this source; if not, download it ----
|
41 |
5 |
subhasis25 |
---- from http://www.opencores.org/lgpl.shtml ----
|
42 |
2 |
subhasis25 |
---- ----
|
43 |
|
|
----------------------------------------------------------------------
|
44 |
|
|
------------------------------------------------------
|
45 |
|
|
-- Project: AESFast
|
46 |
|
|
-- Author: Subhasis
|
47 |
|
|
-- Last Modified: 20/03/10
|
48 |
|
|
-- Email: subhasis256@gmail.com
|
49 |
|
|
------------------------------------------------------
|
50 |
|
|
--
|
51 |
|
|
-- Description: The MixColumns operation
|
52 |
|
|
-- Ports:
|
53 |
|
|
-- clk: System Clock
|
54 |
|
|
-- in0: Byte 0 of a column
|
55 |
|
|
-- in1: Byte 1 of a column
|
56 |
|
|
-- in2: Byte 2 of a column
|
57 |
|
|
-- in3: Byte 3 of a column
|
58 |
|
|
-- out0: Byte 0 of output column
|
59 |
|
|
-- out1: Byte 1 of output column
|
60 |
|
|
-- out2: Byte 2 of output column
|
61 |
|
|
-- out3: Byte 3 of output column
|
62 |
|
|
-- keyblock: Input Key Blocks three at a time
|
63 |
|
|
-- ciphertext: Output Cipher Block
|
64 |
|
|
------------------------------------------------------
|
65 |
|
|
|
66 |
|
|
library IEEE;
|
67 |
|
|
use IEEE.std_logic_1164.all;
|
68 |
|
|
use IEEE.std_logic_arith.all;
|
69 |
|
|
use IEEE.std_logic_unsigned.all;
|
70 |
|
|
|
71 |
|
|
library work;
|
72 |
|
|
use work.aes_pkg.all;
|
73 |
|
|
|
74 |
|
|
entity mixcol is
|
75 |
|
|
port(
|
76 |
|
|
clk: in std_logic;
|
77 |
|
|
in0: in std_logic_vector(7 downto 0);
|
78 |
|
|
in1: in std_logic_vector(7 downto 0);
|
79 |
|
|
in2: in std_logic_vector(7 downto 0);
|
80 |
|
|
in3: in std_logic_vector(7 downto 0);
|
81 |
|
|
out0: out std_logic_vector(7 downto 0);
|
82 |
|
|
out1: out std_logic_vector(7 downto 0);
|
83 |
|
|
out2: out std_logic_vector(7 downto 0);
|
84 |
|
|
out3: out std_logic_vector(7 downto 0)
|
85 |
|
|
);
|
86 |
|
|
end mixcol;
|
87 |
|
|
|
88 |
|
|
architecture rtl of mixcol is
|
89 |
|
|
signal d0, d1, d2, d3: std_logic_vector(7 downto 0);
|
90 |
|
|
signal t0, t1, t2, t3: std_logic_vector(7 downto 0);
|
91 |
|
|
signal sh0, sh1, sh2, sh3: std_logic_vector(7 downto 0);
|
92 |
|
|
signal xored: std_logic_vector(7 downto 0);
|
93 |
|
|
|
94 |
|
|
begin
|
95 |
|
|
sh0(0) <= '0';
|
96 |
|
|
sh1(0) <= '0';
|
97 |
|
|
sh2(0) <= '0';
|
98 |
|
|
sh3(0) <= '0';
|
99 |
|
|
-----------------------------------------------------
|
100 |
|
|
-- In GF(2^8) 2*x = (x << 1) xor 0x1b if x(7) = '1'
|
101 |
|
|
-- (x << 1) else
|
102 |
|
|
-- This just left shifts each byte by 1.
|
103 |
|
|
shift: for i in 7 downto 1 generate
|
104 |
|
|
sh0(i) <= in0(i-1);
|
105 |
|
|
sh1(i) <= in1(i-1);
|
106 |
|
|
sh2(i) <= in2(i-1);
|
107 |
|
|
sh3(i) <= in3(i-1);
|
108 |
|
|
end generate;
|
109 |
|
|
-- Conditional XOR'ing
|
110 |
|
|
d0 <= sh0 xor X"1b" when in0(7) = '1' else
|
111 |
|
|
sh0;
|
112 |
|
|
d1 <= sh1 xor X"1b" when in1(7) = '1' else
|
113 |
|
|
sh1;
|
114 |
|
|
d2 <= sh2 xor X"1b" when in2(7) = '1' else
|
115 |
|
|
sh2;
|
116 |
|
|
d3 <= sh3 xor X"1b" when in3(7) = '1' else
|
117 |
|
|
sh3;
|
118 |
|
|
|
119 |
|
|
----------------------------------------------------
|
120 |
|
|
-- 3*x = 2*x xor x
|
121 |
|
|
----------------------------------------------------
|
122 |
|
|
t0 <= d0 xor in0;
|
123 |
|
|
t1 <= d1 xor in1;
|
124 |
|
|
t2 <= d2 xor in2;
|
125 |
|
|
t3 <= d3 xor in3;
|
126 |
|
|
|
127 |
|
|
xored <= in0 xor in1 xor in2 xor in3;
|
128 |
|
|
process(clk)
|
129 |
|
|
begin
|
130 |
|
|
if(rising_edge(clk)) then
|
131 |
|
|
out0 <= xored xor t0 xor d1;
|
132 |
|
|
out1 <= xored xor t1 xor d2;
|
133 |
|
|
out2 <= xored xor t2 xor d3;
|
134 |
|
|
out3 <= xored xor t3 xor d0;
|
135 |
|
|
end if;
|
136 |
|
|
end process;
|
137 |
|
|
end rtl;
|