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

Subversion Repositories apbtoaes128

[/] [apbtoaes128/] [trunk/] [rtl/] [mix_columns.v] - Blame information for rev 4

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

Line No. Rev Author Line
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 mix_columns
77
(
78
        // OUTPUTS
79
        output [31:0] mix_out_enc,
80
        output [31:0] mix_out_dec,
81
        // INPUTS
82
        input  [31:0] mix_in
83
);
84
 
85
localparam SIZE      = 32;
86
localparam WORD_SIZE = 8;
87
localparam NUM_WORDS = 4;
88
 
89
wire [WORD_SIZE - 1 : 0] col  [0 : NUM_WORDS - 1];
90
wire [WORD_SIZE - 1 : 0] sum_p[0 : NUM_WORDS - 1];
91
wire [WORD_SIZE - 1 : 0] y    [0 : NUM_WORDS - 2];
92
 
93
//=====================================================================================
94
// Multiplication by 02 in GF(2^8) 
95
//=====================================================================================
96
function [7:0] aes_mult_02;
97
  input [7:0] data_in;
98
  begin
99
    aes_mult_02 = (data_in << 1) ^ {8{data_in[7]}} & 8'h1b;
100
  end
101
endfunction
102
 
103
//=====================================================================================
104
// Multiplication by 04 in GF(2^8)
105
//=====================================================================================
106
function [7:0] aes_mult_04;
107
  input [7:0] data_in;
108
  begin
109
    aes_mult_04 = ((data_in << 2) ^ {8{data_in[6]}} & 8'h1b) ^ {8{data_in[7]}} & 8'h36;
110
  end
111
endfunction
112
 
113
//=====================================================================================
114
// Word to Byte transformation
115
//=====================================================================================
116
generate
117
        genvar i;
118
        for(i = 0 ; i < NUM_WORDS; i = i + 1)
119
                assign col[i] = mix_in[WORD_SIZE*(i + 1) - 1: WORD_SIZE*i];
120
endgenerate
121
 
122
//=====================================================================================
123
// Direct Mix Column Operation
124
//=====================================================================================
125
generate
126
        genvar j;
127
        for(j = 0; j < NUM_WORDS; j = j + 1)
128
                begin
129
                        assign sum_p[j] = col[(j + 1)%NUM_WORDS] ^ col[(j + 2)%NUM_WORDS] ^ col[(j + 3)%NUM_WORDS];
130
                        assign mix_out_enc[ WORD_SIZE*(j + 1) - 1 : WORD_SIZE*j] = aes_mult_02(col[j] ^ col[(j + NUM_WORDS - 1)%NUM_WORDS]) ^ sum_p[j];
131
                end
132
endgenerate
133
 
134
//=====================================================================================
135
// Inverse Mix Column Operation
136
//=====================================================================================
137
assign y[0] = aes_mult_04(col[2] ^ col[0]);
138
assign y[1] = aes_mult_04(col[3] ^ col[1]);
139
assign y[2] = aes_mult_02(  y[1] ^   y[0]);
140
assign mix_out_dec = mix_out_enc ^ {2{y[2] ^ y[1], y[2] ^ y[0]}};
141
 
142
endmodule

powered by: WebSVN 2.1.0

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