PolarSSL v1.3.8
des.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_DES_H
28 #define POLARSSL_DES_H
29 
30 #if !defined(POLARSSL_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include POLARSSL_CONFIG_FILE
34 #endif
35 
36 #include <string.h>
37 
38 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
39 #include <basetsd.h>
40 typedef UINT32 uint32_t;
41 #else
42 #include <inttypes.h>
43 #endif
44 
45 #define DES_ENCRYPT 1
46 #define DES_DECRYPT 0
47 
48 #define POLARSSL_ERR_DES_INVALID_INPUT_LENGTH -0x0032
50 #define DES_KEY_SIZE 8
51 
52 #if !defined(POLARSSL_DES_ALT)
53 // Regular implementation
54 //
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
63 typedef struct
64 {
65  int mode;
66  uint32_t sk[32];
67 }
69 
73 typedef struct
74 {
75  int mode;
76  uint32_t sk[96];
77 }
79 
85 void des_init( des_context *ctx );
86 
92 void des_free( des_context *ctx );
93 
99 void des3_init( des3_context *ctx );
100 
106 void des3_free( des3_context *ctx );
107 
116 void des_key_set_parity( unsigned char key[DES_KEY_SIZE] );
117 
128 int des_key_check_key_parity( const unsigned char key[DES_KEY_SIZE] );
129 
137 int des_key_check_weak( const unsigned char key[DES_KEY_SIZE] );
138 
147 int des_setkey_enc( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
148 
157 int des_setkey_dec( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
158 
168  const unsigned char key[DES_KEY_SIZE * 2] );
169 
179  const unsigned char key[DES_KEY_SIZE * 2] );
180 
190  const unsigned char key[DES_KEY_SIZE * 3] );
191 
201  const unsigned char key[DES_KEY_SIZE * 3] );
202 
212 int des_crypt_ecb( des_context *ctx,
213  const unsigned char input[8],
214  unsigned char output[8] );
215 
216 #if defined(POLARSSL_CIPHER_MODE_CBC)
217 
227 int des_crypt_cbc( des_context *ctx,
228  int mode,
229  size_t length,
230  unsigned char iv[8],
231  const unsigned char *input,
232  unsigned char *output );
233 #endif /* POLARSSL_CIPHER_MODE_CBC */
234 
244 int des3_crypt_ecb( des3_context *ctx,
245  const unsigned char input[8],
246  unsigned char output[8] );
247 
248 #if defined(POLARSSL_CIPHER_MODE_CBC)
249 
261 int des3_crypt_cbc( des3_context *ctx,
262  int mode,
263  size_t length,
264  unsigned char iv[8],
265  const unsigned char *input,
266  unsigned char *output );
267 #endif /* POLARSSL_CIPHER_MODE_CBC */
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 
273 #else /* POLARSSL_DES_ALT */
274 #include "des_alt.h"
275 #endif /* POLARSSL_DES_ALT */
276 
277 #ifdef __cplusplus
278 extern "C" {
279 #endif
280 
286 int des_self_test( int verbose );
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif /* des.h */