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

Subversion Repositories avs_aes

[/] [avs_aes/] [trunk/] [rtl/] [VHDL/] [shiftrow_fwd.vhd] - Blame information for rev 20

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ruschi
--------------------------------------------------------------------------------
2 10 ruschi
-- This file is part of the project  avs_aes
3
-- see: http://opencores.org/project,avs_aes
4 2 ruschi
--
5
-- description: (Encryption implementation of Shiftrow) 
6
-- Shift Row rotates the Rows of the AES Block
7
-- This module takes the whole Rijdael state as input, extracts the rows,
8
-- shifts them and rebuilts the state.
9
--
10
-------------------------------------------------------------------------------
11
--
12
-- Author(s):
13
--         Thomas Ruschival -- ruschi@opencores.org (www.ruschival.de)
14
--
15
--------------------------------------------------------------------------------
16
-- Copyright (c) 2009, Authors and opencores.org
17
-- All rights reserved.
18
--
19
-- Redistribution and use in source and binary forms, with or without modification,
20
-- are permitted provided that the following conditions are met:
21
--    * Redistributions of source code must retain the above copyright notice,
22
--    this list of conditions and the following disclaimer.
23
--    * Redistributions in binary form must reproduce the above copyright notice,
24
--    this list of conditions and the following disclaimer in the documentation
25
--    and/or other materials provided with the distribution.
26
--    * Neither the name of the organization nor the names of its contributors
27
--    may be used to endorse or promote products derived from this software without
28
--    specific prior written permission.
29
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
33
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
34
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
39
-- THE POSSIBILITY OF SUCH DAMAGE
40
-------------------------------------------------------------------------------
41
-- version management:
42 20 ruschi
-- $Author::                                         $
43
-- $Date::                                           $
44
-- $Revision::                                       $
45 2 ruschi
-------------------------------------------------------------------------------
46
 
47
library IEEE;
48
use IEEE.numeric_std.all;
49
use IEEE.std_logic_1164.all;
50
 
51 11 ruschi
library avs_aes_lib;
52
use avs_aes_lib.avs_aes_pkg.all;
53 2 ruschi
 
54
 
55
architecture fwd of Shiftrow is
56
                -- type of converting the columns into rows
57
        subtype ROW is BYTEARRAY(0 to 3);
58
        -- Row signal for easier handling of the shift operations
59
        signal row1_in  : Row;                          -- 1st row
60
        signal row2_in  : Row;                          -- 2nd row
61
        signal row3_in  : Row;                          -- 3rd row
62
        signal row4_in  : Row;                          -- 4th row
63
        -- single rows after shift operation
64
        -- row1 of the shifted state = row1 of unshifted state 
65
        signal row2_out : Row;                          -- 2nd row
66
        signal row3_out : Row;                          -- 3rd row
67
        signal row4_out : Row;                          -- 4th row
68
 
69
begin  -- architecture arch1
70
        -- purpose: build the temorary internal signals for easier handling
71
        -- type   : combinational
72
        -- inputs : state_in
73
        -- outputs: state_out
74
        build_in : process (state_in) is
75
        begin  -- process build_in
76
                -- state is a DWORD array with 16, 24 or 32 Byte in 4,6 or 8 columns
77
                -- thus we loop through the columns and slice the column in its bytes
78
                for col_cnt in 0 to (state_in'high) loop
79
                        row1_in(col_cnt) <= state_in(col_cnt)(31 downto 24);
80
                        row2_in(col_cnt) <= state_in(col_cnt)(23 downto 16);
81
                        row3_in(col_cnt) <= state_in(col_cnt)(15 downto 8);
82
                        row4_in(col_cnt) <= state_in(col_cnt)(7 downto 0);
83
                end loop;  -- col_cnt
84
        end process build_in;
85
 
86
 
87
        -- purpose: shift rows of Rindael state by 'shift_delta'
88
        -- type   : combinational
89
        -- inputs : row(1 to 4)_in
90
        -- outputs: row(1 to 4)_out
91
        shifter : process (row2_in, row3_in, row4_in) is
92
        begin
93
                -- 1st row was never shifted so no reverse action needed
94
                -- rotate 2nd row left
95
                row2_out <= row2_in(row2_in'left+1 to row2_in'right) & row2_in(row2_in'left);
96
                --rotate by 2 left
97
                row3_out <= row3_in(row3_in'left+2 to row3_in'right) & row3_in(row3_in'left to row3_in'left+1);
98
                -- rotate by 3 left
99
                row4_out <= row4_in(row4_in'left+3 to row4_in'right) & row4_in(row4_in'left to row4_in'left+2);
100
        end process shifter;
101
 
102
 
103
        -- purpose: rebuilt the state form the shifted rows
104
        -- type   : combinational
105
        -- inputs : row1_out, row2_out, row3_out, row4_out
106
        -- outputs: state_out
107
        rebuilt_state : process (row1_in, row2_out, row3_out, row4_out) is
108
        begin  -- process rebuilt_state 
109
                for col_cnt in 0 to state_out'high loop   -- works because 15/4=3
110
                        state_out(col_cnt)(31 downto 24) <= row1_in(col_cnt);
111
                        state_out(col_cnt)(23 downto 16) <= row2_out(col_cnt);
112
                        state_out(col_cnt)(15 downto 8)  <= row3_out(col_cnt);
113
                        state_out(col_cnt)(7 downto 0)    <= row4_out(col_cnt);
114
                end loop;  -- col_cnt           
115
        end process rebuilt_state;
116
 
117
end architecture fwd;

powered by: WebSVN 2.1.0

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