1 |
2 |
schengopen |
////////////////////////////////////////////////////////////////// ////
|
2 |
|
|
//// ////
|
3 |
|
|
//// AES Decryption Core for FPGA ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the AES Decryption Core for FPGA project ////
|
6 |
|
|
//// http://www.opencores.org/cores/xxx/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// Implementation of AES Decryption Core for FPGA according to ////
|
10 |
|
|
//// core specification document. ////
|
11 |
|
|
//// ////
|
12 |
|
|
//// To Do: ////
|
13 |
|
|
//// - ////
|
14 |
|
|
//// ////
|
15 |
|
|
//// Author(s): ////
|
16 |
|
|
//// - scheng, schengopencores@opencores.org ////
|
17 |
|
|
//// ////
|
18 |
|
|
//////////////////////////////////////////////////////////////////////
|
19 |
|
|
//// ////
|
20 |
|
|
//// Copyright (C) 2009 Authors and OPENCORES.ORG ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// This source file may be used and distributed without ////
|
23 |
|
|
//// restriction provided that this copyright statement is not ////
|
24 |
|
|
//// removed from the file and that any derivative work contains ////
|
25 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
26 |
|
|
//// ////
|
27 |
|
|
//// This source file is free software; you can redistribute it ////
|
28 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
29 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
30 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
31 |
|
|
//// later version. ////
|
32 |
|
|
//// ////
|
33 |
|
|
//// This source is distributed in the hope that it will be ////
|
34 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
35 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
36 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
37 |
|
|
//// details. ////
|
38 |
|
|
//// ////
|
39 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
40 |
|
|
//// Public License along with this source; if not, download it ////
|
41 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
42 |
|
|
//// //// ///
|
43 |
|
|
///////////////////////////////////////////////////////////////////
|
44 |
|
|
//// ////
|
45 |
|
|
//// This module implements the Galois field multipliers ////
|
46 |
|
|
//// for x2, x3, x9, xb, xd, xe. Used in InvMixCol_slice. ////
|
47 |
|
|
//// See section 4.2 of FIPS-197 specification for details. ////
|
48 |
|
|
//// ////
|
49 |
|
|
////////////////////////////////////////////////////////////////////////
|
50 |
|
|
module gfmul_inv(
|
51 |
|
|
input [7:0] d,
|
52 |
|
|
output [7:0] x2,
|
53 |
|
|
output [7:0] x3,
|
54 |
|
|
output [7:0] x9,
|
55 |
|
|
output [7:0] xb,
|
56 |
|
|
output [7:0] xd,
|
57 |
|
|
output [7:0] xe
|
58 |
|
|
);
|
59 |
|
|
// Multiplier over GF(256)
|
60 |
|
|
// Generates - x2, 3 for cipher
|
61 |
|
|
// - x9, xb, xd, xe for inverse cipher
|
62 |
|
|
|
63 |
|
|
function byte unsigned xtime(byte unsigned x);
|
64 |
|
|
// Multiplication by 2 over GF(256)
|
65 |
|
|
// Refer to FIPS-197 spec section 4.2.1 on definition of GF(256) multiplication
|
66 |
|
|
xtime = (x[7])? (x<<1) ^ 8'h1b : x<<1;
|
67 |
|
|
endfunction
|
68 |
|
|
|
69 |
|
|
function byte unsigned GFmul3(byte unsigned x);
|
70 |
|
|
// Multiply by 3 over GF(256)
|
71 |
|
|
// 3*x = 2*x +x
|
72 |
|
|
GFmul3 = xtime(x) ^ x;
|
73 |
|
|
endfunction
|
74 |
|
|
|
75 |
|
|
function byte unsigned GFmul4(byte unsigned x);
|
76 |
|
|
// Multiply by 4 over GF(256)
|
77 |
|
|
// 4*x = 2*(2*x)
|
78 |
|
|
GFmul4 = xtime(xtime(x));
|
79 |
|
|
endfunction
|
80 |
|
|
|
81 |
|
|
function byte unsigned GFmul8(byte unsigned x);
|
82 |
|
|
// Multiply by 8 over GF(256)
|
83 |
|
|
// 8*x = 2*(4*x)
|
84 |
|
|
GFmul8 = xtime(GFmul4(x));
|
85 |
|
|
endfunction
|
86 |
|
|
|
87 |
|
|
function byte unsigned GFmul9(byte unsigned x);
|
88 |
|
|
// Multiply by 9 over GF(256)
|
89 |
|
|
// 9*x = 8*x + x
|
90 |
|
|
// Addition over GF(256) is xor
|
91 |
|
|
GFmul9 = GFmul8(x) ^ x;
|
92 |
|
|
endfunction
|
93 |
|
|
|
94 |
|
|
function byte unsigned GFmulb(byte unsigned x);
|
95 |
|
|
// Multiply by 0xb over GF(256)
|
96 |
|
|
// b*x = 8*x + 2*x +x
|
97 |
|
|
GFmulb = GFmul8(x) ^ xtime(x) ^ x;
|
98 |
|
|
endfunction
|
99 |
|
|
|
100 |
|
|
function byte unsigned GFmuld(byte unsigned x);
|
101 |
|
|
// Multiply by 0xd over GF(256)
|
102 |
|
|
// d*x = 8*x + 4*x + x
|
103 |
|
|
GFmuld = GFmul8(x) ^ GFmul4(x) ^ x;
|
104 |
|
|
endfunction
|
105 |
|
|
|
106 |
|
|
function byte unsigned GFmule(byte unsigned x);
|
107 |
|
|
// Multiply by 0xe over GF(256)
|
108 |
|
|
// e*x = 8*x + 4*x +2*x
|
109 |
|
|
GFmule = GFmul8(x) ^ GFmul4(x) ^ xtime(x);
|
110 |
|
|
endfunction
|
111 |
|
|
|
112 |
|
|
assign x2 = xtime(d);
|
113 |
|
|
assign x3 = GFmul3(d);
|
114 |
|
|
assign x9 = GFmul9(d);
|
115 |
|
|
assign xb = GFmulb(d);
|
116 |
|
|
assign xd = GFmuld(d);
|
117 |
|
|
assign xe = GFmule(d);
|
118 |
|
|
|
119 |
|
|
endmodule
|