Skip to content
Newer
Older
100644 141 lines (128 sloc) 4.26 KB
ff4b830 @ckolivas Import aes and sha2 libraries from polarssl code.
authored
1 /**
2 * \file aes.h
3 *
bc86829 @ckolivas Modify aes and sha from polar to build into lrzip.
authored
4 * Copyright (C) 2011, Con Kolivas <kernel@kolivas.org>
ff4b830 @ckolivas Import aes and sha2 libraries from polarssl code.
authored
5 * Copyright (C) 2006-2010, Brainspark B.V.
6 *
7 * This file is part of PolarSSL (http://www.polarssl.org)
8 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26 #ifndef POLARSSL_AES_H
27 #define POLARSSL_AES_H
28
29 #define AES_ENCRYPT 1
30 #define AES_DECRYPT 0
31
32 #define POLARSSL_ERR_AES_INVALID_KEY_LENGTH -0x0800
33 #define POLARSSL_ERR_AES_INVALID_INPUT_LENGTH -0x0810
34
35 /**
36 * \brief AES context structure
37 */
38 typedef struct
39 {
40 int nr; /*!< number of rounds */
41 unsigned long *rk; /*!< AES round keys */
42 unsigned long buf[68]; /*!< unaligned data */
43 }
44 aes_context;
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /**
51 * \brief AES key schedule (encryption)
52 *
53 * \param ctx AES context to be initialized
54 * \param key encryption key
55 * \param keysize must be 128, 192 or 256
56 *
57 * \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
58 */
59 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize );
60
61 /**
62 * \brief AES key schedule (decryption)
63 *
64 * \param ctx AES context to be initialized
65 * \param key decryption key
66 * \param keysize must be 128, 192 or 256
67 *
68 * \return 0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
69 */
70 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize );
71
72 /**
73 * \brief AES-ECB block encryption/decryption
74 *
75 * \param ctx AES context
76 * \param mode AES_ENCRYPT or AES_DECRYPT
77 * \param input 16-byte input block
78 * \param output 16-byte output block
79 *
80 * \return 0 if successful
81 */
82 int aes_crypt_ecb( aes_context *ctx,
83 int mode,
84 const unsigned char input[16],
85 unsigned char output[16] );
86
87 /**
88 * \brief AES-CBC buffer encryption/decryption
89 * Length should be a multiple of the block
90 * size (16 bytes)
91 *
92 * \param ctx AES context
93 * \param mode AES_ENCRYPT or AES_DECRYPT
94 * \param length length of the input data
95 * \param iv initialization vector (updated after use)
96 * \param input buffer holding the input data
97 * \param output buffer holding the output data
98 *
99 * \return 0 if successful, or POLARSSL_ERR_AES_INVALID_INPUT_LENGTH
100 */
101 int aes_crypt_cbc( aes_context *ctx,
102 int mode,
b302e6b @ckolivas Better make length a long long int in aes_crypt_cbc just in case.
authored
103 long long int length,
ff4b830 @ckolivas Import aes and sha2 libraries from polarssl code.
authored
104 unsigned char iv[16],
105 const unsigned char *input,
106 unsigned char *output );
107
108 /**
109 * \brief AES-CFB128 buffer encryption/decryption.
110 *
111 * \param ctx AES context
112 * \param mode AES_ENCRYPT or AES_DECRYPT
113 * \param length length of the input data
114 * \param iv_off offset in IV (updated after use)
115 * \param iv initialization vector (updated after use)
116 * \param input buffer holding the input data
117 * \param output buffer holding the output data
118 *
119 * \return 0 if successful
120 */
121 int aes_crypt_cfb128( aes_context *ctx,
122 int mode,
123 int length,
124 int *iv_off,
125 unsigned char iv[16],
126 const unsigned char *input,
127 unsigned char *output );
128
129 /**
130 * \brief Checkup routine
131 *
132 * \return 0 if successful, or 1 if the test failed
133 */
134 int aes_self_test( int verbose );
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* aes.h */
Something went wrong with that request. Please try again.