Revision 551a0c79 libavutil/des.c
libavutil/des.c | ||
---|---|---|
310 | 310 |
uint64_t dst_val; |
311 | 311 |
uint64_t src_val = src ? be2me_64(*(const uint64_t *)src) : 0; |
312 | 312 |
if (decrypt) { |
313 |
uint64_t tmp = src_val; |
|
313 | 314 |
if (d->triple_des) { |
314 | 315 |
src_val = des_encdec(src_val, d->round_keys[2], 1); |
315 | 316 |
src_val = des_encdec(src_val, d->round_keys[1], 0); |
316 | 317 |
} |
317 | 318 |
dst_val = des_encdec(src_val, d->round_keys[0], 1) ^ iv_val; |
318 |
iv_val = iv ? src_val : 0;
|
|
319 |
iv_val = iv ? tmp : 0;
|
|
319 | 320 |
} else { |
320 | 321 |
dst_val = des_encdec(src_val ^ iv_val, d->round_keys[0], 0); |
321 | 322 |
if (d->triple_des) { |
... | ... | |
349 | 350 |
static const DECLARE_ALIGNED(8, uint8_t, plain[]) = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}; |
350 | 351 |
static const DECLARE_ALIGNED(8, uint8_t, crypt[]) = {0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18}; |
351 | 352 |
static DECLARE_ALIGNED(8, uint8_t, tmp[8]); |
353 |
static DECLARE_ALIGNED(8, uint8_t, large_buffer[10002][8]); |
|
354 |
static const uint8_t cbc_key[] = { |
|
355 |
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, |
|
356 |
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, |
|
357 |
0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23 |
|
358 |
}; |
|
359 |
|
|
360 |
int run_test(int cbc, int decrypt) { |
|
361 |
AVDES d; |
|
362 |
int delay = cbc && !decrypt ? 2 : 1; |
|
363 |
uint64_t res; |
|
364 |
AV_WB64(large_buffer[0], 0x4e6f772069732074ULL); |
|
365 |
AV_WB64(large_buffer[1], 0x1234567890abcdefULL); |
|
366 |
AV_WB64(tmp, 0x1234567890abcdefULL); |
|
367 |
av_des_init(&d, cbc_key, 192, decrypt); |
|
368 |
av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt); |
|
369 |
res = AV_RB64(large_buffer[9999 + delay]); |
|
370 |
if (cbc) { |
|
371 |
if (decrypt) |
|
372 |
return res == 0xc5cecf63ecec514cULL; |
|
373 |
else |
|
374 |
return res == 0xcb191f85d1ed8439ULL; |
|
375 |
} else { |
|
376 |
if (decrypt) |
|
377 |
return res == 0x8325397644091a0aULL; |
|
378 |
else |
|
379 |
return res == 0xdd17e8b8b437d232ULL; |
|
380 |
} |
|
381 |
} |
|
352 | 382 |
|
353 | 383 |
int main(void) { |
354 | 384 |
AVDES d; |
... | ... | |
376 | 406 |
printf("Public API decryption failed\n"); |
377 | 407 |
return 1; |
378 | 408 |
} |
409 |
run_test(0, 0); run_test(0, 1); run_test(1, 0); run_test(1, 1); |
|
410 |
if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) { |
|
411 |
printf("Partial Monte-Carlo test failed\n"); |
|
412 |
return 1; |
|
413 |
} |
|
379 | 414 |
for (i = 0; i < 1000000; i++) { |
380 | 415 |
key[0] = rand64(); key[1] = rand64(); key[2] = rand64(); |
381 | 416 |
data = rand64(); |
Also available in: Unified diff