PandA-2024.02
aes_dec.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_dec.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 extern void __builtin_bambu_time_start();
64 extern void __builtin_bambu_time_stop();
65 
66 int
67 __attribute__ ((noinline))
68 decrypt (int statemt[32], int key[32], int type)
69 {
70  int i;
71  /*
72  +--------------------------------------------------------------------------+
73  | * Test Vector (added for CHStone) |
74  | out_enc_statemt : expected output data for "decrypt" |
75  +--------------------------------------------------------------------------+
76  */
77  const int out_dec_statemt[16] =
78  { 0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2,
79  0xe0, 0x37, 0x7, 0x34
80  };
82  KeySchedule (type, key);
83 
84  switch (type)
85  {
86  case 128128:
87  i_round = 10;
88  nb = 4;
89  break;
90  case 128192:
91  case 192192:
92  i_round = 12;
93  nb = 6;
94  break;
95  case 192128:
96  i_round = 12;
97  nb = 4;
98  break;
99  case 128256:
100  case 192256:
101  i_round = 14;
102  nb = 8;
103  break;
104  case 256128:
105  i_round = 14;
106  nb = 4;
107  break;
108  case 256192:
109  i_round = 14;
110  nb = 6;
111  break;
112  case 256256:
113  i_round = 14;
114  nb = 8;
115  break;
116  }
117 
118  AddRoundKey (statemt, type, i_round);
119 
120  InversShiftRow_ByteSub (statemt, nb);
121 
122  for (i = i_round - 1; i >= 1; --i)
123  {
124  AddRoundKey_InversMixColumn (statemt, nb, i);
125  InversShiftRow_ByteSub (statemt, nb);
126  }
127 
128  AddRoundKey (statemt, type, 0);
129 
130  printf ("\ndecrypto message\t");
131  for (i = 0; i < ((type % 1000) / 8); ++i)
132  {
133  if (statemt[i] < 16)
134  printf ("0");
135  printf ("%x", statemt[i]);
136  }
137 
138  for (i = 0; i < 16; i++)
139  main_result += (statemt[i] != out_dec_statemt[i]);
140 
142  return 0;
143 }
void __builtin_bambu_time_stop()
int AddRoundKey(int *, int, int)
int main_result
Definition: mips.c:38
int KeySchedule(int, int *)
int __attribute__((noinline))
Definition: aes_dec.c:67
void __builtin_bambu_time_start()
int key[32]
Definition: aes.h:67
int decrypt(int statemt[32], int key[32], int type)
Definition: aes_dec.c:63
int statemt[32]
Definition: aes.h:68
void InversShiftRow_ByteSub(int *, int)
int nb
Definition: aes.h:65
int AddRoundKey_InversMixColumn(int *, int, int)
int i_round
Definition: aes.h:66

Generated on Mon Feb 12 2024 13:02:48 for PandA-2024.02 by doxygen 1.8.13