00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef MBEDTLS_DES_H
00055 #define MBEDTLS_DES_H
00056
00057 #if !defined(MBEDTLS_CONFIG_FILE)
00058 #include "config.h"
00059 #else
00060 #include MBEDTLS_CONFIG_FILE
00061 #endif
00062
00063 #include <stddef.h>
00064 #include <stdint.h>
00065
00066 #define MBEDTLS_DES_ENCRYPT 1
00067 #define MBEDTLS_DES_DECRYPT 0
00068
00069 #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
00070 #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
00072 #define MBEDTLS_DES_KEY_SIZE 8
00073
00074 #if !defined(MBEDTLS_DES_ALT)
00075
00076
00077
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081
00089 typedef struct
00090 {
00091 uint32_t sk[32];
00092 }
00093 mbedtls_des_context;
00094
00098 typedef struct
00099 {
00100 uint32_t sk[96];
00101 }
00102 mbedtls_des3_context;
00103
00113 void mbedtls_des_init( mbedtls_des_context *ctx );
00114
00124 void mbedtls_des_free( mbedtls_des_context *ctx );
00125
00131 void mbedtls_des3_init( mbedtls_des3_context *ctx );
00132
00138 void mbedtls_des3_free( mbedtls_des3_context *ctx );
00139
00152 void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00153
00168 int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00169
00181 int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00182
00195 int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00196
00209 int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00210
00219 int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
00220 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
00221
00230 int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
00231 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
00232
00241 int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
00242 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
00243
00252 int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
00253 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
00254
00268 int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
00269 const unsigned char input[8],
00270 unsigned char output[8] );
00271
00272 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00273
00295 int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
00296 int mode,
00297 size_t length,
00298 unsigned char iv[8],
00299 const unsigned char *input,
00300 unsigned char *output );
00301 #endif
00302
00312 int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
00313 const unsigned char input[8],
00314 unsigned char output[8] );
00315
00316 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00317
00337 int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
00338 int mode,
00339 size_t length,
00340 unsigned char iv[8],
00341 const unsigned char *input,
00342 unsigned char *output );
00343 #endif
00344
00357 void mbedtls_des_setkey( uint32_t SK[32],
00358 const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00359 #ifdef __cplusplus
00360 }
00361 #endif
00362
00363 #else
00364 #include "des_alt.h"
00365 #endif
00366
00367 #ifdef __cplusplus
00368 extern "C" {
00369 #endif
00370
00376 int mbedtls_des_self_test( int verbose );
00377
00378 #ifdef __cplusplus
00379 }
00380 #endif
00381
00382 #endif