PolarSSL v1.1.4
|
00001 00027 #ifndef POLARSSL_DES_H 00028 #define POLARSSL_DES_H 00029 00030 #include <string.h> 00031 00032 #define DES_ENCRYPT 1 00033 #define DES_DECRYPT 0 00034 00035 #define POLARSSL_ERR_DES_INVALID_INPUT_LENGTH -0x0032 00037 #define DES_KEY_SIZE 8 00038 00042 typedef struct 00043 { 00044 int mode; 00045 unsigned long sk[32]; 00046 } 00047 des_context; 00048 00052 typedef struct 00053 { 00054 int mode; 00055 unsigned long sk[96]; 00056 } 00057 des3_context; 00058 00059 #ifdef __cplusplus 00060 extern "C" { 00061 #endif 00062 00071 void des_key_set_parity( unsigned char key[DES_KEY_SIZE] ); 00072 00083 int des_key_check_key_parity( const unsigned char key[DES_KEY_SIZE] ); 00084 00092 int des_key_check_weak( const unsigned char key[DES_KEY_SIZE] ); 00093 00102 int des_setkey_enc( des_context *ctx, const unsigned char key[DES_KEY_SIZE] ); 00103 00112 int des_setkey_dec( des_context *ctx, const unsigned char key[DES_KEY_SIZE] ); 00113 00122 int des3_set2key_enc( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 2] ); 00123 00132 int des3_set2key_dec( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 2] ); 00133 00142 int des3_set3key_enc( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 3] ); 00143 00152 int des3_set3key_dec( des3_context *ctx, const unsigned char key[DES_KEY_SIZE * 3] ); 00153 00163 int des_crypt_ecb( des_context *ctx, 00164 const unsigned char input[8], 00165 unsigned char output[8] ); 00166 00177 int des_crypt_cbc( des_context *ctx, 00178 int mode, 00179 size_t length, 00180 unsigned char iv[8], 00181 const unsigned char *input, 00182 unsigned char *output ); 00183 00193 int des3_crypt_ecb( des3_context *ctx, 00194 const unsigned char input[8], 00195 unsigned char output[8] ); 00196 00209 int des3_crypt_cbc( des3_context *ctx, 00210 int mode, 00211 size_t length, 00212 unsigned char iv[8], 00213 const unsigned char *input, 00214 unsigned char *output ); 00215 00216 /* 00217 * \brief Checkup routine 00218 * 00219 * \return 0 if successful, or 1 if the test failed 00220 */ 00221 int des_self_test( int verbose ); 00222 00223 #ifdef __cplusplus 00224 } 00225 #endif 00226 00227 #endif /* des.h */