license change, XYSSL upgrade
[syren.git] / src / xyssl / des.h
blobf118eac4efc805e53eb27b0823f0c860fdc3ab7a
1 /**
2 * \file des.h
3 */
4 #ifndef XYSSL_DES_H
5 #define XYSSL_DES_H
7 #define DES_ENCRYPT 1
8 #define DES_DECRYPT 0
10 /**
11 * \brief DES context structure
13 typedef struct
15 int mode; /*!< encrypt/decrypt */
16 unsigned long sk[32]; /*!< DES subkeys */
18 des_context;
20 /**
21 * \brief Triple-DES context structure
23 typedef struct
25 int mode; /*!< encrypt/decrypt */
26 unsigned long sk[96]; /*!< 3DES subkeys */
28 des3_context;
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 /**
35 * \brief DES key schedule (56-bit, encryption)
37 * \param ctx DES context to be initialized
38 * \param key 8-byte secret key
40 void des_setkey_enc( des_context *ctx, unsigned char key[8] );
42 /**
43 * \brief DES key schedule (56-bit, decryption)
45 * \param ctx DES context to be initialized
46 * \param key 8-byte secret key
48 void des_setkey_dec( des_context *ctx, unsigned char key[8] );
50 /**
51 * \brief Triple-DES key schedule (112-bit, encryption)
53 * \param ctx 3DES context to be initialized
54 * \param key 16-byte secret key
56 void des3_set2key_enc( des3_context *ctx, unsigned char key[16] );
58 /**
59 * \brief Triple-DES key schedule (112-bit, decryption)
61 * \param ctx 3DES context to be initialized
62 * \param key 16-byte secret key
64 void des3_set2key_dec( des3_context *ctx, unsigned char key[16] );
66 /**
67 * \brief Triple-DES key schedule (168-bit, encryption)
69 * \param ctx 3DES context to be initialized
70 * \param key 24-byte secret key
72 void des3_set3key_enc( des3_context *ctx, unsigned char key[24] );
74 /**
75 * \brief Triple-DES key schedule (168-bit, decryption)
77 * \param ctx 3DES context to be initialized
78 * \param key 24-byte secret key
80 void des3_set3key_dec( des3_context *ctx, unsigned char key[24] );
82 /**
83 * \brief DES-ECB block encryption/decryption
85 * \param ctx DES context
86 * \param input 64-bit input block
87 * \param output 64-bit output block
89 void des_crypt_ecb( des_context *ctx,
90 unsigned char input[8],
91 unsigned char output[8] );
93 /**
94 * \brief DES-CBC buffer encryption/decryption
96 * \param ctx DES context
97 * \param mode DES_ENCRYPT or DES_DECRYPT
98 * \param length length of the input data
99 * \param iv initialization vector (updated after use)
100 * \param input buffer holding the input data
101 * \param output buffer holding the output data
103 void des_crypt_cbc( des_context *ctx,
104 int mode,
105 int length,
106 unsigned char iv[8],
107 unsigned char *input,
108 unsigned char *output );
111 * \brief 3DES-ECB block encryption/decryption
113 * \param ctx 3DES context
114 * \param input 64-bit input block
115 * \param output 64-bit output block
117 void des3_crypt_ecb( des3_context *ctx,
118 unsigned char input[8],
119 unsigned char output[8] );
122 * \brief 3DES-CBC buffer encryption/decryption
124 * \param ctx 3DES context
125 * \param mode DES_ENCRYPT or DES_DECRYPT
126 * \param length length of the input data
127 * \param iv initialization vector (updated after use)
128 * \param input buffer holding the input data
129 * \param output buffer holding the output data
131 void des3_crypt_cbc( des3_context *ctx,
132 int mode,
133 int length,
134 unsigned char iv[8],
135 unsigned char *input,
136 unsigned char *output );
139 * \brief Checkup routine
141 * \return 0 if successful, or 1 if the test failed
143 int des_self_test( int verbose );
145 #ifdef __cplusplus
147 #endif
149 #endif /* des.h */