PolarSSL v1.2.12
des.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_DES_H
28 #define POLARSSL_DES_H
29 
30 #include "config.h"
31 
32 #include <string.h>
33 
34 #ifdef _MSC_VER
35 #include <basetsd.h>
36 typedef UINT32 uint32_t;
37 #else
38 #include <inttypes.h>
39 #endif
40 
41 #define DES_ENCRYPT 1
42 #define DES_DECRYPT 0
43 
44 #define POLARSSL_ERR_DES_INVALID_INPUT_LENGTH -0x0032
46 #define DES_KEY_SIZE 8
47 
48 #if !defined(POLARSSL_DES_ALT)
49 // Regular implementation
50 //
51 
55 typedef struct
56 {
57  int mode;
58  uint32_t sk[32];
59 }
61 
65 typedef struct
66 {
67  int mode;
68  uint32_t sk[96];
69 }
71 
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75 
84 void des_key_set_parity( unsigned char key[DES_KEY_SIZE] );
85 
96 int des_key_check_key_parity( const unsigned char key[DES_KEY_SIZE] );
97 
105 int des_key_check_weak( const unsigned char key[DES_KEY_SIZE] );
106 
115 int des_setkey_enc( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
116 
125 int des_setkey_dec( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
126 
135 int des3_set2key_enc( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 2] );
136 
145 int des3_set2key_dec( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 2] );
146 
155 int des3_set3key_enc( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 3] );
156 
165 int des3_set3key_dec( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 3] );
166 
176 int des_crypt_ecb( des_context *ctx,
177  const unsigned char input[8],
178  unsigned char output[8] );
179 
190 int des_crypt_cbc( des_context *ctx,
191  int mode,
192  size_t length,
193  unsigned char iv[8],
194  const unsigned char *input,
195  unsigned char *output );
196 
206 int des3_crypt_ecb( des3_context *ctx,
207  const unsigned char input[8],
208  unsigned char output[8] );
209 
222 int des3_crypt_cbc( des3_context *ctx,
223  int mode,
224  size_t length,
225  unsigned char iv[8],
226  const unsigned char *input,
227  unsigned char *output );
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #else /* POLARSSL_DES_ALT */
234 #include "des_alt.h"
235 #endif /* POLARSSL_DES_ALT */
236 
237 #ifdef __cplusplus
238 extern "C" {
239 #endif
240 
246 int des_self_test( int verbose );
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #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:67
Configuration options (set of defines)
DES context structure.
Definition: des.h:55
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:65
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:46
int mode
Definition: des.h:57
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