1 #ifndef __DES_CORE_H__ 2 #define __DES_CORE_H__ 3 4 #include <stdint.h> 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 #define ENCRYPT 1 11 #define DECRYPT 0 12 13 #define DES_BLOCK_SIZE 8 14 15 #ifdef OPENSSL_FIPS 16 #define FIPS_AES_SIZE_T int 17 #endif 18 19 /* zhangzj: make sure u64 is 8 bytes */ 20 #ifndef u32 21 22 #if defined(__arch64__) 23 #define U64(C) C##UL 24 #else 25 #define U64(C) C##ULL 26 #endif 27 28 typedef int64_t i64; 29 typedef uint64_t u64; 30 typedef uint32_t u32; 31 typedef uint16_t u16; 32 typedef uint8_t u8; 33 #endif 34 35 enum{ 36 DES_MODE_ECB = 0, 37 DES_MODE_CBC, 38 DES_MODE_OFB, 39 DES_MODE_CFB 40 }; 41 42 /** 43 * \brief DES context structure 44 */ 45 typedef struct 46 { 47 unsigned int sk[32]; /*!< DES subkeys */ 48 } 49 rk_des_context; 50 51 /** 52 * \brief Triple-DES context structure 53 */ 54 typedef struct 55 { 56 unsigned int sk[96]; /*!< 3DES subkeys */ 57 } 58 rk_des3_context; 59 60 int rk_des_setkey_enc( rk_des_context *ctx, const unsigned char key[DES_BLOCK_SIZE] ); 61 int rk_des_setkey_dec( rk_des_context *ctx, const unsigned char key[DES_BLOCK_SIZE] ); 62 int rk_des3_set2key_enc( rk_des3_context *ctx, 63 const unsigned char key[DES_BLOCK_SIZE * 2] ); 64 int rk_des3_set2key_dec( rk_des3_context *ctx, 65 const unsigned char key[DES_BLOCK_SIZE * 2] ); 66 int rk_des3_set3key_enc( rk_des3_context *ctx, 67 const unsigned char key[DES_BLOCK_SIZE * 3] ); 68 int rk_des3_set3key_dec( rk_des3_context *ctx, 69 const unsigned char key[DES_BLOCK_SIZE * 3] ); 70 int rk_des_crypt_ecb(const unsigned char input[8], 71 unsigned char output[8], void *ctx ); 72 73 int rk_des3_crypt_ecb(const unsigned char input[8], 74 unsigned char output[8], void *ctx); 75 76 typedef int (*block128_f)(const unsigned char input[8], 77 unsigned char output[8], void *ctx); 78 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif 85