00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef MBEDTLS_DES_H
00030 #define MBEDTLS_DES_H
00031
00032 #if !defined(MBEDTLS_CONFIG_FILE)
00033 #include "config.h"
00034 #else
00035 #include MBEDTLS_CONFIG_FILE
00036 #endif
00037
00038 #include <stddef.h>
00039 #include <stdint.h>
00040
00041 #define MBEDTLS_DES_ENCRYPT 1
00042 #define MBEDTLS_DES_DECRYPT 0
00043
00044 #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
00045 #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
00047 #define MBEDTLS_DES_KEY_SIZE 8
00048
00049 #if !defined(MBEDTLS_DES_ALT)
00050
00051
00052
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056
00064 typedef struct
00065 {
00066 uint32_t sk[32];
00067 }
00068 mbedtls_des_context;
00069
00073 typedef struct
00074 {
00075 uint32_t sk[96];
00076 }
00077 mbedtls_des3_context;
00078
00088 void mbedtls_des_init( mbedtls_des_context *ctx );
00089
00099 void mbedtls_des_free( mbedtls_des_context *ctx );
00100
00106 void mbedtls_des3_init( mbedtls_des3_context *ctx );
00107
00113 void mbedtls_des3_free( mbedtls_des3_context *ctx );
00114
00127 void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00128
00143 int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00144
00156 int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00157
00170 int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00171
00184 int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00185
00194 int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
00195 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
00196
00205 int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
00206 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
00207
00216 int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
00217 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
00218
00227 int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
00228 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
00229
00243 int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
00244 const unsigned char input[8],
00245 unsigned char output[8] );
00246
00247 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00248
00270 int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
00271 int mode,
00272 size_t length,
00273 unsigned char iv[8],
00274 const unsigned char *input,
00275 unsigned char *output );
00276 #endif
00277
00287 int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
00288 const unsigned char input[8],
00289 unsigned char output[8] );
00290
00291 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00292
00312 int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
00313 int mode,
00314 size_t length,
00315 unsigned char iv[8],
00316 const unsigned char *input,
00317 unsigned char *output );
00318 #endif
00319
00332 void mbedtls_des_setkey( uint32_t SK[32],
00333 const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00334 #ifdef __cplusplus
00335 }
00336 #endif
00337
00338 #else
00339 #include "des_alt.h"
00340 #endif
00341
00342 #ifdef __cplusplus
00343 extern "C" {
00344 #endif
00345
00351 int mbedtls_des_self_test( int verbose );
00352
00353 #ifdef __cplusplus
00354 }
00355 #endif
00356
00357 #endif