Adds DAHDI support alongside Zaptel. DAHDI usage favored, but all Zap stuff should...
[asterisk-bristuff.git] / include / asterisk / aes.h
blobaf648e8eeacffd0794b3db881542475d4d5f2dc4
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * See http://www.asterisk.org for more information about
5 * the Asterisk project. Please do not directly contact
6 * any of the maintainers of this project for assistance;
7 * the project provides a web site, mailing lists and IRC
8 * channels for your use.
9 */
12 ---------------------------------------------------------------------------
13 Copyright (c) 2003, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
14 All rights reserved.
16 LICENSE TERMS
18 The free distribution and use of this software in both source and binary
19 form is allowed (with or without changes) provided that:
21 1. distributions of this source code include the above copyright
22 notice, this list of conditions and the following disclaimer;
24 2. distributions in binary form include the above copyright
25 notice, this list of conditions and the following disclaimer
26 in the documentation and/or other associated materials;
28 3. the copyright holder's name is not used to endorse products
29 built using this software without specific written permission.
31 ALTERNATIVELY, provided that this notice is retained in full, this product
32 may be distributed under the terms of the GNU General Public License (GPL),
33 in which case the provisions of the GPL apply INSTEAD OF those given above.
35 DISCLAIMER
37 This software is provided 'as is' with no explicit or implied warranties
38 in respect of its properties, including, but not limited to, correctness
39 and/or fitness for purpose.
40 ---------------------------------------------------------------------------
41 Issue Date: 26/08/2003
43 /*!\file
45 \brief This file contains the definitions required to use AES in C. See aesopt.h
46 for optimisation details.
49 #ifndef _AES_H
50 #define _AES_H
52 /* This include is used to find 8 & 32 bit unsigned integer types */
53 #include "limits.h"
55 #if defined(__cplusplus)
56 extern "C"
58 #endif
60 #define AES_128 /* define if AES with 128 bit keys is needed */
61 #undef AES_192 /* define if AES with 192 bit keys is needed */
62 #undef AES_256 /* define if AES with 256 bit keys is needed */
63 #undef AES_VAR /* define if a variable key size is needed */
65 /* The following must also be set in assembler files if being used */
67 #define AES_ENCRYPT /* if support for encryption is needed */
68 #define AES_DECRYPT /* if support for decryption is needed */
69 #define AES_ERR_CHK /* for parameter checks & error return codes */
71 #if UCHAR_MAX == 0xff /* an unsigned 8 bit type */
72 typedef unsigned char aes_08t;
73 #else
74 #error Please define aes_08t as an 8-bit unsigned integer type in aes.h
75 #endif
77 #if UINT_MAX == 0xffffffff /* an unsigned 32 bit type */
78 typedef unsigned int aes_32t;
79 #elif ULONG_MAX == 0xffffffff
80 typedef unsigned long aes_32t;
81 #else
82 #error Please define aes_32t as a 32-bit unsigned integer type in aes.h
83 #endif
85 #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
86 #define N_COLS 4 /* the number of columns in the state */
88 /* a maximum of 60 32-bit words are needed for the key schedule but */
89 /* 64 are claimed to allow space at the top for a CBC xor buffer. */
90 /* If this is not needed, this value can be reduced to 60. A value */
91 /* of 64 may also help in maintaining alignment in some situations */
92 #define KS_LENGTH 64
94 #ifdef AES_ERR_CHK
95 #define aes_ret int
96 #define aes_good 0
97 #define aes_error -1
98 #else
99 #define aes_ret void
100 #endif
102 #ifndef AES_DLL /* implement normal/DLL functions */
103 #define aes_rval aes_ret
104 #else
105 #define aes_rval aes_ret __declspec(dllexport) _stdcall
106 #endif
108 /* This routine must be called before first use if non-static */
109 /* tables are being used */
111 void gen_tabs(void);
113 /* The key length (klen) is input in bytes when it is in the range */
114 /* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */
116 #ifdef AES_ENCRYPT
118 typedef struct
119 { aes_32t ks[KS_LENGTH];
120 } aes_encrypt_ctx;
122 #if defined(AES_128) || defined(AES_VAR)
123 aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx[1]);
124 #endif
126 #if defined(AES_192) || defined(AES_VAR)
127 aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx[1]);
128 #endif
130 #if defined(AES_256) || defined(AES_VAR)
131 aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx[1]);
132 #endif
134 #if defined(AES_VAR)
135 aes_rval aes_encrypt_key(const void *in_key, int key_len, aes_encrypt_ctx cx[1]);
136 #endif
138 aes_rval aes_encrypt(const void *in_blk, void *out_blk, const aes_encrypt_ctx cx[1]);
139 #endif
141 #ifdef AES_DECRYPT
143 typedef struct
144 { aes_32t ks[KS_LENGTH];
145 } aes_decrypt_ctx;
147 #if defined(AES_128) || defined(AES_VAR)
148 aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx[1]);
149 #endif
151 #if defined(AES_192) || defined(AES_VAR)
152 aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1]);
153 #endif
155 #if defined(AES_256) || defined(AES_VAR)
156 aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx[1]);
157 #endif
159 #if defined(AES_VAR)
160 aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx[1]);
161 #endif
163 aes_rval aes_decrypt(const void *in_blk, void *out_blk, const aes_decrypt_ctx cx[1]);
164 #endif
166 #if defined(__cplusplus)
168 #endif
170 #endif