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 2

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

powered by: WebSVN 2.1.0

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