PolarSSL v1.3.7
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 
88 void des_key_set_parity( unsigned char key[DES_KEY_SIZE] );
89 
100 int des_key_check_key_parity( const unsigned char key[DES_KEY_SIZE] );
101 
109 int des_key_check_weak( const unsigned char key[DES_KEY_SIZE] );
110 
119 int des_setkey_enc( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
120 
129 int des_setkey_dec( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
130 
140  const unsigned char key[DES_KEY_SIZE * 2] );
141 
151  const unsigned char key[DES_KEY_SIZE * 2] );
152 
162  const unsigned char key[DES_KEY_SIZE * 3] );
163 
173  const unsigned char key[DES_KEY_SIZE * 3] );
174 
184 int des_crypt_ecb( des_context *ctx,
185  const unsigned char input[8],
186  unsigned char output[8] );
187 
188 #if defined(POLARSSL_CIPHER_MODE_CBC)
189 
199 int des_crypt_cbc( des_context *ctx,
200  int mode,
201  size_t length,
202  unsigned char iv[8],
203  const unsigned char *input,
204  unsigned char *output );
205 #endif /* POLARSSL_CIPHER_MODE_CBC */
206 
216 int des3_crypt_ecb( des3_context *ctx,
217  const unsigned char input[8],
218  unsigned char output[8] );
219 
220 #if defined(POLARSSL_CIPHER_MODE_CBC)
221 
233 int des3_crypt_cbc( des3_context *ctx,
234  int mode,
235  size_t length,
236  unsigned char iv[8],
237  const unsigned char *input,
238  unsigned char *output );
239 #endif /* POLARSSL_CIPHER_MODE_CBC */
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #else /* POLARSSL_DES_ALT */
246 #include "des_alt.h"
247 #endif /* POLARSSL_DES_ALT */
248 
249 #ifdef __cplusplus
250 extern "C" {
251 #endif
252 
258 int des_self_test( int verbose );
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #endif /* des.h */
int des_self_test(int verbose)
Checkup routine.
int des_crypt_ecb(des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
int mode
Definition: des.h:75
Configuration options (set of defines)
DES context structure.
Definition: des.h:63
int des3_set3key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
int des3_set3key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, decryption)
Triple-DES context structure.
Definition: des.h:73
int des3_set2key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, encryption)
void des_key_set_parity(unsigned char key[DES_KEY_SIZE])
Set key parity on the given key to odd.
int des_crypt_cbc(des_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
DES-CBC buffer encryption/decryption.
int des_setkey_enc(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, encryption)
int des_setkey_dec(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, decryption)
int des3_crypt_ecb(des3_context *ctx, const unsigned char input[8], unsigned char output[8])
3DES-ECB block encryption/decryption
int des_key_check_weak(const unsigned char key[DES_KEY_SIZE])
Check that key is not a weak or semi-weak DES key.
#define DES_KEY_SIZE
Definition: des.h:50
int mode
Definition: des.h:65
int des_key_check_key_parity(const unsigned char key[DES_KEY_SIZE])
Check that key parity on the given key is odd.
int des3_set2key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, decryption)
int des3_crypt_cbc(des3_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
3DES-CBC buffer encryption/decryption