aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/CHStone/aes/aes_enc.c
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/CHStone/aes/aes_enc.c')
-rwxr-xr-xbenchmarks/CHStone/aes/aes_enc.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/benchmarks/CHStone/aes/aes_enc.c b/benchmarks/CHStone/aes/aes_enc.c
new file mode 100755
index 0000000..edeb665
--- /dev/null
+++ b/benchmarks/CHStone/aes/aes_enc.c
@@ -0,0 +1,130 @@
+/*
++--------------------------------------------------------------------------+
+| CHStone : a suite of benchmark programs for C-based High-Level Synthesis |
+| ======================================================================== |
+| |
+| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, |
+| H. Takada and K. Ishii |
+| Nagoya University, Japan |
+| |
+| * Remark : |
+| 1. This source code is modified to unify the formats of the benchmark |
+| programs in CHStone. |
+| 2. Test vectors are added for CHStone. |
+| 3. If "main_result" is 0 at the end of the program, the program is |
+| correctly executed. |
+| 4. Please follow the copyright of each benchmark program. |
++--------------------------------------------------------------------------+
+*/
+/* aes_enc.c */
+/*
+ * Copyright (C) 2005
+ * Akira Iwata & Masayuki Sato
+ * Akira Iwata Laboratory,
+ * Nagoya Institute of Technology in Japan.
+ *
+ * All rights reserved.
+ *
+ * This software is written by Masayuki Sato.
+ * And if you want to contact us, send an email to Kimitake Wakayama
+ * (wakayama@elcom.nitech.ac.jp)
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software must
+ * display the following acknowledgment:
+ * "This product includes software developed by Akira Iwata Laboratory,
+ * Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)."
+ *
+ * 4. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by Akira Iwata Laboratory,
+ * Nagoya Institute of Technology in Japan (http://mars.elcom.nitech.ac.jp/)."
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
+ * AKIRA IWATA LABORATORY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
+ * IN NO EVENT SHALL AKIRA IWATA LABORATORY BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+/* ******* encrypto ************ */
+int
+encrypt (int statemt[32], int key[32], int type)
+{
+ int i;
+/*
++--------------------------------------------------------------------------+
+| * Test Vector (added for CHStone) |
+| out_enc_statemt : expected output data for "encrypt" |
++--------------------------------------------------------------------------+
+*/
+ const int out_enc_statemt[16] =
+ { 0x39, 0x25, 0x84, 0x1d, 0x2, 0xdc, 0x9, 0xfb, 0xdc, 0x11, 0x85, 0x97,
+ 0x19, 0x6a, 0xb, 0x32
+ };
+
+ KeySchedule (type, key);
+ switch (type)
+ {
+ case 128128:
+ round_val = 0;
+ nb = 4;
+ break;
+ case 192128:
+ round_val = 2;
+ nb = 4;
+ break;
+ case 256128:
+ round_val = 4;
+ nb = 4;
+ break;
+ case 128192:
+ case 192192:
+ round_val = 2;
+ nb = 6;
+ break;
+ case 256192:
+ round_val = 4;
+ nb = 6;
+ break;
+ case 128256:
+ case 192256:
+ case 256256:
+ round_val = 4;
+ nb = 8;
+ break;
+ }
+ AddRoundKey (statemt, type, 0);
+ for (i = 1; i <= round_val + 9; ++i)
+ {
+ ByteSub_ShiftRow (statemt, nb);
+ MixColumn_AddRoundKey (statemt, nb, i);
+ }
+ ByteSub_ShiftRow (statemt, nb);
+ AddRoundKey (statemt, type, i);
+
+ printf ("encrypted message \t");
+ for (i = 0; i < nb * 4; ++i)
+ {
+ if (statemt[i] < 16)
+ printf ("0");
+ printf ("%x", statemt[i]);
+ }
+
+ for (i = 0; i < 16; i++)
+ main_result += (statemt[i] != out_enc_statemt[i]);
+
+ return 0;
+}