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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [rtl/] [shift_rows.v] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    AES CORE BLOCK
5
////
6
////
7
////
8 7 redbear
//// This file is part of the APB to I2C project
9 2 redbear
////
10 7 redbear
//// http://www.opencores.org/cores/apbi2c/
11 2 redbear
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// aes128_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29
////              Julio Cesar 
30
////
31
///////////////////////////////////////////////////////////////// 
32
////
33
////
34
//// Copyright (C) 2009 Authors and OPENCORES.ORG
35
////
36
////
37
////
38
//// This source file may be used and distributed without
39
////
40
//// restriction provided that this copyright statement is not
41
////
42
//// removed from the file and that any derivative work contains
43
//// the original copyright notice and the associated disclaimer.
44
////
45
////
46
//// This source file is free software; you can redistribute it
47
////
48
//// and/or modify it under the terms of the GNU Lesser General
49
////
50
//// Public License as published by the Free Software Foundation;
51
//// either version 2.1 of the License, or (at your option) any
52
////
53
//// later version.
54
////
55
////
56
////
57
//// This source is distributed in the hope that it will be
58
////
59
//// useful, but WITHOUT ANY WARRANTY; without even the implied
60
////
61
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
62
////
63
//// PURPOSE. See the GNU Lesser General Public License for more
64
//// details.
65
////
66
////
67
////
68
//// You should have received a copy of the GNU Lesser General
69
////
70
//// Public License along with this source; if not, download it
71
////
72
//// from http://www.opencores.org/lgpl.shtml
73
////
74
////
75
///////////////////////////////////////////////////////////////////
76
module shift_rows
77
(
78
        //OUTPUTS
79
        output [127 : 0] data_out_enc,  // Result after Shift Rows operation - enc
80
        output [127 : 0] data_out_dec,  // Result after Shift Rows operation - dec
81
        //INPUTS
82
        input  [127 : 0] data_in        // Input Bus
83
);
84
 
85 7 redbear
localparam integer BUS_WIDTH = 128;  // Bus Width
86
localparam integer ST_WORD   =   8;  // Data Size of word in State MAtrix
87
localparam integer ST_LINE   =   4;  // Number of Lines of State Matrix
88
localparam integer ST_COL    =   4;  // Number of Columns of State Matrix
89 2 redbear
 
90
wire [ST_WORD - 1 : 0] state[0 : ST_LINE - 1][0 : ST_COL - 1];
91
wire [ST_WORD - 1 : 0] state_sft_l[0 : ST_LINE - 1][0 : ST_COL - 1];
92
wire [ST_WORD - 1 : 0] state_sft_r[0 : ST_LINE - 1][0 : ST_COL - 1];
93
 
94
//=====================================================================================
95
// State Matrix generation
96
//=====================================================================================
97
generate
98
        genvar l,c;
99 14 redbear
        for(l = 0; l < ST_LINE; l = l + 1)
100
        begin:SMG
101
                for(c = 0; c < ST_COL; c = c + 1)
102
                begin:BLOCK
103 2 redbear
                        assign state[l][c] = data_in[ST_WORD*((ST_COL - c)*ST_LINE - l) - 1 : ST_WORD*((ST_COL - c)*ST_LINE - l - 1)];
104 14 redbear
                end
105
        end
106 2 redbear
endgenerate
107
 
108
//=====================================================================================
109
// Shift Row operation
110
//=====================================================================================
111
generate
112
        genvar l1,c1;
113 14 redbear
        for(l1 = 0; l1 < ST_LINE; l1 = l1 + 1)
114
        begin:SRO
115 2 redbear
                for(c1 = 0; c1 < ST_COL; c1 = c1 + 1)
116 14 redbear
                        begin:BLOCK
117 2 redbear
                                assign state_sft_l[l1][c1] = state[l1][(c1 + l1)%ST_COL];
118
                                assign state_sft_r[l1][c1] = state[l1][(c1 + (ST_COL - l1))%ST_COL];
119 14 redbear
                        end
120
        end
121 2 redbear
endgenerate
122
 
123
//=====================================================================================
124
// State Matrix to Bus Output Transformation
125
//=====================================================================================
126
generate
127
        genvar l2,c2;
128 14 redbear
        for(l2 = 0; l2 < ST_LINE; l2 = l2 + 1)
129
        begin:SMBOT
130 2 redbear
                for(c2 = 0; c2 < ST_COL; c2 = c2 + 1)
131 14 redbear
                        begin:BLOCK
132 2 redbear
                                assign data_out_enc[ST_WORD*((ST_COL - c2)*ST_LINE - l2) - 1 : ST_WORD*((ST_COL - c2)*ST_LINE - l2 - 1)] = state_sft_l[l2][c2];
133
                                assign data_out_dec[ST_WORD*((ST_COL - c2)*ST_LINE - l2) - 1 : ST_WORD*((ST_COL - c2)*ST_LINE - l2 - 1)] = state_sft_r[l2][c2];
134 14 redbear
                        end
135
        end
136 2 redbear
endgenerate
137
endmodule

powered by: WebSVN 2.1.0

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