PolarSSL v1.3.4
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 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
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 */
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:71
Configuration options (set of defines)
DES context structure.
Definition: des.h:59
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:69
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:61
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