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

Subversion Repositories aes_pipe

[/] [aes_pipe/] [tags/] [P0/] [rtl/] [vhdl/] [mixcol.vhdl] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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