53#if !defined(MBEDTLS_CONFIG_FILE)
56#include MBEDTLS_CONFIG_FILE
59#if defined(MBEDTLS_DES_C)
66#if defined(MBEDTLS_SELF_TEST)
67#if defined(MBEDTLS_PLATFORM_C)
71#define mbedtls_printf printf
75#if !defined(MBEDTLS_DES_ALT)
81#define GET_UINT32_BE(n,b,i) \
83 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
84 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
85 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
86 | ( (uint32_t) (b)[(i) + 3] ); \
91#define PUT_UINT32_BE(n,b,i) \
93 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
94 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
95 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
96 (b)[(i) + 3] = (unsigned char) ( (n) ); \
105 0x01010400, 0x00000000, 0x00010000, 0x01010404,
106 0x01010004, 0x00010404, 0x00000004, 0x00010000,
107 0x00000400, 0x01010400, 0x01010404, 0x00000400,
108 0x01000404, 0x01010004, 0x01000000, 0x00000004,
109 0x00000404, 0x01000400, 0x01000400, 0x00010400,
110 0x00010400, 0x01010000, 0x01010000, 0x01000404,
111 0x00010004, 0x01000004, 0x01000004, 0x00010004,
112 0x00000000, 0x00000404, 0x00010404, 0x01000000,
113 0x00010000, 0x01010404, 0x00000004, 0x01010000,
114 0x01010400, 0x01000000, 0x01000000, 0x00000400,
115 0x01010004, 0x00010000, 0x00010400, 0x01000004,
116 0x00000400, 0x00000004, 0x01000404, 0x00010404,
117 0x01010404, 0x00010004, 0x01010000, 0x01000404,
118 0x01000004, 0x00000404, 0x00010404, 0x01010400,
119 0x00000404, 0x01000400, 0x01000400, 0x00000000,
120 0x00010004, 0x00010400, 0x00000000, 0x01010004
125 0x80108020, 0x80008000, 0x00008000, 0x00108020,
126 0x00100000, 0x00000020, 0x80100020, 0x80008020,
127 0x80000020, 0x80108020, 0x80108000, 0x80000000,
128 0x80008000, 0x00100000, 0x00000020, 0x80100020,
129 0x00108000, 0x00100020, 0x80008020, 0x00000000,
130 0x80000000, 0x00008000, 0x00108020, 0x80100000,
131 0x00100020, 0x80000020, 0x00000000, 0x00108000,
132 0x00008020, 0x80108000, 0x80100000, 0x00008020,
133 0x00000000, 0x00108020, 0x80100020, 0x00100000,
134 0x80008020, 0x80100000, 0x80108000, 0x00008000,
135 0x80100000, 0x80008000, 0x00000020, 0x80108020,
136 0x00108020, 0x00000020, 0x00008000, 0x80000000,
137 0x00008020, 0x80108000, 0x00100000, 0x80000020,
138 0x00100020, 0x80008020, 0x80000020, 0x00100020,
139 0x00108000, 0x00000000, 0x80008000, 0x00008020,
140 0x80000000, 0x80100020, 0x80108020, 0x00108000
145 0x00000208, 0x08020200, 0x00000000, 0x08020008,
146 0x08000200, 0x00000000, 0x00020208, 0x08000200,
147 0x00020008, 0x08000008, 0x08000008, 0x00020000,
148 0x08020208, 0x00020008, 0x08020000, 0x00000208,
149 0x08000000, 0x00000008, 0x08020200, 0x00000200,
150 0x00020200, 0x08020000, 0x08020008, 0x00020208,
151 0x08000208, 0x00020200, 0x00020000, 0x08000208,
152 0x00000008, 0x08020208, 0x00000200, 0x08000000,
153 0x08020200, 0x08000000, 0x00020008, 0x00000208,
154 0x00020000, 0x08020200, 0x08000200, 0x00000000,
155 0x00000200, 0x00020008, 0x08020208, 0x08000200,
156 0x08000008, 0x00000200, 0x00000000, 0x08020008,
157 0x08000208, 0x00020000, 0x08000000, 0x08020208,
158 0x00000008, 0x00020208, 0x00020200, 0x08000008,
159 0x08020000, 0x08000208, 0x00000208, 0x08020000,
160 0x00020208, 0x00000008, 0x08020008, 0x00020200
165 0x00802001, 0x00002081, 0x00002081, 0x00000080,
166 0x00802080, 0x00800081, 0x00800001, 0x00002001,
167 0x00000000, 0x00802000, 0x00802000, 0x00802081,
168 0x00000081, 0x00000000, 0x00800080, 0x00800001,
169 0x00000001, 0x00002000, 0x00800000, 0x00802001,
170 0x00000080, 0x00800000, 0x00002001, 0x00002080,
171 0x00800081, 0x00000001, 0x00002080, 0x00800080,
172 0x00002000, 0x00802080, 0x00802081, 0x00000081,
173 0x00800080, 0x00800001, 0x00802000, 0x00802081,
174 0x00000081, 0x00000000, 0x00000000, 0x00802000,
175 0x00002080, 0x00800080, 0x00800081, 0x00000001,
176 0x00802001, 0x00002081, 0x00002081, 0x00000080,
177 0x00802081, 0x00000081, 0x00000001, 0x00002000,
178 0x00800001, 0x00002001, 0x00802080, 0x00800081,
179 0x00002001, 0x00002080, 0x00800000, 0x00802001,
180 0x00000080, 0x00800000, 0x00002000, 0x00802080
185 0x00000100, 0x02080100, 0x02080000, 0x42000100,
186 0x00080000, 0x00000100, 0x40000000, 0x02080000,
187 0x40080100, 0x00080000, 0x02000100, 0x40080100,
188 0x42000100, 0x42080000, 0x00080100, 0x40000000,
189 0x02000000, 0x40080000, 0x40080000, 0x00000000,
190 0x40000100, 0x42080100, 0x42080100, 0x02000100,
191 0x42080000, 0x40000100, 0x00000000, 0x42000000,
192 0x02080100, 0x02000000, 0x42000000, 0x00080100,
193 0x00080000, 0x42000100, 0x00000100, 0x02000000,
194 0x40000000, 0x02080000, 0x42000100, 0x40080100,
195 0x02000100, 0x40000000, 0x42080000, 0x02080100,
196 0x40080100, 0x00000100, 0x02000000, 0x42080000,
197 0x42080100, 0x00080100, 0x42000000, 0x42080100,
198 0x02080000, 0x00000000, 0x40080000, 0x42000000,
199 0x00080100, 0x02000100, 0x40000100, 0x00080000,
200 0x00000000, 0x40080000, 0x02080100, 0x40000100
205 0x20000010, 0x20400000, 0x00004000, 0x20404010,
206 0x20400000, 0x00000010, 0x20404010, 0x00400000,
207 0x20004000, 0x00404010, 0x00400000, 0x20000010,
208 0x00400010, 0x20004000, 0x20000000, 0x00004010,
209 0x00000000, 0x00400010, 0x20004010, 0x00004000,
210 0x00404000, 0x20004010, 0x00000010, 0x20400010,
211 0x20400010, 0x00000000, 0x00404010, 0x20404000,
212 0x00004010, 0x00404000, 0x20404000, 0x20000000,
213 0x20004000, 0x00000010, 0x20400010, 0x00404000,
214 0x20404010, 0x00400000, 0x00004010, 0x20000010,
215 0x00400000, 0x20004000, 0x20000000, 0x00004010,
216 0x20000010, 0x20404010, 0x00404000, 0x20400000,
217 0x00404010, 0x20404000, 0x00000000, 0x20400010,
218 0x00000010, 0x00004000, 0x20400000, 0x00404010,
219 0x00004000, 0x00400010, 0x20004010, 0x00000000,
220 0x20404000, 0x20000000, 0x00400010, 0x20004010
225 0x00200000, 0x04200002, 0x04000802, 0x00000000,
226 0x00000800, 0x04000802, 0x00200802, 0x04200800,
227 0x04200802, 0x00200000, 0x00000000, 0x04000002,
228 0x00000002, 0x04000000, 0x04200002, 0x00000802,
229 0x04000800, 0x00200802, 0x00200002, 0x04000800,
230 0x04000002, 0x04200000, 0x04200800, 0x00200002,
231 0x04200000, 0x00000800, 0x00000802, 0x04200802,
232 0x00200800, 0x00000002, 0x04000000, 0x00200800,
233 0x04000000, 0x00200800, 0x00200000, 0x04000802,
234 0x04000802, 0x04200002, 0x04200002, 0x00000002,
235 0x00200002, 0x04000000, 0x04000800, 0x00200000,
236 0x04200800, 0x00000802, 0x00200802, 0x04200800,
237 0x00000802, 0x04000002, 0x04200802, 0x04200000,
238 0x00200800, 0x00000000, 0x00000002, 0x04200802,
239 0x00000000, 0x00200802, 0x04200000, 0x00000800,
240 0x04000002, 0x04000800, 0x00000800, 0x00200002
245 0x10001040, 0x00001000, 0x00040000, 0x10041040,
246 0x10000000, 0x10001040, 0x00000040, 0x10000000,
247 0x00040040, 0x10040000, 0x10041040, 0x00041000,
248 0x10041000, 0x00041040, 0x00001000, 0x00000040,
249 0x10040000, 0x10000040, 0x10001000, 0x00001040,
250 0x00041000, 0x00040040, 0x10040040, 0x10041000,
251 0x00001040, 0x00000000, 0x00000000, 0x10040040,
252 0x10000040, 0x10001000, 0x00041040, 0x00040000,
253 0x00041040, 0x00040000, 0x10041000, 0x00001000,
254 0x00000040, 0x10040040, 0x00001000, 0x00041040,
255 0x10001000, 0x00000040, 0x10000040, 0x10040000,
256 0x10040040, 0x10000000, 0x00040000, 0x10001040,
257 0x00000000, 0x10041040, 0x00040040, 0x10000040,
258 0x10040000, 0x10001000, 0x10001040, 0x00000000,
259 0x10041040, 0x00041000, 0x00041000, 0x00001040,
260 0x00001040, 0x00040040, 0x10000000, 0x10041000
268 0x00000000, 0x00000001, 0x00000100, 0x00000101,
269 0x00010000, 0x00010001, 0x00010100, 0x00010101,
270 0x01000000, 0x01000001, 0x01000100, 0x01000101,
271 0x01010000, 0x01010001, 0x01010100, 0x01010101
276 0x00000000, 0x01000000, 0x00010000, 0x01010000,
277 0x00000100, 0x01000100, 0x00010100, 0x01010100,
278 0x00000001, 0x01000001, 0x00010001, 0x01010001,
279 0x00000101, 0x01000101, 0x00010101, 0x01010101,
288 T = (((X) >> 4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T << 4); \
289 T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
290 T = (((Y) >> 2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T << 2); \
291 T = (((Y) >> 8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T << 8); \
292 (Y) = (((Y) << 1) | ((Y) >> 31)) & 0xFFFFFFFF; \
293 T = ((X) ^ (Y)) & 0xAAAAAAAA; (Y) ^= T; (X) ^= T; \
294 (X) = (((X) << 1) | ((X) >> 31)) & 0xFFFFFFFF; \
303 (X) = (((X) << 31) | ((X) >> 1)) & 0xFFFFFFFF; \
304 T = ((X) ^ (Y)) & 0xAAAAAAAA; (X) ^= T; (Y) ^= T; \
305 (Y) = (((Y) << 31) | ((Y) >> 1)) & 0xFFFFFFFF; \
306 T = (((Y) >> 8) ^ (X)) & 0x00FF00FF; (X) ^= T; (Y) ^= (T << 8); \
307 T = (((Y) >> 2) ^ (X)) & 0x33333333; (X) ^= T; (Y) ^= (T << 2); \
308 T = (((X) >> 16) ^ (Y)) & 0x0000FFFF; (Y) ^= T; (X) ^= (T << 16); \
309 T = (((X) >> 4) ^ (Y)) & 0x0F0F0F0F; (Y) ^= T; (X) ^= (T << 4); \
315#define DES_ROUND(X,Y) \
319 (Y) ^= SB8[ (T ) & 0x3F ] ^ \
320 SB6[ (T >> 8) & 0x3F ] ^ \
321 SB4[ (T >> 16) & 0x3F ] ^ \
322 SB2[ (T >> 24) & 0x3F ]; \
324 T = *SK++ ^ (((X) << 28) | ((X) >> 4)); \
325 (Y) ^= SB7[ (T ) & 0x3F ] ^ \
326 SB5[ (T >> 8) & 0x3F ] ^ \
327 SB3[ (T >> 16) & 0x3F ] ^ \
328 SB1[ (T >> 24) & 0x3F ]; \
334 uint32_t t = (a); (a) = (b); (b) = t; t = 0; \
363static const unsigned char odd_parity_table[128] = { 1, 2, 4, 7, 8,
364 11, 13, 14, 16, 19, 21, 22, 25, 26, 28, 31, 32, 35, 37, 38, 41, 42, 44,
365 47, 49, 50, 52, 55, 56, 59, 61, 62, 64, 67, 69, 70, 73, 74, 76, 79, 81,
366 82, 84, 87, 88, 91, 93, 94, 97, 98, 100, 103, 104, 107, 109, 110, 112,
367 115, 117, 118, 121, 122, 124, 127, 128, 131, 133, 134, 137, 138, 140,
368 143, 145, 146, 148, 151, 152, 155, 157, 158, 161, 162, 164, 167, 168,
369 171, 173, 174, 176, 179, 181, 182, 185, 186, 188, 191, 193, 194, 196,
370 199, 200, 203, 205, 206, 208, 211, 213, 214, 217, 218, 220, 223, 224,
371 227, 229, 230, 233, 234, 236, 239, 241, 242, 244, 247, 248, 251, 253,
379 key[
i] = odd_parity_table[
key[
i] / 2];
390 if(
key[
i] != odd_parity_table[
key[
i] / 2] )
417#define WEAK_KEY_COUNT 16
421 { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
422 { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
423 { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
424 { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
426 { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
427 { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
428 { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
429 { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
430 { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
431 { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
432 { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
433 { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
434 { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
435 { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
436 { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
437 { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
444 for(
i = 0;
i < WEAK_KEY_COUNT;
i++ )
451#if !defined(MBEDTLS_DES_SETKEY_ALT)
457 GET_UINT32_BE(
X,
key, 0 );
458 GET_UINT32_BE(
Y,
key, 4 );
463 T = ((
Y >> 4) ^
X) & 0x0F0F0F0F;
X ^=
T;
Y ^= (
T << 4);
464 T = ((
Y ) ^
X) & 0x10101010;
X ^=
T;
Y ^= (
T );
466 X = (LHs[ (
X ) & 0xF] << 3) | (LHs[ (
X >> 8) & 0xF ] << 2)
467 | (LHs[ (
X >> 16) & 0xF] << 1) | (LHs[ (
X >> 24) & 0xF ] )
468 | (LHs[ (
X >> 5) & 0xF] << 7) | (LHs[ (
X >> 13) & 0xF ] << 6)
469 | (LHs[ (
X >> 21) & 0xF] << 5) | (LHs[ (
X >> 29) & 0xF ] << 4);
471 Y = (RHs[ (
Y >> 1) & 0xF] << 3) | (RHs[ (
Y >> 9) & 0xF ] << 2)
472 | (RHs[ (
Y >> 17) & 0xF] << 1) | (RHs[ (
Y >> 25) & 0xF ] )
473 | (RHs[ (
Y >> 4) & 0xF] << 7) | (RHs[ (
Y >> 12) & 0xF ] << 6)
474 | (RHs[ (
Y >> 20) & 0xF] << 5) | (RHs[ (
Y >> 28) & 0xF ] << 4);
482 for(
i = 0;
i < 16;
i++ )
484 if(
i < 2 ||
i == 8 ||
i == 15 )
486 X = ((
X << 1) | (
X >> 27)) & 0x0FFFFFFF;
487 Y = ((
Y << 1) | (
Y >> 27)) & 0x0FFFFFFF;
491 X = ((
X << 2) | (
X >> 26)) & 0x0FFFFFFF;
492 Y = ((
Y << 2) | (
Y >> 26)) & 0x0FFFFFFF;
495 *SK++ = ((
X << 4) & 0x24000000) | ((
X << 28) & 0x10000000)
496 | ((
X << 14) & 0x08000000) | ((
X << 18) & 0x02080000)
497 | ((
X << 6) & 0x01000000) | ((
X << 9) & 0x00200000)
498 | ((
X >> 1) & 0x00100000) | ((
X << 10) & 0x00040000)
499 | ((
X << 2) & 0x00020000) | ((
X >> 10) & 0x00010000)
500 | ((
Y >> 13) & 0x00002000) | ((
Y >> 4) & 0x00001000)
501 | ((
Y << 6) & 0x00000800) | ((
Y >> 1) & 0x00000400)
502 | ((
Y >> 14) & 0x00000200) | ((
Y ) & 0x00000100)
503 | ((
Y >> 5) & 0x00000020) | ((
Y >> 10) & 0x00000010)
504 | ((
Y >> 3) & 0x00000008) | ((
Y >> 18) & 0x00000004)
505 | ((
Y >> 26) & 0x00000002) | ((
Y >> 24) & 0x00000001);
507 *SK++ = ((
X << 15) & 0x20000000) | ((
X << 17) & 0x10000000)
508 | ((
X << 10) & 0x08000000) | ((
X << 22) & 0x04000000)
509 | ((
X >> 2) & 0x02000000) | ((
X << 1) & 0x01000000)
510 | ((
X << 16) & 0x00200000) | ((
X << 11) & 0x00100000)
511 | ((
X << 3) & 0x00080000) | ((
X >> 6) & 0x00040000)
512 | ((
X << 15) & 0x00020000) | ((
X >> 4) & 0x00010000)
513 | ((
Y >> 2) & 0x00002000) | ((
Y << 8) & 0x00001000)
514 | ((
Y >> 14) & 0x00000808) | ((
Y >> 9) & 0x00000400)
515 | ((
Y ) & 0x00000200) | ((
Y << 7) & 0x00000100)
516 | ((
Y >> 7) & 0x00000020) | ((
Y >> 3) & 0x00000011)
517 | ((
Y << 2) & 0x00000004) | ((
Y >> 21) & 0x00000002);
541 for(
i = 0;
i < 16;
i += 2 )
550static void des3_set2key(
uint32_t esk[96],
559 for(
i = 0;
i < 32;
i += 2 )
561 dsk[
i ] = esk[30 -
i];
562 dsk[
i + 1] = esk[31 -
i];
564 esk[
i + 32] = dsk[62 -
i];
565 esk[
i + 33] = dsk[63 -
i];
567 esk[
i + 64] = esk[
i ];
568 esk[
i + 65] = esk[
i + 1];
570 dsk[
i + 64] = dsk[
i ];
571 dsk[
i + 65] = dsk[
i + 1];
583 des3_set2key(
ctx->sk, sk,
key );
597 des3_set2key( sk,
ctx->sk,
key );
603static void des3_set3key(
uint32_t esk[96],
605 const unsigned char key[24] )
613 for(
i = 0;
i < 32;
i += 2 )
615 dsk[
i ] = esk[94 -
i];
616 dsk[
i + 1] = esk[95 -
i];
618 esk[
i + 32] = dsk[62 -
i];
619 esk[
i + 33] = dsk[63 -
i];
621 dsk[
i + 64] = esk[30 -
i];
622 dsk[
i + 65] = esk[31 -
i];
634 des3_set3key(
ctx->sk, sk,
key );
648 des3_set3key( sk,
ctx->sk,
key );
657#if !defined(MBEDTLS_DES_CRYPT_ECB_ALT)
659 const unsigned char input[8],
660 unsigned char output[8] )
667 GET_UINT32_BE(
X,
input, 0 );
668 GET_UINT32_BE(
Y,
input, 4 );
672 for(
i = 0;
i < 8;
i++ )
680 PUT_UINT32_BE(
Y, output, 0 );
681 PUT_UINT32_BE(
X, output, 4 );
687#if defined(MBEDTLS_CIPHER_MODE_CBC)
695 const unsigned char *
input,
696 unsigned char *output )
699 unsigned char temp[8];
708 for(
i = 0;
i < 8;
i++ )
709 output[
i] = (
unsigned char)(
input[
i] ^ iv[
i] );
726 for(
i = 0;
i < 8;
i++ )
727 output[
i] = (
unsigned char)( output[
i] ^ iv[
i] );
744#if !defined(MBEDTLS_DES3_CRYPT_ECB_ALT)
746 const unsigned char input[8],
747 unsigned char output[8] )
754 GET_UINT32_BE(
X,
input, 0 );
755 GET_UINT32_BE(
Y,
input, 4 );
759 for(
i = 0;
i < 8;
i++ )
765 for(
i = 0;
i < 8;
i++ )
771 for(
i = 0;
i < 8;
i++ )
779 PUT_UINT32_BE(
Y, output, 0 );
780 PUT_UINT32_BE(
X, output, 4 );
786#if defined(MBEDTLS_CIPHER_MODE_CBC)
794 const unsigned char *
input,
795 unsigned char *output )
798 unsigned char temp[8];
807 for(
i = 0;
i < 8;
i++ )
808 output[
i] = (
unsigned char)(
input[
i] ^ iv[
i] );
825 for(
i = 0;
i < 8;
i++ )
826 output[
i] = (
unsigned char)( output[
i] ^ iv[
i] );
842#if defined(MBEDTLS_SELF_TEST)
848static const unsigned char des3_test_keys[24] =
850 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
851 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
852 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23
855static const unsigned char des3_test_buf[8] =
857 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74
860static const unsigned char des3_test_ecb_dec[3][8] =
862 { 0xCD, 0xD6, 0x4F, 0x2F, 0x94, 0x27, 0xC1, 0x5D },
863 { 0x69, 0x96, 0xC8, 0xFA, 0x47, 0xA2, 0xAB, 0xEB },
864 { 0x83, 0x25, 0x39, 0x76, 0x44, 0x09, 0x1A, 0x0A }
867static const unsigned char des3_test_ecb_enc[3][8] =
869 { 0x6A, 0x2A, 0x19, 0xF4, 0x1E, 0xCA, 0x85, 0x4B },
870 { 0x03, 0xE6, 0x9F, 0x5B, 0xFA, 0x58, 0xEB, 0x42 },
871 { 0xDD, 0x17, 0xE8, 0xB8, 0xB4, 0x37, 0xD2, 0x32 }
874#if defined(MBEDTLS_CIPHER_MODE_CBC)
875static const unsigned char des3_test_iv[8] =
877 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
880static const unsigned char des3_test_cbc_dec[3][8] =
882 { 0x12, 0x9F, 0x40, 0xB9, 0xD2, 0x00, 0x56, 0xB3 },
883 { 0x47, 0x0E, 0xFC, 0x9A, 0x6B, 0x8E, 0xE3, 0x93 },
884 { 0xC5, 0xCE, 0xCF, 0x63, 0xEC, 0xEC, 0x51, 0x4C }
887static const unsigned char des3_test_cbc_enc[3][8] =
889 { 0x54, 0xF1, 0x5A, 0xF6, 0xEB, 0xE3, 0xA4, 0xB4 },
890 { 0x35, 0x76, 0x11, 0x56, 0x5F, 0xA1, 0x8E, 0x4D },
891 { 0xCB, 0x19, 0x1F, 0x85, 0xD1, 0xED, 0x84, 0x39 }
898int mbedtls_des_self_test(
int verbose )
903 unsigned char buf[8];
904#if defined(MBEDTLS_CIPHER_MODE_CBC)
905 unsigned char prv[8];
914 for(
i = 0;
i < 6;
i++ )
921 (
u == 0 ) ?
' ' :
'3', 56 +
u * 56,
956 for(
j = 0;
j < 10000;
j++ )
965 memcmp(
buf, des3_test_ecb_dec[
u], 8 ) != 0 ) ||
967 memcmp(
buf, des3_test_ecb_enc[
u], 8 ) != 0 ) )
983#if defined(MBEDTLS_CIPHER_MODE_CBC)
987 for(
i = 0;
i < 6;
i++ )
994 (
u == 0 ) ?
' ' :
'3', 56 +
u * 56,
997 memcpy( iv, des3_test_iv, 8 );
998 memcpy( prv, des3_test_iv, 8 );
1033 for(
j = 0;
j < 10000;
j++ )
1043 for(
j = 0;
j < 10000;
j++ )
1045 unsigned char tmp[8];
1061 memcmp(
buf, des3_test_cbc_dec[
u], 8 ) != 0 ) ||
1063 memcmp(
buf, des3_test_cbc_enc[
u], 8 ) != 0 ) )
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei GLsizei * length
GLenum GLenum GLenum input
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
#define memcpy(s1, s2, n)
Configuration options (set of defines)
void mbedtls_des_init(mbedtls_des_context *ctx)
Initialize DES context.
#define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
#define MBEDTLS_DES_ENCRYPT
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
DES key schedule (56-bit, decryption)
void mbedtls_des3_free(mbedtls_des3_context *ctx)
Clear Triple-DES context.
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, decryption)
int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
3DES-CBC buffer encryption/decryption
int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
DES key schedule (56-bit, encryption)
void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE])
Set key parity on the given key to odd.
int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx, const unsigned char input[8], unsigned char output[8])
3DES-ECB block encryption/decryption
int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
DES-CBC buffer encryption/decryption.
int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, encryption)
void mbedtls_des_setkey(uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KEY_SIZE])
Internal function for key expansion. (Only exposed to allow overriding it, see MBEDTLS_DES_SETKEY_ALT...
int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE])
Check that key parity on the given key is odd.
int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE])
Check that key is not a weak or semi-weak DES key.
void mbedtls_des3_init(mbedtls_des3_context *ctx)
Initialize Triple-DES context.
#define MBEDTLS_DES_KEY_SIZE
#define MBEDTLS_DES_DECRYPT
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, decryption)
void mbedtls_des_free(mbedtls_des_context *ctx)
Clear DES context.
Triple-DES context structure.