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

Subversion Repositories threeaesc

[/] [threeaesc/] [trunk/] [aes_c_2/] [src/] [aes_enc.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 entactogen
-- Copyright (c) 2011 Antonio de la Piedra
2
 
3
-- This program is free software: you can redistribute it and/or modify
4
-- it under the terms of the GNU General Public License as published by
5
-- the Free Software Foundation, either version 3 of the License, or
6
-- (at your option) any later version.
7
 
8
-- This program is distributed in the hope that it will be useful,
9
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
-- GNU General Public License for more details.
12
 
13
-- You should have received a copy of the GNU General Public License
14
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
library IEEE;
17
 
18
use IEEE.STD_LOGIC_1164.ALL;
19
use IEEE.std_logic_ARITH.ALL;
20
use IEEE.std_logic_UNSIGNED.ALL;
21
 
22
use work.aes_lib.all;
23
 
24
entity aes_enc is
25
        port(     clk: in std_logic;
26
                  block_in : in std_logic_vector(127 downto 0);
27
                  sub_key : in std_logic_vector(127 downto 0);
28
                  last : in std_logic;
29
                  block_out : out std_logic_vector(127 downto 0));
30
        end aes_enc;
31
 
32
architecture Behavioral of aes_enc is
33
 
34
        signal sub_tmp_s   : std_logic_vector(127 downto 0);
35
        signal sub_tmp_mix : std_logic_vector(127 downto 0);
36
 
37
begin
38
 
39
        S_BOX_DUAL_1: entity work.dual_mem(rtl) port map (clk, '0', block_in(7 downto 0),     block_in(47 downto 40), (others=>'0'),    sub_tmp_s(7 downto 0),  sub_tmp_s(15 downto 8));
40
        S_BOX_DUAL_2: entity work.dual_mem(rtl) port map (clk, '0', block_in(87 downto 80),   block_in(127 downto 120), (others=>'0'),  sub_tmp_s(23 downto 16),  sub_tmp_s(31 downto 24));
41
        S_BOX_DUAL_3: entity work.dual_mem(rtl) port map (clk, '0', block_in(39 downto 32),   block_in(79 downto 72), (others=>'0'),   sub_tmp_s(39 downto 32),  sub_tmp_s(47 downto 40));
42
        S_BOX_DUAL_4: entity work.dual_mem(rtl) port map (clk, '0', block_in(119 downto 112),   block_in(31 downto 24), (others=>'0'),   sub_tmp_s(55 downto 48),  sub_tmp_s(63 downto 56));
43
        S_BOX_DUAL_5: entity work.dual_mem(rtl) port map (clk, '0', block_in(71 downto 64),   block_in(111 downto 104), (others=>'0'),   sub_tmp_s(71 downto 64),  sub_tmp_s(79 downto 72));
44
        S_BOX_DUAL_6: entity work.dual_mem(rtl) port map (clk, '0', block_in(23 downto 16),   block_in(63 downto 56), (others=>'0'),   sub_tmp_s(87 downto 80), sub_tmp_s(95 downto 88));
45
        S_BOX_DUAL_7: entity work.dual_mem(rtl) port map (clk, '0', block_in(103 downto 96),  block_in(15 downto 8), (others=>'0'), sub_tmp_s(103 downto 96), sub_tmp_s(111 downto 104));
46
        S_BOX_DUAL_8: entity work.dual_mem(rtl) port map (clk, '0', block_in(55 downto 48), block_in(95 downto 88), (others=>'0'), sub_tmp_s(119 downto 112), sub_tmp_s(127 downto 120));
47
 
48
        MIX_COL: process(sub_tmp_s, last)
49
        begin
50
                if last = '0' then
51
 
52
                        sub_tmp_mix(7 downto 0)  <= gfmult2(sub_tmp_s(7 downto 0)) xor gfmult3(sub_tmp_s(15 downto 8)) xor sub_tmp_s(23 downto 16) xor sub_tmp_s(31 downto 24);
53
                        sub_tmp_mix(15 downto 8) <= sub_tmp_s(7 downto 0) xor gfmult2(sub_tmp_s(15 downto 8)) xor gfmult3(sub_tmp_s(23 downto 16)) xor sub_tmp_s(31 downto 24);
54
                        sub_tmp_mix(23 downto 16) <= sub_tmp_s(7 downto 0) xor sub_tmp_s(15 downto 8) xor gfmult2(sub_tmp_s(23 downto 16)) xor gfmult3(sub_tmp_s(31 downto 24));
55
                        sub_tmp_mix(31 downto 24) <= gfmult3(sub_tmp_s(7 downto 0)) xor sub_tmp_s(15 downto 8) xor sub_tmp_s(23 downto 16) xor gfmult2(sub_tmp_s(31 downto 24));
56
 
57
                        sub_tmp_mix(39 downto 32) <= gfmult2(sub_tmp_s(39 downto 32)) xor gfmult3(sub_tmp_s(47 downto 40)) xor sub_tmp_s(55 downto 48) xor sub_tmp_s(63 downto 56);
58
                        sub_tmp_mix(47 downto 40) <= sub_tmp_s(39 downto 32) xor gfmult2(sub_tmp_s(47 downto 40)) xor gfmult3(sub_tmp_s(55 downto 48)) xor sub_tmp_s(63 downto 56);
59
                        sub_tmp_mix(55 downto 48) <= sub_tmp_s(39 downto 32) xor sub_tmp_s(47 downto 40) xor gfmult2(sub_tmp_s(55 downto 48)) xor gfmult3(sub_tmp_s(63 downto 56));
60
                        sub_tmp_mix(63 downto 56) <= gfmult3(sub_tmp_s(39 downto 32)) xor sub_tmp_s(47 downto 40) xor sub_tmp_s(55 downto 48) xor gfmult2(sub_tmp_s(63 downto 56));
61
 
62
                        sub_tmp_mix(71 downto 64) <= gfmult2(sub_tmp_s(71 downto 64)) xor gfmult3(sub_tmp_s(79 downto 72)) xor sub_tmp_s(87 downto 80) xor sub_tmp_s(95 downto 88);
63
                        sub_tmp_mix(79 downto 72) <= sub_tmp_s(71 downto 64) xor gfmult2(sub_tmp_s(79 downto 72)) xor gfmult3(sub_tmp_s(87 downto 80)) xor sub_tmp_s(95 downto 88);
64
                        sub_tmp_mix(87 downto 80) <= sub_tmp_s(71 downto 64) xor sub_tmp_s(79 downto 72) xor gfmult2(sub_tmp_s(87 downto 80)) xor gfmult3(sub_tmp_s(95 downto 88));
65
                        sub_tmp_mix(95 downto 88) <= gfmult3(sub_tmp_s(71 downto 64)) xor sub_tmp_s(79 downto 72) xor sub_tmp_s(87 downto 80) xor gfmult2(sub_tmp_s(95 downto 88));
66
 
67
                        sub_tmp_mix(103 downto 96) <= gfmult2(sub_tmp_s(103 downto 96)) xor gfmult3(sub_tmp_s(111 downto 104)) xor sub_tmp_s(119 downto 112) xor sub_tmp_s(127 downto 120);
68
                        sub_tmp_mix(111 downto 104) <= sub_tmp_s(103 downto 96) xor gfmult2(sub_tmp_s(111 downto 104)) xor gfmult3(sub_tmp_s(119 downto 112)) xor sub_tmp_s(127 downto 120);
69
                        sub_tmp_mix(119 downto 112) <= sub_tmp_s(103 downto 96) xor sub_tmp_s(111 downto 104) xor gfmult2(sub_tmp_s(119 downto 112)) xor gfmult3(sub_tmp_s(127 downto 120));
70
                        sub_tmp_mix(127 downto 120) <= gfmult3(sub_tmp_s(103 downto 96)) xor sub_tmp_s(111 downto 104) xor sub_tmp_s(119 downto 112) xor gfmult2(sub_tmp_s(127 downto 120));
71
 
72
                else
73
                        sub_tmp_mix <= sub_tmp_s;
74
 
75
                end if;
76
        end process;
77
 
78
        block_out <= sub_tmp_mix xor sub_key;
79
 
80
end Behavioral;
81
 

powered by: WebSVN 2.1.0

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