summaryrefslogtreecommitdiffstats
path: root/all_pairs/source/rijndael_dec
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_dec
parent54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff)
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'all_pairs/source/rijndael_dec')
-rw-r--r--all_pairs/source/rijndael_dec/ChangeLog.txt58
-rw-r--r--all_pairs/source/rijndael_dec/aes.c406
-rw-r--r--all_pairs/source/rijndael_dec/aes.h165
-rw-r--r--all_pairs/source/rijndael_dec/aestab.h379
-rw-r--r--all_pairs/source/rijndael_dec/input_small_enc.c2051
-rw-r--r--all_pairs/source/rijndael_dec/rijndael_dec.c195
-rw-r--r--all_pairs/source/rijndael_dec/rijndael_dec_libc.c66
-rw-r--r--all_pairs/source/rijndael_dec/rijndael_dec_libc.h24
8 files changed, 3344 insertions, 0 deletions
diff --git a/all_pairs/source/rijndael_dec/ChangeLog.txt b/all_pairs/source/rijndael_dec/ChangeLog.txt
new file mode 100644
index 0000000..75e26a8
--- /dev/null
+++ b/all_pairs/source/rijndael_dec/ChangeLog.txt
@@ -0,0 +1,58 @@
1File: rijndael_decoder.c
2Source: security section of MiBench
3
4- Prefix library functions with rijndael_dec
5- Move functionality from function main into functions
6 rijndael_enc_init, rijndael_enc_main, and rijndael_enc_return
7 (reusing code from rijndael_enc benchmark)
8- Added general TACLeBench header to beginning of source code
9- Applied code formatting with astyle as in the example
10- Rename to rijndael_dec.c
11- Make loop counter in rijndael_dec_init unsigned
12- Remove dead code in rijndael_dec_decfile
13
14File: aes.h
15Source: security section of MiBench
16
172016-04-20:
18- Replace with file aes.h from rijndael_enc benchmark
19- Declare prototype for rijndael_enc_decrypt instead of rijndael_enc_encrypt
20
21File: aes.c
22Source: security section of MiBench
23
242016-04-20:
25- Replace with file aes.h from rijndael_enc benchmark, using prefix
26 rijndael_dec
27- Replace implementation for rijndael_enc_encrypt with implementation
28 for rijndael_enc_decrypt
29- Applied code formatting with astyle as in the example
30- Remove unused macros s, ff_poly, ff_hi, m1, m2, m3, FFmulX,
31 fwd_mcol, fwd_var, inv_var, si, so, fwd_rnd, inv_rnd, fwd_lrnd,
32 inv_lrnd, locals, l_copy, state_in, state_out, round
33
342016-06-14:
35- Added cast to make C++ compiler happy
36
37File: aestab.h
38Source: security section of MiBench
39
402016-04-20:
41- Replace with file aestab.h from rijndael_enc benchmark, using prefix
42 rijndael_dec
43- Remove unused arrays rijndael_dec_s_box, rijndael_dec_inv_s_box,
44 rijndael_dec_ft_tab
45
46Files: glibc_common.c, my_file.c, glibc_common.h, my_file.h
47Source: security section of MiBench
48
492016-04-20:
50- Replace with files rijndael_enc_libc.c and rijndael_enc_libc.h from
51 rijndael_enc benchmark (renamed to rijndael_dec_libc.c and
52 rijndael_dec_libc.h, using prefix rijndael_dec)
53
54File: input_small_enc.c
55Source: security section of MiBench
56
572016-02-26:
58- Prefix input array with rijndael_dec
diff --git a/all_pairs/source/rijndael_dec/aes.c b/all_pairs/source/rijndael_dec/aes.c
new file mode 100644
index 0000000..f47adfd
--- /dev/null
+++ b/all_pairs/source/rijndael_dec/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_dec_fl_tab,vf1,rf2,c)
43
44#define inv_mcol(x) four_tables(x,rijndael_dec_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_dec_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 cx->e_key[3] = word_in( in_key + 12 );
83
84 kf = cx->e_key;
85 kt = kf + nc * ( cx->Nrnd + 1 ) - cx->Nkey;
86 rci = 0;
87
88 switch ( cx->Nkey ) {
89 case 4:
90 _Pragma( "loopbound min 0 max 0" )
91 do {
92 kf[4] = kf[0] ^ ls_box( kf[3], 3 ) ^ rijndael_dec_rcon_tab[rci++];
93 kf[5] = kf[1] ^ kf[4];
94 kf[6] = kf[2] ^ kf[5];
95 kf[7] = kf[3] ^ kf[6];
96 kf += 4;
97 } while ( kf < kt );
98 break;
99
100 case 6:
101 cx->e_key[4] = word_in( in_key + 16 );
102 cx->e_key[5] = word_in( in_key + 20 );
103 _Pragma( "loopbound min 0 max 0" )
104 do {
105 kf[ 6] = kf[0] ^ ls_box( kf[5], 3 ) ^ rijndael_dec_rcon_tab[rci++];
106 kf[ 7] = kf[1] ^ kf[ 6];
107 kf[ 8] = kf[2] ^ kf[ 7];
108 kf[ 9] = kf[3] ^ kf[ 8];
109 kf[10] = kf[4] ^ kf[ 9];
110 kf[11] = kf[5] ^ kf[10];
111 kf += 6;
112 } while ( kf < kt );
113 break;
114
115 case 8:
116 cx->e_key[4] = word_in( in_key + 16 );
117 cx->e_key[5] = word_in( in_key + 20 );
118 cx->e_key[6] = word_in( in_key + 24 );
119 cx->e_key[7] = word_in( in_key + 28 );
120 _Pragma( "loopbound min 7 max 7" )
121 do {
122 kf[ 8] = kf[0] ^ ls_box( kf[7], 3 ) ^ rijndael_dec_rcon_tab[rci++];
123 kf[ 9] = kf[1] ^ kf[ 8];