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

Subversion Repositories mini_aes

[/] [mini_aes/] [trunk/] [source/] [folded_register.vhdl] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 arif_endro
-- ------------------------------------------------------------------------
2 15 arif_endro
-- Copyright (C) 2005 Arif Endro Nugroho
3 21 arif_endro
-- All rights reserved.
4 2 arif_endro
-- 
5 21 arif_endro
-- Redistribution and use in source and binary forms, with or without
6
-- modification, are permitted provided that the following conditions
7
-- are met:
8 2 arif_endro
-- 
9 21 arif_endro
-- 1. Redistributions of source code must retain the above copyright
10
--    notice, this list of conditions and the following disclaimer.
11
-- 2. Redistributions in binary form must reproduce the above copyright
12
--    notice, this list of conditions and the following disclaimer in the
13
--    documentation and/or other materials provided with the distribution.
14 2 arif_endro
-- 
15 21 arif_endro
-- THIS SOFTWARE IS PROVIDED BY ARIF ENDRO NUGROHO "AS IS" AND ANY EXPRESS
16
-- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
-- DISCLAIMED. IN NO EVENT SHALL ARIF ENDRO NUGROHO BE LIABLE FOR ANY
19
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23
-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
-- POSSIBILITY OF SUCH DAMAGE.
26 2 arif_endro
-- 
27 21 arif_endro
-- End Of License.
28
-- ------------------------------------------------------------------------
29 2 arif_endro
 
30
library ieee;
31
use ieee.std_logic_1164.all;
32
use ieee.std_logic_unsigned.all;
33
 
34
entity folded_register is
35
  port (
36
    clk_i  : in  std_logic;
37
    enc_i  : in  std_logic;
38
    load_i : in  std_logic;
39
    data_i : in  std_logic_vector (127 downto 000);
40
    key_i  : in  std_logic_vector (127 downto 000);
41
    di_0_i : in  std_logic_vector (007 downto 000);
42
    di_1_i : in  std_logic_vector (007 downto 000);
43
    di_2_i : in  std_logic_vector (007 downto 000);
44
    di_3_i : in  std_logic_vector (007 downto 000);
45
    do_0_o : out std_logic_vector (007 downto 000);
46
    do_1_o : out std_logic_vector (007 downto 000);
47
    do_2_o : out std_logic_vector (007 downto 000);
48
    do_3_o : out std_logic_vector (007 downto 000)
49
    );
50
end folded_register;
51
 
52
architecture data_flow of folded_register is
53
 
54
  component counter2bit
55
    port (
56
      clock : in  std_logic;
57
      clear : in  std_logic;
58
      count : out std_logic_vector (1 downto 0)
59
      );
60
  end component;
61
 
62
  type fifo16x8 is array (00 to 15) of std_logic_vector (7 downto 0);
63
  type addr4x4 is array (3 downto 0) of std_logic_vector (3 downto 0);
64
  type addr4x8 is array (3 downto 0) of std_logic_vector (7 downto 0);
65
 
66
  signal foldreg0 : fifo16x8 :=
67
    (
68
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00",
69
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00"
70
      );
71
--
72
  signal foldreg1 : fifo16x8 :=
73
    (
74
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00",
75
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00"
76
      );
77
--
78
  signal foldreg2 : fifo16x8 :=
79
    (
80
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00",
81
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00"
82
      );
83
 
84
  signal   round0             : std_logic_vector (127 downto 000) := ( X"00000000_00000000_00000000_00000000" );
85
--
86
  signal   a_0_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
87
  signal   a_1_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
88
  signal   a_2_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
89
  signal   a_3_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
90
--
91
  constant fifo_addr_cons     : std_logic_vector (63 downto 00)   := ( X"05AF_49E3_8D27_C16B" );
92
  constant fifo_addr_cons_inv : std_logic_vector (63 downto 00)   := ( X"0DA7_41EB_852F_C963" );
93
  signal   fifo_addr          : std_logic_vector (63 downto 00)   := ( X"0000_0000_0000_0000" );
94
--
95
  signal   tmp                : addr4x8                           := ( X"00", X"00", X"00", X"00" );
96
  signal   addr               : addr4x4                           := ( X"0", X"0", X"0", X"0" );
97
--
98
  signal   count              : std_logic_vector (1 downto 0);
99
  signal   switch             : std_logic                         := '0';
100
  signal   reg_i              : std_logic                         := '0';
101
 
102
begin
103
 
104
  sect : counter2bit
105
    port map (
106
      clock => clk_i,
107
      clear => load_i,
108
      count => count
109
      );
110
 
111
  round0 <= data_i xor key_i;
112
 
113
  process(clk_i, load_i)
114
  begin
115
    if (load_i = '1') then
116
      foldreg0                 <= (
117
        round0 (127 downto 120), round0 (119 downto 112), round0 (111 downto 104), round0 (103 downto 096),
118
        round0 (095 downto 088), round0 (087 downto 080), round0 (079 downto 072), round0 (071 downto 064),
119
        round0 (063 downto 056), round0 (055 downto 048), round0 (047 downto 040), round0 (039 downto 032),
120
        round0 (031 downto 024), round0 (023 downto 016), round0 (015 downto 008), round0 (007 downto 000)
121
        );
122
--
123
      foldreg1                 <= (
124
        round0 (127 downto 120), round0 (119 downto 112), round0 (111 downto 104), round0 (103 downto 096),
125
        round0 (095 downto 088), round0 (087 downto 080), round0 (079 downto 072), round0 (071 downto 064),
126
        round0 (063 downto 056), round0 (055 downto 048), round0 (047 downto 040), round0 (039 downto 032),
127
        round0 (031 downto 024), round0 (023 downto 016), round0 (015 downto 008), round0 (007 downto 000)
128
        );
129
--
130
      if (enc_i = '0') then
131
        fifo_addr              <= fifo_addr_cons;
132
      else
133
        fifo_addr              <= fifo_addr_cons_inv;
134
      end if;
135
      reg_i                    <= '0';
136
    elsif (clk_i = '1' and clk_i'event) then
137
      if (reg_i = '1') then
138
        foldreg0 (00 to 11)    <= ( foldreg0 (04 to 15) );
139
        foldreg0 (12 to 15)    <= ( di_0_i, di_1_i, di_2_i, di_3_i );
140
      else
141
        foldreg1 (00 to 11)    <= ( foldreg1 (04 to 15) );
142
        foldreg1 (12 to 15)    <= ( di_0_i, di_1_i, di_2_i, di_3_i );
143
      end if;
144
      fifo_addr (63 downto 16) <= fifo_addr (47 downto 00);
145
      fifo_addr (15 downto 00) <= fifo_addr (63 downto 48);
146
      if (switch = '1') then
147
        reg_i                  <= not(reg_i);
148
      end if;
149
    end if;
150
  end process;
151
 
152
  a_0_i               <= addr(0);
153
  a_1_i               <= addr(1);
154
  a_2_i               <= addr(2);
155
  a_3_i               <= addr(3);
156
--
157
  foldreg2 (00 to 11) <= ( foldreg0 (04 to 15) )       when (reg_i = '1')    else ( foldreg1 (04 to 15) );
158
  foldreg2 (12 to 15) <= ( di_0_i, di_1_i, di_2_i, di_3_i );
159
--
160
  switch              <= (count(1)) and (count(0));
161
--
162
  addr(0)             <= fifo_addr (51 downto 48)      when ( load_i = '1' ) else fifo_addr (35 downto 32);
163
  addr(1)             <= fifo_addr (55 downto 52)      when ( load_i = '1' ) else fifo_addr (39 downto 36);
164
  addr(2)             <= fifo_addr (59 downto 56)      when ( load_i = '1' ) else fifo_addr (43 downto 40);
165
  addr(3)             <= fifo_addr (63 downto 60)      when ( load_i = '1' ) else fifo_addr (47 downto 44);
166
--
167
  tmp(0)              <= foldreg1(conv_integer(a_0_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_0_i));
168
  tmp(1)              <= foldreg1(conv_integer(a_1_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_1_i));
169
  tmp(2)              <= foldreg1(conv_integer(a_2_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_2_i));
170
  tmp(3)              <= foldreg1(conv_integer(a_3_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_3_i));
171
--
172
  do_0_o              <= tmp(3)                        when ( switch = '0')  else foldreg2(conv_integer(a_3_i));
173
  do_1_o              <= tmp(2)                        when ( switch = '0')  else foldreg2(conv_integer(a_2_i));
174
  do_2_o              <= tmp(1)                        when ( switch = '0')  else foldreg2(conv_integer(a_1_i));
175
  do_3_o              <= tmp(0)                        when ( switch = '0')  else foldreg2(conv_integer(a_0_i));
176
 
177
end data_flow;

powered by: WebSVN 2.1.0

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