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

Subversion Repositories cryptopan_core

[/] [cryptopan_core/] [trunk/] [rtl/] [round_unit.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tonyb33
--
2
-- This file is part of the Crypto-PAn core.
3
--
4
-- Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5
-- Authors: Anthony Blake (tonyb33@opencores.org)
6
--          
7
-- All rights reserved.
8
--
9
-- This code has been developed by the University of Waikato WAND 
10
-- research group. For further information please see http://www.wand.net.nz/
11
--
12
-- This source file is free software; you can redistribute it and/or modify
13
-- it under the terms of the GNU General Public License as published by
14
-- the Free Software Foundation; either version 2 of the License, or
15
-- (at your option) any later version.
16
--
17
-- This source is distributed in the hope that it will be useful,
18
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-- GNU General Public License for more details.
21
--
22
-- You should have received a copy of the GNU General Public License
23
-- along with libtrace; if not, write to the Free Software
24
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
--
26
 
27
library ieee;
28
use ieee.std_logic_1164.all;
29
use ieee.std_logic_unsigned.all;
30
 
31
use work.cryptopan.all;
32
 
33
entity round_unit is
34
  generic (
35
    do_mixcolumns :     boolean := true);
36
  port (
37
    bytes_in      : in  s_vector;
38
    bytes_out     : out s_vector;
39
 
40
    in_en  : in  std_logic;
41
    out_en : out std_logic;
42
 
43
    load_en   : in std_logic;
44
    load_data : in std_logic_vector(31 downto 0);
45
 
46
    load_clk : in std_logic;
47
    clk   : in std_logic;
48
    reset : in std_logic
49
    );
50
 
51
end round_unit;
52
 
53
architecture rtl of round_unit is
54
 
55
  component mixcolumns
56
    port (
57
      bytes_in  : in  s_vector;
58
      bytes_out : out s_vector;
59
      in_en     : in  std_logic;
60
      out_en    : out std_logic;
61
      clk       : in  std_logic;
62
      reset     : in  std_logic);
63
  end component;
64
 
65
  component subbytesshiftrows
66
    port (
67
      bytes_in    : in  s_vector;
68
      bytes_out   : out s_vector;
69
      in_en       : in  std_logic;
70
      out_en      : out std_logic;
71
      clk         : in  std_logic;
72
      reset       : in  std_logic);
73
  end component;
74
  signal sbsr_out :     s_vector;
75
  signal mix_out  :     s_vector;
76
 
77
  signal round_key : s_vector;
78
  signal round_out : s_vector;
79
 
80
  signal load_counter : std_logic_vector(1 downto 0);
81
  signal sbsr_out_en  : std_logic;
82
  signal mix_out_en : std_logic;
83
begin
84
 
85
  bytes_out <= round_out;
86
 
87
  LOAD_LOGIC : process (load_clk, reset)
88
  begin
89
    if reset = '1' then
90
      for i in 0 to 15 loop
91
        round_key(i) <= (others => '0');
92
      end loop;
93
      load_counter   <= "00";
94
 
95
    elsif load_clk'event and load_clk = '1' then
96
 
97
      if load_en = '1' then
98
        if load_counter = "00" then
99
          round_key(12) <= load_data(7 downto 0);
100
          round_key(8)  <= load_data(15 downto 8);
101
          round_key(4)  <= load_data(23 downto 16);
102
          round_key(0)  <= load_data(31 downto 24);
103
        elsif load_counter = "01" then
104
          round_key(13) <= load_data(7 downto 0);
105
          round_key(9)  <= load_data(15 downto 8);
106
          round_key(5)  <= load_data(23 downto 16);
107
          round_key(1)  <= load_data(31 downto 24);
108
        elsif load_counter = "10" then
109
          round_key(14) <= load_data(7 downto 0);
110
          round_key(10) <= load_data(15 downto 8);
111
          round_key(6)  <= load_data(23 downto 16);
112
          round_key(2)  <= load_data(31 downto 24);
113
        elsif load_counter = "11" then
114
          round_key(15) <= load_data(7 downto 0);
115
          round_key(11) <= load_data(15 downto 8);
116
          round_key(7)  <= load_data(23 downto 16);
117
          round_key(3)  <= load_data(31 downto 24);
118
        end if;
119
        load_counter    <= load_counter + 1;
120
      else
121
        load_counter    <= "00";
122
      end if;
123
    end if;
124
  end process LOAD_LOGIC;
125
 
126
  SBSR0 : subbytesshiftrows
127
    port map (
128
      bytes_in  => bytes_in,
129
      bytes_out => sbsr_out,
130
      in_en     => in_en,
131
      out_en    => sbsr_out_en,
132
      clk       => clk,
133
      reset     => reset);
134
 
135
  out_en    <= mix_out_en;
136
 
137
 
138
  GENMIXCOLUMNS : if do_mixcolumns = true generate
139
    MIX0        : mixcolumns
140
      port map (
141
        bytes_in  => sbsr_out,
142
        bytes_out => mix_out,
143
        in_en => sbsr_out_en,
144
        out_en => mix_out_en,
145
        clk       => clk,
146
        reset     => reset);
147
 
148
  end generate GENMIXCOLUMNS;
149
 
150
  NO_GENMIXCOLUMNS : if do_mixcolumns = false generate
151
    mix_out <= sbsr_out;
152
    mix_out_en <= sbsr_out_en;
153
  end generate NO_GENMIXCOLUMNS;
154
 
155
 
156
  ROUND_XOR : for i in 0 to 15 generate
157
    round_out(i) <= round_key(i) xor mix_out(i);
158
  end generate ROUND_XOR;
159
 
160
 
161
end rtl;

powered by: WebSVN 2.1.0

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