PolarSSL v1.3.1
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 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
59 typedef struct
60 {
61  int mode;
62  uint32_t sk[32];
63 }
65 
69 typedef struct
70 {
71  int mode;
72  uint32_t sk[96];
73 }
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 
180 #if defined(POLARSSL_CIPHER_MODE_CBC)
181 
191 int des_crypt_cbc( des_context *ctx,
192  int mode,
193  size_t length,
194  unsigned char iv[8],
195  const unsigned char *input,
196  unsigned char *output );
197 #endif /* POLARSSL_CIPHER_MODE_CBC */
198 
208 int des3_crypt_ecb( des3_context *ctx,
209  const unsigned char input[8],
210  unsigned char output[8] );
211 
212 #if defined(POLARSSL_CIPHER_MODE_CBC)
213 
225 int des3_crypt_cbc( des3_context *ctx,
226  int mode,
227  size_t length,
228  unsigned char iv[8],
229  const unsigned char *input,
230  unsigned char *output );
231 #endif /* POLARSSL_CIPHER_MODE_CBC */
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #else /* POLARSSL_DES_ALT */
238 #include "des_alt.h"
239 #endif /* POLARSSL_DES_ALT */
240 
241 #ifdef __cplusplus
242 extern "C" {
243 #endif
244 
250 int des_self_test( int verbose );
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif /* des.h */