diff options
| author | Joshua Bakita <bakitajoshua@gmail.com> | 2019-10-07 19:13:39 -0400 |
|---|---|---|
| committer | Joshua Bakita <bakitajoshua@gmail.com> | 2019-10-07 19:13:39 -0400 |
| commit | 386b7d3366f1359a265da207a9cafa3edf553b64 (patch) | |
| tree | c76120c2c138faed822e4ae386be6ef22a738a78 /baseline/source/rijndael_enc | |
| parent | 54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff) | |
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'baseline/source/rijndael_enc')
| -rw-r--r-- | baseline/source/rijndael_enc/ChangeLog.txt | 98 | ||||
| -rw-r--r-- | baseline/source/rijndael_enc/aes.c | 406 | ||||
| -rw-r--r-- | baseline/source/rijndael_enc/aes.h | 165 | ||||
| -rw-r--r-- | baseline/source/rijndael_enc/aestab.h | 261 | ||||
| -rw-r--r-- | baseline/source/rijndael_enc/input_small.c | 1963 | ||||
| -rw-r--r-- | baseline/source/rijndael_enc/rijndael_enc.c | 238 | ||||
| -rw-r--r-- | baseline/source/rijndael_enc/rijndael_enc_libc.c | 66 | ||||
| -rw-r--r-- | baseline/source/rijndael_enc/rijndael_enc_libc.h | 24 |
8 files changed, 3221 insertions, 0 deletions
diff --git a/baseline/source/rijndael_enc/ChangeLog.txt b/baseline/source/rijndael_enc/ChangeLog.txt new file mode 100644 index 0000000..6ea9ed4 --- /dev/null +++ b/baseline/source/rijndael_enc/ChangeLog.txt | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | File: rijndael_encoder.c | ||
| 2 | Source: security section of MiBench | ||
| 3 | |||
| 4 | 2016-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 | |||
| 19 | 2016-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 | |||
| 25 | 2016-04-20: | ||
| 26 | - Cast "expected" return value to int for comparison | ||
| 27 | - Make loop counter in rijndael_enc_init unsigned | ||
| 28 | |||
| 29 | Files: aes.c, aes.h, aestab.h | ||
| 30 | Source: security section of MiBench | ||
| 31 | |||
| 32 | 2016-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 | |||
| 52 | 2016-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 | |||
| 60 | 2016-06-14: | ||
| 61 | - Added cast to make C++ compiler happy | ||
| 62 | |||
| 63 | Files: glibc_common.h, my_file.h | ||
| 64 | Source: security section of MiBench | ||
| 65 | |||
| 66 | 2016-02-26: | ||
| 67 | - Merge into file rijndael_enc_libc.h | ||
| 68 | |||
| 69 | File: rijndael_enc_libc.h | ||
| 70 | |||
| 71 | 2016-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 | |||
| 79 | Files: glibc_common.c, my_file.c | ||
| 80 | Source: security section of MiBench | ||
| 81 | |||
| 82 | 2016-02-26: | ||
| 83 | - Merge into file rijndael_enc_libc.c | ||
| 84 | |||
| 85 | File: rijndael_enc_libc.c | ||
| 86 | |||
| 87 | 2016-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 | |||
| 94 | File: input_small.c | ||
| 95 | Source: security section of MiBench | ||
| 96 | |||
| 97 | 2016-02-26: | ||
| 98 | - Break long lines | ||
diff --git a/baseline/source/rijndael_enc/aes.c b/baseline/source/rijndael_enc/aes.c new file mode 100644 index 0000000..c1282a7 --- /dev/null +++ b/baseline/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 | |||
| 66 | aes_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 | cx->e_key[3] = word_in( in_key + 12 ); | ||
