Add phnxdeco with debian patch set (version 0.33-3).
[delutions.git] / tc / crypto / AesSmall.h
blobebeb24efd0fda8684e70ac6df4870aa959fcf718
1 /*
2 ---------------------------------------------------------------------------
3 Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
5 LICENSE TERMS
7 The free distribution and use of this software in both source and binary
8 form is allowed (with or without changes) provided that:
10 1. distributions of this source code include the above copyright
11 notice, this list of conditions and the following disclaimer;
13 2. distributions in binary form include the above copyright
14 notice, this list of conditions and the following disclaimer
15 in the documentation and/or other associated materials;
17 3. the copyright holder's name is not used to endorse products
18 built using this software without specific written permission.
20 ALTERNATIVELY, provided that this notice is retained in full, this product
21 may be distributed under the terms of the GNU General Public License (GPL),
22 in which case the provisions of the GPL apply INSTEAD OF those given above.
24 DISCLAIMER
26 This software is provided 'as is' with no explicit or implied warranties
27 in respect of its properties, including, but not limited to, correctness
28 and/or fitness for purpose.
29 ---------------------------------------------------------------------------
30 Issue 09/09/2006
32 This is an AES implementation that uses only 8-bit byte operations on the
33 cipher state.
36 #ifndef AES_H
37 #define AES_H
39 #if defined(__cplusplus)
40 extern "C"
42 #endif
44 /* This provides speed optimisation opportunities if 32-bit word
45 operations are available
47 #if 1
48 # define HAVE_UINT_32T
49 #endif
51 #if 1
52 # define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
53 #endif
54 #if 1
55 # define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
56 #endif
57 #if 0
58 # define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
59 #endif
60 #if 0
61 # define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
62 #endif
63 #if 0
64 # define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
65 #endif
66 #if 0
67 # define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
68 #endif
70 #define N_ROW 4
71 #define N_COL 4
72 #define N_BLOCK (N_ROW * N_COL)
73 #define N_MAX_ROUNDS 14
75 typedef unsigned char uint_8t;
77 typedef uint_8t return_type;
78 typedef uint_8t length_type;
79 typedef uint_8t uint_type;
81 typedef unsigned char uint_8t;
83 typedef struct
84 { uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
85 uint_8t rnd;
86 } aes_context;
88 /* The following calls are for a precomputed key schedule
90 NOTE: If the length_type used for the key length is an
91 unsigned 8-bit character, a key length of 256 bits must
92 be entered as a length in bytes (valid inputs are hence
93 128, 192, 16, 24 and 32).
96 #if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
98 return_type aes_set_key( const unsigned char key[],
99 length_type keylen,
100 aes_context ctx[1] );
101 #endif
103 #if defined( AES_ENC_PREKEYED )
105 return_type aes_encrypt( const unsigned char in[N_BLOCK],
106 unsigned char out[N_BLOCK],
107 const aes_context ctx[1] );
108 #endif
110 #if defined( AES_DEC_PREKEYED )
112 return_type aes_decrypt( const unsigned char in[N_BLOCK],
113 unsigned char out[N_BLOCK],
114 const aes_context ctx[1] );
115 #endif
117 /* The following calls are for 'on the fly' keying. In this case the
118 encryption and decryption keys are different.
120 The encryption subroutines take a key in an array of bytes in
121 key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
122 192, and 256 bits respectively. They then encrypts the input
123 data, in[] with this key and put the reult in the output array
124 out[]. In addition, the second key array, o_key[L], is used
125 to output the key that is needed by the decryption subroutine
126 to reverse the encryption operation. The two key arrays can
127 be the same array but in this case the original key will be
128 overwritten.
130 In the same way, the decryption subroutines output keys that
131 can be used to reverse their effect when used for encryption.
133 Only 128 and 256 bit keys are supported in these 'on the fly'
134 modes.
137 #if defined( AES_ENC_128_OTFK )
138 void aes_encrypt_128( const unsigned char in[N_BLOCK],
139 unsigned char out[N_BLOCK],
140 const unsigned char key[N_BLOCK],
141 uint_8t o_key[N_BLOCK] );
142 #endif
144 #if defined( AES_DEC_128_OTFK )
145 void aes_decrypt_128( const unsigned char in[N_BLOCK],
146 unsigned char out[N_BLOCK],
147 const unsigned char key[N_BLOCK],
148 unsigned char o_key[N_BLOCK] );
149 #endif
151 #if defined( AES_ENC_256_OTFK )
152 void aes_encrypt_256( const unsigned char in[N_BLOCK],
153 unsigned char out[N_BLOCK],
154 const unsigned char key[2 * N_BLOCK],
155 unsigned char o_key[2 * N_BLOCK] );
156 #endif
158 #if defined( AES_DEC_256_OTFK )
159 void aes_decrypt_256( const unsigned char in[N_BLOCK],
160 unsigned char out[N_BLOCK],
161 const unsigned char key[2 * N_BLOCK],
162 unsigned char o_key[2 * N_BLOCK] );
163 #endif
165 #if defined(__cplusplus)
167 #endif
169 #endif