diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2021-10-26 13:22:32 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2021-10-26 13:22:32 -0400 |
| commit | 14c854543b1a3cf344a371a5b45595657f95786b (patch) | |
| tree | 70f752880522e5e44669af365754ac0f649dce81 /baseline/source/rijndael_dec/rijndael_dec.c | |
| parent | 5e2ccfae0532ddd89bcc04bf14aad451e9c79785 (diff) | |
add deadlines and costs
Diffstat (limited to 'baseline/source/rijndael_dec/rijndael_dec.c')
| -rw-r--r-- | baseline/source/rijndael_dec/rijndael_dec.c | 194 |
1 files changed, 0 insertions, 194 deletions
diff --git a/baseline/source/rijndael_dec/rijndael_dec.c b/baseline/source/rijndael_dec/rijndael_dec.c deleted file mode 100644 index 5c0bea8..0000000 --- a/baseline/source/rijndael_dec/rijndael_dec.c +++ /dev/null | |||
| @@ -1,194 +0,0 @@ | |||
| 1 | /* | ||
| 2 | |||
| 3 | This program is part of the TACLeBench benchmark suite. | ||
| 4 | Version V 2.0 | ||
| 5 | |||
| 6 | Name: rijndael_enc | ||
| 7 | |||
| 8 | Author: Dr Brian Gladman | ||
| 9 | |||
| 10 | Function: rijndael_dec is an implementation of the AES decryption | ||
| 11 | algorithm (Rijndael). | ||
| 12 | |||
| 13 | Source: security section of MiBench | ||
| 14 | |||
| 15 | Changes: Add computation of a checksum, refactoring | ||
| 16 | |||
| 17 | License: see below | ||
| 18 | |||
| 19 | */ | ||
| 20 | |||
| 21 | /* | ||
| 22 | ----------------------------------------------------------------------- | ||
| 23 | Copyright (c) 2001 Dr Brian Gladman <brg@gladman.uk.net>, Worcester, UK | ||
| 24 | |||
| 25 | TERMS | ||
| 26 | |||
| 27 | Redistribution and use in source and binary forms, with or without | ||
| 28 | modification, are permitted provided that the following conditions | ||
| 29 | are met: | ||
| 30 | 1. Redistributions of source code must retain the above copyright | ||
| 31 | notice, this list of conditions and the following disclaimer. | ||
| 32 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 33 | notice, this list of conditions and the following disclaimer in the | ||
| 34 | documentation and/or other materials provided with the distribution. | ||
| 35 | |||
| 36 | This software is provided 'as is' with no guarantees of correctness or | ||
| 37 | fitness for purpose. | ||
| 38 | ----------------------------------------------------------------------- | ||
| 39 | */ | ||
| 40 | |||
| 41 | #include "extra.h" | ||
| 42 | #include "aes.h" | ||
| 43 | #include "rijndael_dec_libc.h" | ||
| 44 | |||
| 45 | /* | ||
| 46 | Global variable definitions | ||
| 47 | */ | ||
| 48 | unsigned char rijndael_dec_key[32]; | ||
| 49 | int rijndael_dec_key_len; | ||
| 50 | |||
| 51 | extern unsigned char rijndael_dec_data[]; | ||
| 52 | struct rijndael_dec_FILE rijndael_dec_fin; | ||
| 53 | |||
| 54 | int rijndael_dec_checksum = 0; | ||
| 55 | |||
| 56 | /* | ||
| 57 | Forward declaration of functions | ||
| 58 | */ | ||
| 59 | void rijndael_dec_init( void ); | ||
| 60 | int rijndael_dec_return( void ); | ||
| 61 | void rijndael_dec_fillrand( unsigned char *buf, int len ); | ||
| 62 | void rijndael_dec_decfile( struct rijndael_dec_FILE *fin, struct aes *ctx ); | ||
| 63 | void rijndael_dec_main( void ); | ||
| 64 | |||
| 65 | void rijndael_dec_init( void ) | ||
| 66 | { | ||
| 67 | /* create a pseudo-file for the input*/ | ||
| 68 | rijndael_dec_fin.data = rijndael_dec_data; | ||
| 69 | rijndael_dec_fin.size = 32768; | ||
| 70 | rijndael_dec_fin.cur_pos = 0; | ||
| 71 | rijndael_dec_checksum = 0; | ||
| 72 | |||
| 73 | unsigned i; | ||
| 74 | volatile int x = 0; | ||
| 75 | rijndael_dec_fin.size ^= x; | ||
| 76 | _Pragma( "loopbound min 32768 max 32768" ) | ||
| 77 | for ( i = 0; i < rijndael_dec_fin.size; i++ ) | ||
| 78 | rijndael_dec_fin.data[i] ^= x; | ||
| 79 | |||
| 80 | /* this is a pointer to the hexadecimal key digits */ | ||
| 81 | const volatile char *cp = | ||
| 82 | "1234567890abcdeffedcba09876543211234567890abcdeffedcba0987654321"; | ||
| 83 | char ch; | ||
| 84 | int by = 0; | ||
| 85 | |||
| 86 | i = 0; /* this is a count for the input digits processed */ | ||
| 87 | _Pragma( "loopbound min 64 max 64" ) | ||
| 88 | while ( i < 64 && *cp ) { /* the maximum key length is 32 bytes and */ | ||
| 89 | /* hence at most 64 hexadecimal digits */ | ||
| 90 | ch = rijndael_dec_toupper( *cp++ ); /* process a hexadecimal digit */ | ||
| 91 | if ( ch >= '0' && ch <= '9' ) | ||
| 92 | by = ( by << 4 ) + ch - '0'; | ||
| 93 | else | ||
| 94 | if ( ch >= 'A' && ch <= 'F' ) | ||
| 95 | by = ( by << 4 ) + ch - 'A' + 10; | ||
| 96 | else { /* error if not hexadecimal */ | ||
| 97 | rijndael_dec_checksum = -2; | ||
| 98 | return; | ||
| 99 | } | ||
| 100 | |||
| 101 | /* store a key byte for each pair of hexadecimal digits */ | ||
| 102 | if ( i++ & 1 ) | ||
| 103 | rijndael_dec_key[i / 2 - 1] = by & 0xff; | ||
| 104 | } | ||
| 105 | |||
| 106 | if ( *cp ) { | ||
| 107 | rijndael_dec_checksum = -3; | ||
| 108 | return; | ||
| 109 | } else | ||
| 110 | if ( i < 32 || ( i & 15 ) ) { | ||
| 111 | rijndael_dec_checksum = -4; | ||
| 112 | return; | ||
| 113 | } | ||
| 114 | |||
| 115 | rijndael_dec_key_len = i / 2; | ||
| 116 | } | ||
| 117 | |||
| 118 | int rijndael_dec_return( void ) | ||
| 119 | { | ||
| 120 | return ( ( rijndael_dec_checksum == ( int )262180 ) ? 0 : -1 ); | ||
| 121 | } | ||
| 122 | |||
| 123 | void rijndael_dec_decfile( struct rijndael_dec_FILE *fin, struct aes *ctx ) | ||
| 124 | { | ||
| 125 | unsigned char inbuf1[16], inbuf2[16], outbuf[16], *bp1, *bp2, *tp; | ||
| 126 | int i; | ||
| 127 | |||
| 128 | |||
| 129 | rijndael_dec_fread( inbuf1, 1, 16, fin ); | ||
| 130 | |||
| 131 | i = rijndael_dec_fread( inbuf2, 1, 16, | ||
| 132 | fin ); /* read 1st encrypted file block */ | ||
| 133 | |||
| 134 | if ( i && i != 16 ) { | ||
| 135 | rijndael_dec_checksum = -10; | ||
| 136 | return; | ||
| 137 | } | ||
| 138 | |||
| 139 | rijndael_dec_decrypt( inbuf2, outbuf, | ||
| 140 | ctx ); /* decrypt it */ | ||
| 141 | |||
| 142 | rijndael_dec_checksum += outbuf[15]; | ||
| 143 | |||
| 144 | _Pragma( "loopbound min 16 max 16" ) | ||
| 145 | for ( i = 0; i < 16; ++i ) /* xor with previous input */ | ||
| 146 | outbuf[i] ^= inbuf1[i]; | ||
| 147 | |||
| 148 | bp1 = inbuf1; /* set up pointers to two input buffers */ | ||
| 149 | bp2 = inbuf2; | ||
| 150 | |||
| 151 | /* TODO: this is necessarily an input-dependent loop bound */ | ||
| 152 | _Pragma( "loopbound min 19491 max 91491" ) | ||
| 153 | while ( 1 ) { | ||
| 154 | i = rijndael_dec_fread( bp1, 1, 16, fin ); /* read next encrypted block */ | ||
| 155 | /* to first input buffer */ | ||
| 156 | if ( i != 16 ) /* no more bytes in input - the decrypted */ | ||
| 157 | break; /* partial final buffer needs to be output */ | ||
| 158 | |||
| 159 | /* if a block has been read the previous block must have been */ | ||
| 160 | /* full lnegth so we can now write it out */ | ||
| 161 | |||
| 162 | rijndael_dec_decrypt( bp1, outbuf, ctx ); /* decrypt the new input block and */ | ||
| 163 | |||
| 164 | rijndael_dec_checksum += outbuf[15]; | ||
| 165 | |||
| 166 | _Pragma( "loopbound min 16 max 16" ) | ||
| 167 | for ( i = 0; i < 16; ++i ) /* xor it with previous input block */ | ||
| 168 | outbuf[i] ^= bp2[i]; | ||
| 169 | |||
| 170 | /* swap buffer pointers */ | ||
| 171 | tp = bp1, bp1 = bp2, bp2 = tp; | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | void _Pragma( "entrypoint" ) rijndael_dec_main( void ) | ||
| 176 | { | ||
| 177 | struct aes ctx[1]; | ||
| 178 | |||
| 179 | /* decryption in Cipher Block Chaining mode */ | ||
| 180 | rijndael_dec_set_key( rijndael_dec_key, rijndael_dec_key_len, dec, ctx ); | ||
| 181 | rijndael_dec_decfile( &rijndael_dec_fin, ctx ); | ||
| 182 | } | ||
| 183 | |||
| 184 | int main(int argc, char** argv) | ||
| 185 | { | ||
| 186 | SET_UP | ||
| 187 | for_each_job { | ||
| 188 | rijndael_dec_init(); | ||
| 189 | rijndael_dec_main(); | ||
| 190 | } | ||
| 191 | WRITE_TO_FILE | ||
