| 1 |
2 |
redbear |
//////////////////////////////////////////////////////////////////
|
| 2 |
|
|
////
|
| 3 |
|
|
////
|
| 4 |
|
|
//// AES CORE BLOCK
|
| 5 |
|
|
////
|
| 6 |
|
|
////
|
| 7 |
|
|
////
|
| 8 |
3 |
redbear |
//// This file is part of the APB to AES128 project
|
| 9 |
2 |
redbear |
////
|
| 10 |
3 |
redbear |
//// http://www.opencores.org/cores/apbtoaes128/
|
| 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 |
|
|
localparam BUS_WIDTH = 128; // Bus Width
|
| 86 |
|
|
localparam ST_WORD = 8; // Data Size of word in State MAtrix
|
| 87 |
|
|
localparam ST_LINE = 4; // Number of Lines of State Matrix
|
| 88 |
|
|
localparam ST_COL = 4; // Number of Columns of State Matrix
|
| 89 |
|
|
|
| 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 |
|
|
for(l = 0; l < ST_LINE; l = l + 1)
|
| 100 |
|
|
for(c = 0; c < ST_COL; c = c + 1)
|
| 101 |
|
|
assign state[l][c] = data_in[ST_WORD*((ST_COL - c)*ST_LINE - l) - 1 : ST_WORD*((ST_COL - c)*ST_LINE - l - 1)];
|
| 102 |
|
|
endgenerate
|
| 103 |
|
|
|
| 104 |
|
|
//=====================================================================================
|
| 105 |
|
|
// Shift Row operation
|
| 106 |
|
|
//=====================================================================================
|
| 107 |
|
|
generate
|
| 108 |
|
|
genvar l1,c1;
|
| 109 |
|
|
for(l1 = 0; l1 < ST_LINE; l1 = l1 + 1)
|
| 110 |
|
|
for(c1 = 0; c1 < ST_COL; c1 = c1 + 1)
|
| 111 |
|
|
begin
|
| 112 |
|
|
assign state_sft_l[l1][c1] = state[l1][(c1 + l1)%ST_COL];
|
| 113 |
|
|
assign state_sft_r[l1][c1] = state[l1][(c1 + (ST_COL - l1))%ST_COL];
|
| 114 |
|
|
end
|
| 115 |
|
|
endgenerate
|
| 116 |
|
|
|
| 117 |
|
|
//=====================================================================================
|
| 118 |
|
|
// State Matrix to Bus Output Transformation
|
| 119 |
|
|
//=====================================================================================
|
| 120 |
|
|
generate
|
| 121 |
|
|
genvar l2,c2;
|
| 122 |
|
|
for(l2 = 0; l2 < ST_LINE; l2 = l2 + 1)
|
| 123 |
|
|
for(c2 = 0; c2 < ST_COL; c2 = c2 + 1)
|
| 124 |
|
|
begin
|
| 125 |
|
|
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];
|
| 126 |
|
|
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];
|
| 127 |
|
|
end
|
| 128 |
|
|
endgenerate
|
| 129 |
|
|
endmodule
|