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

Subversion Repositories aes_pipe

[/] [aes_pipe/] [trunk/] [rtl/] [vhdl/] [mixcol.vhdl] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 9 subhasis25
-- Last Modified: 25/03/10
48 2 subhasis25
-- 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 9 subhasis25
        rst: in std_logic;
78 2 subhasis25
        in0: in std_logic_vector(7 downto 0);
79
        in1: in std_logic_vector(7 downto 0);
80
        in2: in std_logic_vector(7 downto 0);
81
        in3: in std_logic_vector(7 downto 0);
82
        out0: out std_logic_vector(7 downto 0);
83
        out1: out std_logic_vector(7 downto 0);
84
        out2: out std_logic_vector(7 downto 0);
85
        out3: out std_logic_vector(7 downto 0)
86
        );
87
end mixcol;
88
 
89
architecture rtl of mixcol is
90
signal d0, d1, d2, d3: std_logic_vector(7 downto 0);
91
signal t0, t1, t2, t3: std_logic_vector(7 downto 0);
92
signal sh0, sh1, sh2, sh3: std_logic_vector(7 downto 0);
93
signal xored: std_logic_vector(7 downto 0);
94
 
95
begin
96
        sh0(0) <= '0';
97
        sh1(0) <= '0';
98
        sh2(0) <= '0';
99
        sh3(0) <= '0';
100
        -----------------------------------------------------
101
        -- In GF(2^8) 2*x = (x << 1) xor 0x1b if x(7) = '1'
102
        --                  (x << 1) else
103
        -- This just left shifts each byte by 1.
104
        shift: for i in 7 downto 1 generate
105
                sh0(i) <= in0(i-1);
106
                sh1(i) <= in1(i-1);
107
                sh2(i) <= in2(i-1);
108
                sh3(i) <= in3(i-1);
109
        end generate;
110
        -- Conditional XOR'ing
111
        d0 <= sh0 xor X"1b" when in0(7) = '1' else
112
        sh0;
113
        d1 <= sh1 xor X"1b" when in1(7) = '1' else
114
        sh1;
115
        d2 <= sh2 xor X"1b" when in2(7) = '1' else
116
        sh2;
117
        d3 <= sh3 xor X"1b" when in3(7) = '1' else
118
        sh3;
119
 
120
        ----------------------------------------------------
121
        -- 3*x = 2*x xor x
122
        ----------------------------------------------------
123
        t0 <= d0 xor in0;
124
        t1 <= d1 xor in1;
125
        t2 <= d2 xor in2;
126
        t3 <= d3 xor in3;
127
 
128
        xored <= in0 xor in1 xor in2 xor in3;
129 9 subhasis25
        process(clk,rst)
130 2 subhasis25
        begin
131 9 subhasis25
                if(rst = '1') then
132
                        out0 <= X"00";
133
                        out1 <= X"00";
134
                        out2 <= X"00";
135
                        out3 <= X"00";
136
                elsif(rising_edge(clk)) then
137 2 subhasis25
                        out0 <= xored xor t0 xor d1;
138
                        out1 <= xored xor t1 xor d2;
139
                        out2 <= xored xor t2 xor d3;
140
                        out3 <= xored xor t3 xor d0;
141
                end if;
142
        end process;
143
end rtl;

powered by: WebSVN 2.1.0

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