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
00055
00056 #ifndef MBEDTLS_DES_H
00057 #define MBEDTLS_DES_H
00058
00059 #if !defined(MBEDTLS_CONFIG_FILE)
00060 #include "config.h"
00061 #else
00062 #include MBEDTLS_CONFIG_FILE
00063 #endif
00064
00065 #include <stddef.h>
00066 #include <stdint.h>
00067
00068 #define MBEDTLS_DES_ENCRYPT 1
00069 #define MBEDTLS_DES_DECRYPT 0
00070
00071 #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032
00072 #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033
00074 #define MBEDTLS_DES_KEY_SIZE 8
00075
00076 #if !defined(MBEDTLS_DES_ALT)
00077
00078
00079
00080 #ifdef __cplusplus
00081 extern "C" {
00082 #endif
00083
00091 typedef struct
00092 {
00093 uint32_t sk[32];
00094 }
00095 mbedtls_des_context;
00096
00100 typedef struct
00101 {
00102 uint32_t sk[96];
00103 }
00104 mbedtls_des3_context;
00105
00115 void mbedtls_des_init( mbedtls_des_context *ctx );
00116
00126 void mbedtls_des_free( mbedtls_des_context *ctx );
00127
00133 void mbedtls_des3_init( mbedtls_des3_context *ctx );
00134
00140 void mbedtls_des3_free( mbedtls_des3_context *ctx );
00141
00154 void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00155
00170 int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00171
00183 int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00184
00197 int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00198
00211 int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00212
00221 int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
00222 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
00223
00232 int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
00233 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
00234
00243 int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
00244 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
00245
00254 int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
00255 const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
00256
00270 int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
00271 const unsigned char input[8],
00272 unsigned char output[8] );
00273
00274 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00275
00297 int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
00298 int mode,
00299 size_t length,
00300 unsigned char iv[8],
00301 const unsigned char *input,
00302 unsigned char *output );
00303 #endif
00304
00314 int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
00315 const unsigned char input[8],
00316 unsigned char output[8] );
00317
00318 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00319
00339 int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
00340 int mode,
00341 size_t length,
00342 unsigned char iv[8],
00343 const unsigned char *input,
00344 unsigned char *output );
00345 #endif
00346
00359 void mbedtls_des_setkey( uint32_t SK[32],
00360 const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
00361 #ifdef __cplusplus
00362 }
00363 #endif
00364
00365 #else
00366 #include "des_alt.h"
00367 #endif
00368
00369 #ifdef __cplusplus
00370 extern "C" {
00371 #endif
00372
00378 int mbedtls_des_self_test( int verbose );
00379
00380 #ifdef __cplusplus
00381 }
00382 #endif
00383
00384 #endif