PandA-2024.02
examples
hls_study
aes_encrypt
optimized
aes_key.c
Go to the documentation of this file.
1
/*
2
+--------------------------------------------------------------------------+
3
| CHStone : a suite of benchmark programs for C-based High-Level Synthesis |
4
| ======================================================================== |
5
| |
6
| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, |
7
| H. Takada and K. Ishii |
8
| Nagoya University, Japan |
9
| |
10
| * Remark : |
11
| 1. This source code is modified to unify the formats of the benchmark |
12
| programs in CHStone. |
13
| 2. Test vectors are added for CHStone. |
14
| 3. If "main_result" is 0 at the end of the program, the program is |
15
| correctly executed. |
16
| 4. Please follow the copyright of each benchmark program. |
17
+--------------------------------------------------------------------------+
18
*/
19
/* aes_key.c */
20
/*
21
* Copyright (C) 2005
22
* Akira Iwata & Masayuki Sato
23
* Akira Iwata Laboratory,
24
* Nagoya Institute of Technology in Japan.
25
*
26
* All rights reserved.
27
*
28
* This software is written by Masayuki Sato.
29
* And if you want to contact us, send an email to Kimitake Wakayama
30
* (wakayama@elcom.nitech.ac.jp)
31
*
32
* Redistribution and use in source and binary forms, with or without modification,
33
* are permitted provided that the following conditions are met:
34
*
35
* 1. Redistributions of source code must retain the above copyright notice,
36
* this list of conditions and the following disclaimer.
37
*
38
* 2. Redistributions in binary form must reproduce the above copyright notice,
39
* this list of conditions and the following disclaimer in the documentation
40
* and/or other materials provided with the distribution.
41
*
42
* 3. All advertising materials mentioning features or use of this software must
43
* display the following acknowledgment:
44
* "This product includes software developed by Akira Iwata Laboratory,
45
* Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)."
46
*
47
* 4. Redistributions of any form whatsoever must retain the following
48
* acknowledgment:
49
* "This product includes software developed by Akira Iwata Laboratory,
50
* Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)."
51
*
52
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
53
* AKIRA IWATA LABORATORY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
54
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
55
* IN NO EVENT SHALL AKIRA IWATA LABORATORY BE LIABLE FOR ANY SPECIAL,
56
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
57
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
58
* NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION
59
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
60
*
61
*/
62
63
/* **************key generate & key display *******************/
64
const
int
Rcon0
[30] = {
65
0x01, 0x02, 0x04, 0x08,
66
0x10, 0x20, 0x40, 0x80,
67
0x1b, 0x36, 0x6c, 0xd8,
68
0xab, 0x4d, 0x9a, 0x2f,
69
0x5e, 0xbc, 0x63, 0xc6,
70
0x97, 0x35, 0x6a, 0xd4,
71
0xb3, 0x7d, 0xfa, 0xef,
72
0xc5, 0x91,
73
};
74
75
/* **************** key expand ************************ */
76
int
77
KeySchedule
(
int
type
,
int
key
[32])
78
{
79
int
nk,
nb
, round;
80
int
i, j, temp[4];
81
82
switch
(type)
83
{
84
case
128128:
85
nk = 4;
86
nb = 4;
87
round = 10;
88
break
;
89
case
128192:
90
nk = 4;
91
nb = 6;
92
round = 12;
93
break
;
94
case
128256:
95
nk = 4;
96
nb = 8;
97
round = 14;
98
break
;
99
case
192128:
100
nk = 6;
101
nb = 4;
102
round = 12;
103
break
;
104
case
192192:
105
nk = 6;
106
nb = 6;
107
round = 12;
108
break
;
109
case
192256:
110
nk = 6;
111
nb = 8;
112
round = 14;
113
break
;
114
case
256128:
115
nk = 8;
116
nb = 4;
117
round = 14;
118
break
;
119
case
256192:
120
nk = 8;
121
nb = 6;
122
round = 14;
123
break
;
124
case
256256:
125
nk = 8;
126
nb = 8;
127
round = 14;
128
break
;
129
default
:
130
return
-1;
131
}
132
for
(j = 0; j < nk; ++j)
133
for
(i = 0; i < 4; ++i)
134
/* 0 word */
135
word
[i][j] = key[i + j * 4];
136
137
/* expanded key is generated */
138
for
(j = nk; j < nb * (round + 1); ++j)
139
{
140
141
/* RotByte */
142
if
((j % nk) == 0)
143
{
144
temp[0] =
SubByte
(
word
[1][j - 1]) ^
Rcon0
[(j / nk) - 1];
145
temp[1] =
SubByte
(
word
[2][j - 1]);
146
temp[2] =
SubByte
(
word
[3][j - 1]);
147
temp[3] =
SubByte
(
word
[0][j - 1]);
148
}
149
if
((j % nk) != 0)
150
{
151
temp[0] =
word
[0][j - 1];
152
temp[1] =
word
[1][j - 1];
153
temp[2] =
word
[2][j - 1];
154
temp[3] =
word
[3][j - 1];
155
}
156
if
(nk > 6 && j % nk == 4)
157
for
(i = 0; i < 4; ++i)
158
temp[i] =
SubByte
(temp[i]);
159
for
(i = 0; i < 4; ++i)
160
word
[i][j] =
word
[i][j - nk] ^ temp[i];
161
}
162
return
0;
163
}
Rcon0
const int Rcon0[30]
Definition:
aes_key.c:64
test_panda.type
type
Definition:
test_panda.py:447
key
int key[32]
Definition:
aes.h:67
SubByte
int SubByte(int)
Definition:
aes_func.c:246
nb
int nb
Definition:
aes.h:65
KeySchedule
int KeySchedule(int type, int key[32])
Definition:
aes_key.c:77
word
short word
Definition:
private.h:30
Generated on Mon Feb 12 2024 13:02:48 for PandA-2024.02 by
1.8.13