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 15

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

Line No. Rev Author Line
1 2 arif_endro
-- $Id: folded_register.vhdl,v 1.1.1.1 2005-12-06 02:48:32 arif_endro Exp $
2
-------------------------------------------------------------------------------
3
-- Title       : Folded register. 
4
-- Project     : Mini AES 128 
5
-------------------------------------------------------------------------------
6
-- File        : folded_register.vhdl
7
-- Author      : "Arif E. Nugroho" <arif_endro@yahoo.com>
8
-- Created     : 2005/12/03
9
-- Last update : 
10
-- Simulators  : ModelSim SE PLUS 6.0
11
-- Synthesizers: ISE Xilinx 6.3i
12
-- Target      : 
13
-------------------------------------------------------------------------------
14
-- Description : Folded register manipulations for manipulating data.
15
-------------------------------------------------------------------------------
16 15 arif_endro
-- Copyright (C) 2005 Arif Endro Nugroho
17 2 arif_endro
-------------------------------------------------------------------------------
18
-- 
19
--         THIS SOURCE FILE MAY BE USED AND DISTRIBUTED WITHOUT RESTRICTION
20
-- PROVIDED THAT THIS COPYRIGHT STATEMENT IS NOT REMOVED FROM THE FILE AND THAT
21
-- ANY DERIVATIVE WORK CONTAINS THE ORIGINAL COPYRIGHT NOTICE AND THE
22
-- ASSOCIATED DISCLAIMER.
23
-- 
24
-------------------------------------------------------------------------------
25
-- 
26
--         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27
-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28
-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
29
-- EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32
-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33
-- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34
-- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35
-- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
-- 
37
-------------------------------------------------------------------------------
38
 
39
library ieee;
40
use ieee.std_logic_1164.all;
41
use ieee.std_logic_unsigned.all;
42
 
43
entity folded_register is
44
  port (
45
    clk_i  : in  std_logic;
46
    enc_i  : in  std_logic;
47
    load_i : in  std_logic;
48
    data_i : in  std_logic_vector (127 downto 000);
49
    key_i  : in  std_logic_vector (127 downto 000);
50
    di_0_i : in  std_logic_vector (007 downto 000);
51
    di_1_i : in  std_logic_vector (007 downto 000);
52
    di_2_i : in  std_logic_vector (007 downto 000);
53
    di_3_i : in  std_logic_vector (007 downto 000);
54
    do_0_o : out std_logic_vector (007 downto 000);
55
    do_1_o : out std_logic_vector (007 downto 000);
56
    do_2_o : out std_logic_vector (007 downto 000);
57
    do_3_o : out std_logic_vector (007 downto 000)
58
    );
59
end folded_register;
60
 
61
architecture data_flow of folded_register is
62
 
63
  component counter2bit
64
    port (
65
      clock : in  std_logic;
66
      clear : in  std_logic;
67
      count : out std_logic_vector (1 downto 0)
68
      );
69
  end component;
70
 
71
  type fifo16x8 is array (00 to 15) of std_logic_vector (7 downto 0);
72
  type addr4x4 is array (3 downto 0) of std_logic_vector (3 downto 0);
73
  type addr4x8 is array (3 downto 0) of std_logic_vector (7 downto 0);
74
 
75
  signal foldreg0 : fifo16x8 :=
76
    (
77
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00",
78
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00"
79
      );
80
--
81
  signal foldreg1 : fifo16x8 :=
82
    (
83
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00",
84
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00"
85
      );
86
--
87
  signal foldreg2 : fifo16x8 :=
88
    (
89
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00",
90
      X"00", X"00", X"00", X"00", X"00", X"00", X"00", X"00"
91
      );
92
 
93
  signal   round0             : std_logic_vector (127 downto 000) := ( X"00000000_00000000_00000000_00000000" );
94
--
95
  signal   a_0_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
96
  signal   a_1_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
97
  signal   a_2_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
98
  signal   a_3_i              : std_logic_vector (3 downto 0)     := ( B"0000" );
99
--
100
  constant fifo_addr_cons     : std_logic_vector (63 downto 00)   := ( X"05AF_49E3_8D27_C16B" );
101
  constant fifo_addr_cons_inv : std_logic_vector (63 downto 00)   := ( X"0DA7_41EB_852F_C963" );
102
  signal   fifo_addr          : std_logic_vector (63 downto 00)   := ( X"0000_0000_0000_0000" );
103
--
104
  signal   tmp                : addr4x8                           := ( X"00", X"00", X"00", X"00" );
105
  signal   addr               : addr4x4                           := ( X"0", X"0", X"0", X"0" );
106
--
107
  signal   count              : std_logic_vector (1 downto 0);
108
  signal   switch             : std_logic                         := '0';
109
  signal   reg_i              : std_logic                         := '0';
110
 
111
begin
112
 
113
  sect : counter2bit
114
    port map (
115
      clock => clk_i,
116
      clear => load_i,
117
      count => count
118
      );
119
 
120
  round0 <= data_i xor key_i;
121
 
122
  process(clk_i, load_i)
123
  begin
124
    if (load_i = '1') then
125
      foldreg0                 <= (
126
        round0 (127 downto 120), round0 (119 downto 112), round0 (111 downto 104), round0 (103 downto 096),
127
        round0 (095 downto 088), round0 (087 downto 080), round0 (079 downto 072), round0 (071 downto 064),
128
        round0 (063 downto 056), round0 (055 downto 048), round0 (047 downto 040), round0 (039 downto 032),
129
        round0 (031 downto 024), round0 (023 downto 016), round0 (015 downto 008), round0 (007 downto 000)
130
        );
131
--
132
      foldreg1                 <= (
133
        round0 (127 downto 120), round0 (119 downto 112), round0 (111 downto 104), round0 (103 downto 096),
134
        round0 (095 downto 088), round0 (087 downto 080), round0 (079 downto 072), round0 (071 downto 064),
135
        round0 (063 downto 056), round0 (055 downto 048), round0 (047 downto 040), round0 (039 downto 032),
136
        round0 (031 downto 024), round0 (023 downto 016), round0 (015 downto 008), round0 (007 downto 000)
137
        );
138
--
139
      if (enc_i = '0') then
140
        fifo_addr              <= fifo_addr_cons;
141
      else
142
        fifo_addr              <= fifo_addr_cons_inv;
143
      end if;
144
      reg_i                    <= '0';
145
    elsif (clk_i = '1' and clk_i'event) then
146
      if (reg_i = '1') then
147
        foldreg0 (00 to 11)    <= ( foldreg0 (04 to 15) );
148
        foldreg0 (12 to 15)    <= ( di_0_i, di_1_i, di_2_i, di_3_i );
149
      else
150
        foldreg1 (00 to 11)    <= ( foldreg1 (04 to 15) );
151
        foldreg1 (12 to 15)    <= ( di_0_i, di_1_i, di_2_i, di_3_i );
152
      end if;
153
      fifo_addr (63 downto 16) <= fifo_addr (47 downto 00);
154
      fifo_addr (15 downto 00) <= fifo_addr (63 downto 48);
155
      if (switch = '1') then
156
        reg_i                  <= not(reg_i);
157
      end if;
158
    end if;
159
  end process;
160
 
161
  a_0_i               <= addr(0);
162
  a_1_i               <= addr(1);
163
  a_2_i               <= addr(2);
164
  a_3_i               <= addr(3);
165
--
166
  foldreg2 (00 to 11) <= ( foldreg0 (04 to 15) )       when (reg_i = '1')    else ( foldreg1 (04 to 15) );
167
  foldreg2 (12 to 15) <= ( di_0_i, di_1_i, di_2_i, di_3_i );
168
--
169
  switch              <= (count(1)) and (count(0));
170
--
171
  addr(0)             <= fifo_addr (51 downto 48)      when ( load_i = '1' ) else fifo_addr (35 downto 32);
172
  addr(1)             <= fifo_addr (55 downto 52)      when ( load_i = '1' ) else fifo_addr (39 downto 36);
173
  addr(2)             <= fifo_addr (59 downto 56)      when ( load_i = '1' ) else fifo_addr (43 downto 40);
174
  addr(3)             <= fifo_addr (63 downto 60)      when ( load_i = '1' ) else fifo_addr (47 downto 44);
175
--
176
  tmp(0)              <= foldreg1(conv_integer(a_0_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_0_i));
177
  tmp(1)              <= foldreg1(conv_integer(a_1_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_1_i));
178
  tmp(2)              <= foldreg1(conv_integer(a_2_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_2_i));
179
  tmp(3)              <= foldreg1(conv_integer(a_3_i)) when ( reg_i = '1' )  else foldreg0(conv_integer(a_3_i));
180
--
181
  do_0_o              <= tmp(3)                        when ( switch = '0')  else foldreg2(conv_integer(a_3_i));
182
  do_1_o              <= tmp(2)                        when ( switch = '0')  else foldreg2(conv_integer(a_2_i));
183
  do_2_o              <= tmp(1)                        when ( switch = '0')  else foldreg2(conv_integer(a_1_i));
184
  do_3_o              <= tmp(0)                        when ( switch = '0')  else foldreg2(conv_integer(a_0_i));
185
 
186
end data_flow;

powered by: WebSVN 2.1.0

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