00001
00027 #ifndef POLARSSL_DES_H
00028 #define POLARSSL_DES_H
00029
00030 #include "config.h"
00031
00032 #include <string.h>
00033
00034 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
00035 #include <basetsd.h>
00036 typedef UINT32 uint32_t;
00037 #else
00038 #include <inttypes.h>
00039 #endif
00040
00041 #define DES_ENCRYPT 1
00042 #define DES_DECRYPT 0
00043
00044 #define POLARSSL_ERR_DES_INVALID_INPUT_LENGTH -0x0032
00046 #define DES_KEY_SIZE 8
00047
00048 #if !defined(POLARSSL_DES_ALT)
00049
00050
00051
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055
00059 typedef struct
00060 {
00061 int mode;
00062 uint32_t sk[32];
00063 }
00064 des_context;
00065
00069 typedef struct
00070 {
00071 int mode;
00072 uint32_t sk[96];
00073 }
00074 des3_context;
00075
00084 void des_key_set_parity( unsigned char key[DES_KEY_SIZE] );
00085
00096 int des_key_check_key_parity( const unsigned char key[DES_KEY_SIZE] );
00097
00105 int des_key_check_weak( const unsigned char key[DES_KEY_SIZE] );
00106
00115 int des_setkey_enc( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
00116
00125 int des_setkey_dec( des_context *ctx, const unsigned char key[DES_KEY_SIZE] );
00126
00135 int des3_set2key_enc( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 2] );
00136
00145 int des3_set2key_dec( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 2] );
00146
00155 int des3_set3key_enc( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 3] );
00156
00165 int des3_set3key_dec( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 3] );
00166
00176 int des_crypt_ecb( des_context *ctx,
00177 const unsigned char input[8],
00178 unsigned char output[8] );
00179
00180 #if defined(POLARSSL_CIPHER_MODE_CBC)
00181
00191 int des_crypt_cbc( des_context *ctx,
00192 int mode,
00193 size_t length,
00194 unsigned char iv[8],
00195 const unsigned char *input,
00196 unsigned char *output );
00197 #endif
00198
00208 int des3_crypt_ecb( des3_context *ctx,
00209 const unsigned char input[8],
00210 unsigned char output[8] );
00211
00212 #if defined(POLARSSL_CIPHER_MODE_CBC)
00213
00225 int des3_crypt_cbc( des3_context *ctx,
00226 int mode,
00227 size_t length,
00228 unsigned char iv[8],
00229 const unsigned char *input,
00230 unsigned char *output );
00231 #endif
00232
00233 #ifdef __cplusplus
00234 }
00235 #endif
00236
00237 #else
00238 #include "des_alt.h"
00239 #endif
00240
00241 #ifdef __cplusplus
00242 extern "C" {
00243 #endif
00244
00250 int des_self_test( int verbose );
00251
00252 #ifdef __cplusplus
00253 }
00254 #endif
00255
00256 #endif