mbed TLS v1.3.16
des.h
Go to the documentation of this file.
1 
24 #ifndef POLARSSL_DES_H
25 #define POLARSSL_DES_H
26 
27 #if !defined(POLARSSL_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include POLARSSL_CONFIG_FILE
31 #endif
32 
33 #include <stddef.h>
34 
35 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
36 #include <basetsd.h>
37 typedef UINT32 uint32_t;
38 #else
39 #include <inttypes.h>
40 #endif
41 
42 #define DES_ENCRYPT 1
43 #define DES_DECRYPT 0
44 
45 #define POLARSSL_ERR_DES_INVALID_INPUT_LENGTH -0x0032
47 #define DES_KEY_SIZE 8
48 
49 #if !defined(POLARSSL_DES_ALT)
50 // Regular implementation
51 //
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
60 typedef struct
61 {
62  int mode;
63  uint32_t sk[32];
64 }
66 
70 typedef struct
71 {
72  int mode;
73  uint32_t sk[96];
74 }
76 
82 void des_init( des_context *ctx );
83 
89 void des_free( des_context *ctx );
90 
96 void des3_init( des3_context *ctx );
97 
103 void des3_free( des3_context *ctx );
104 
113 void des_key_set_parity( unsigned char key[DES_KEY_SIZE] );
114 
125 int des_key_check_key_parity( const unsigned char key[DES_KEY_SIZE] );
126 
134 int des_key_check_weak( const unsigned char key[DES_KEY_SIZE] );
135 
144 int des_setkey_enc( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
145 
154 int des_setkey_dec( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
155 
165  const unsigned char key[DES_KEY_SIZE * 2] );
166 
176  const unsigned char key[DES_KEY_SIZE * 2] );
177 
187  const unsigned char key[DES_KEY_SIZE * 3] );
188 
198  const unsigned char key[DES_KEY_SIZE * 3] );
199 
209 int des_crypt_ecb( des_context *ctx,
210  const unsigned char input[8],
211  unsigned char output[8] );
212 
213 #if defined(POLARSSL_CIPHER_MODE_CBC)
214 
232 int des_crypt_cbc( des_context *ctx,
233  int mode,
234  size_t length,
235  unsigned char iv[8],
236  const unsigned char *input,
237  unsigned char *output );
238 #endif /* POLARSSL_CIPHER_MODE_CBC */
239 
249 int des3_crypt_ecb( des3_context *ctx,
250  const unsigned char input[8],
251  unsigned char output[8] );
252 
253 #if defined(POLARSSL_CIPHER_MODE_CBC)
254 
274 int des3_crypt_cbc( des3_context *ctx,
275  int mode,
276  size_t length,
277  unsigned char iv[8],
278  const unsigned char *input,
279  unsigned char *output );
280 #endif /* POLARSSL_CIPHER_MODE_CBC */
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 
286 #else /* POLARSSL_DES_ALT */
287 #include "des_alt.h"
288 #endif /* POLARSSL_DES_ALT */
289 
290 #ifdef __cplusplus
291 extern "C" {
292 #endif
293 
299 int des_self_test( int verbose );
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 
305 #endif /* des.h */
void des3_init(des3_context *ctx)
Initialize Triple-DES context.
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:72
Configuration options (set of defines)
DES context structure.
Definition: des.h:60
int des3_set3key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
void des3_free(des3_context *ctx)
Clear Triple-DES context.
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:70
int des3_set2key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, encryption)
void des_init(des_context *ctx)
Initialize DES context.
void des_key_set_parity(unsigned char key[DES_KEY_SIZE])
Set key parity on the given key to odd.
void des_free(des_context *ctx)
Clear DES context.
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:47
int mode
Definition: des.h:62
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