summaryrefslogtreecommitdiffstats
path: root/all_pairs/source/rijndael_enc
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
commit386b7d3366f1359a265da207a9cafa3edf553b64 (patch)
treec76120c2c138faed822e4ae386be6ef22a738a78 /all_pairs/source/rijndael_enc
parent54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff)
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'all_pairs/source/rijndael_enc')
-rw-r--r--all_pairs/source/rijndael_enc/ChangeLog.txt98
-rw-r--r--all_pairs/source/rijndael_enc/aes.c406
-rw-r--r--all_pairs/source/rijndael_enc/aes.h165
-rw-r--r--all_pairs/source/rijndael_enc/aestab.h261
-rw-r--r--all_pairs/source/rijndael_enc/input_small.c1963
-rw-r--r--all_pairs/source/rijndael_enc/rijndael_enc.c238
-rw-r--r--all_pairs/source/rijndael_enc/rijndael_enc_libc.c66
-rw-r--r--all_pairs/source/rijndael_enc/rijndael_enc_libc.h24
8 files changed, 3221 insertions, 0 deletions
diff --git a/all_pairs/source/rijndael_enc/ChangeLog.txt b/all_pairs/source/rijndael_enc/ChangeLog.txt
new file mode 100644
index 0000000..6ea9ed4
--- /dev/null
+++ b/all_pairs/source/rijndael_enc/ChangeLog.txt
@@ -0,0 +1,98 @@
1File: rijndael_encoder.c
2Source: security section of MiBench
3
42016-02-26:
5- Remove commented-out code
6- Prefix functions with "rijndael_enc"
7- Compute a checksum and return it from main
8- Change return type of rijndael_enc_encfile to void
9- Move functionality from function main into functions
10 rijndael_enc_init, rijndael_enc_main, and rijndael_enc_return
11- Reordered functions in source code: initialization- and
12 return-value-related functions first, followed by algorithm core
13 functions, followed by main functions
14- Added function prototypes
15- Applied code formatting with astyle as in the example
16- Added general TACLeBench header to beginning of source code
17- Rename to rijndael_enc.c
18
192016-03-15:
20- Return 0 if checksum is as expected, -1 otherwise
21- Add entrypoint pragma
22- Make inputs volatile (or touch them with a volatile) to rule out
23 optimizations
24
252016-04-20:
26- Cast "expected" return value to int for comparison
27- Make loop counter in rijndael_enc_init unsigned
28
29Files: aes.c, aes.h, aestab.h
30Source: security section of MiBench
31
322016-02-26:
33- Remove unused defines UNROLL, PARTIAL_UNROLL
34- Remove defines FIXED_TABLES, FF_TABLES, ARRAYS, FOUR_TABLES,
35 FOUR_LR_TABLES, FOUR_IM_TABLES
36- Remove (undefined) define ONE_TABLE, ONE_LR_TABLE , ONE_IM_TABLE
37- Assume BLOCK_SIZE is always 16
38- Remove unused define "unused"
39- Remove INTERNAL_BYTE_ORDER, EXTERNAL_BYTE_ORDER, AES_BIG_ENDIAN,
40 AES_LITTLE_ENDIAN (assume internal == external == little endian)
41- Remove defines AES_DLL and AES_IN_CPP
42- Remove "#if defined(__cplusplus)"
43- Replace macros c_name and cf_dec with their definition
44- Remove some stale comments
45- Remove defines no_table and one_table
46- Remove prototypes for unusedfunctions decrypt and set_blk
47- Prefix all functions and global variables with "rijndael_enc"
48- Break lines in overly long macros
49- Protect macros
50- Applied code formatting with astyle as in the example
51
522016-04-20:
53- Remove unused macros s, ff_poly, ff_hi, m1, m2, m3, FFmulX,
54 fwd_mcol, fwd_var, inv_var, si, so, fwd_rnd, inv_rnd, fwd_lrnd,
55 inv_lrnd, locals, l_copy, state_in, state_out, round, i_table,
56 li_table
57- Remove unused arrays rijndael_enc_s_box, rijndael_enc_inv_s_box,
58 rijndael_enc_it_tab, rijndael_enc_il_tab
59
602016-06-14:
61- Added cast to make C++ compiler happy
62
63Files: glibc_common.h, my_file.h
64Source: security section of MiBench
65
662016-02-26:
67- Merge into file rijndael_enc_libc.h
68
69File: rijndael_enc_libc.h
70
712016-02-26:
72- Replace size_x with unsigned long
73- Remove defines LITTLE_ENDIAN and NULL
74- Prefix all functions with "rijndael_enc" (instead of "my_")
75- Prefix definitions that clash with the standard library with
76 "rijndael_enc" (instead of "my_")
77- Applied code formatting with astyle as in the example
78
79Files: glibc_common.c, my_file.c
80Source: security section of MiBench
81
822016-02-26:
83- Merge into file rijndael_enc_libc.c
84
85File: rijndael_enc_libc.c
86
872016-02-26:
88- Replace size_x with unsigned long
89- Prefix all functions with "rijndael_enc" (instead of "my_")
90- Prefix definitions that clash with the standard library with
91 "rijndael_enc" (instead of "my_")
92- Applied code formatting with astyle as in the example
93
94File: input_small.c
95Source: security section of MiBench
96
972016-02-26:
98- Break long lines
diff --git a/all_pairs/source/rijndael_enc/aes.c b/all_pairs/source/rijndael_enc/aes.c
new file mode 100644
index 0000000..c1282a7
--- /dev/null
+++ b/all_pairs/source/rijndael_enc/aes.c
@@ -0,0 +1,406 @@
1/*
2 -----------------------------------------------------------------------
3 Copyright (c) 2001 Dr Brian Gladman <brg@gladman.uk.net>, Worcester, UK
4
5 TERMS
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 This software is provided 'as is' with no guarantees of correctness or
17 fitness for purpose.
18 -----------------------------------------------------------------------
19
20 FUNCTION
21
22 The AES algorithm Rijndael implemented for block and key sizes of 128,
23 bits (16 bytes) by Brian Gladman.
24
25 This is an implementation of the AES encryption algorithm (Rijndael)
26 designed by Joan Daemen and Vincent Rijmen.
27*/
28
29#include "aes.h"
30
31#include "aestab.h"
32
33#define four_tables(x,tab,vf,rf,c) ( tab[0][bval(vf(x,0,c),rf(0,c))] ^ \
34 tab[1][bval(vf(x,1,c),rf(1,c))] ^ \
35 tab[2][bval(vf(x,2,c),rf(2,c))] ^ \
36 tab[3][bval(vf(x,3,c),rf(3,c))] )
37
38#define vf1(x,r,c) (x)
39#define rf1(r,c) (r)
40#define rf2(r,c) ((r-c)&3)
41
42#define ls_box(x,c) four_tables(x,rijndael_enc_fl_tab,vf1,rf2,c)
43
44#define inv_mcol(x) four_tables(x,rijndael_enc_im_tab,vf1,rf1,0)
45
46/*
47 Subroutine to set the block size (if variable) in bytes, legal
48 values being 16, 24 and 32.
49*/
50
51#define nc (Ncol)
52
53/*
54 Initialise the key schedule from the user supplied key. The key
55 length is now specified in bytes - 16, 24 or 32 as appropriate.
56 This corresponds to bit lengths of 128, 192 and 256 bits, and
57 to Nk values of 4, 6 and 8 respectively.
58*/
59
60#define mx(t,f) (*t++ = inv_mcol(*f),f++)
61#define cp(t,f) *t++ = *f++
62
63#define cpy(d,s) do { cp(d,s); cp(d,s); cp(d,s); cp(d,s); } while (0)
64#define mix(d,s) do { mx(d,s); mx(d,s); mx(d,s); mx(d,s); } while (0)
65
66aes_ret rijndael_enc_set_key( byte in_key[], const word n_bytes,
67 const enum aes_key f, struct aes *cx )
68{
69 word *kf, *kt, rci;
70
71 if ( ( n_bytes & 7 ) || n_bytes < 16 || n_bytes > 32 || ( !( f & 1 ) &&
72 !( f & 2 ) ) )
73 return ( n_bytes ? cx->mode &= ~0x03, aes_bad : ( aes_ret )( cx->Nkey << 2 ) );
74
75 cx->mode = ( cx->mode & ~0x03 ) | ( ( byte )f & 0x03 );
76 cx->Nkey = n_bytes >> 2;
77 cx->Nrnd = Nr( cx->Nkey, ( word )nc );
78
79 cx->e_key[0] = word_in( in_key );
80 cx->e_key[1] = word_in( in_key + 4 );
81 cx->e_key[2] = word_in( in_key + 8 );
82