diff options
Diffstat (limited to 'src/daemon/https/lgl/des.c')
-rw-r--r-- | src/daemon/https/lgl/des.c | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/src/daemon/https/lgl/des.c b/src/daemon/https/lgl/des.c index dbe5f3c6..ecb09e41 100644 --- a/src/daemon/https/lgl/des.c +++ b/src/daemon/https/lgl/des.c | |||
@@ -79,13 +79,6 @@ | |||
79 | * unsigned char recoverd[8]; | 79 | * unsigned char recoverd[8]; |
80 | * MHD_gl_3des_ctx context; | 80 | * MHD_gl_3des_ctx context; |
81 | * | 81 | * |
82 | * // If you would like to use two 64bit keys, fill 'key1' and'key2' | ||
83 | * // then setup the encryption context: | ||
84 | * MHD_gl_3des_set2keys(&context, key1, key2); | ||
85 | * | ||
86 | * // To use three 64bit keys with Triple-DES use: | ||
87 | * MHD_gl_3des_set3keys(&context, key1, key2, key3); | ||
88 | * | ||
89 | * // Encrypting plaintext with Triple-DES | 82 | * // Encrypting plaintext with Triple-DES |
90 | * MHD_gl_3des_ecb_encrypt(&context, plaintext, ciphertext); | 83 | * MHD_gl_3des_ecb_encrypt(&context, plaintext, ciphertext); |
91 | * | 84 | * |
@@ -319,35 +312,6 @@ static const unsigned char weak_keys[64][8] = { | |||
319 | {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe} /*w */ | 312 | {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe} /*w */ |
320 | }; | 313 | }; |
321 | 314 | ||
322 | bool | ||
323 | MHD_gl_des_is_weak_key (const char *key) | ||
324 | { | ||
325 | char work[8]; | ||
326 | int i, left, right, middle, cmp_result; | ||
327 | |||
328 | /* clear parity bits */ | ||
329 | for (i = 0; i < 8; ++i) | ||
330 | work[i] = ((unsigned char) key[i]) & 0xfe; | ||
331 | |||
332 | /* binary search in the weak key table */ | ||
333 | left = 0; | ||
334 | right = 63; | ||
335 | while (left <= right) | ||
336 | { | ||
337 | middle = (left + right) / 2; | ||
338 | |||
339 | if (!(cmp_result = memcmp (work, weak_keys[middle], 8))) | ||
340 | return -1; | ||
341 | |||
342 | if (cmp_result > 0) | ||
343 | left = middle + 1; | ||
344 | else | ||
345 | right = middle - 1; | ||
346 | } | ||
347 | |||
348 | return 0; | ||
349 | } | ||
350 | |||
351 | /* | 315 | /* |
352 | * Macro to swap bits across two words. | 316 | * Macro to swap bits across two words. |
353 | */ | 317 | */ |
@@ -531,17 +495,6 @@ MHD_gl_des_setkey (MHD_gl_des_ctx * ctx, const char *key) | |||
531 | } | 495 | } |
532 | } | 496 | } |
533 | 497 | ||
534 | bool | ||
535 | MHD_gl_des_makekey (MHD_gl_des_ctx * ctx, const char *key, size_t keylen) | ||
536 | { | ||
537 | if (keylen != 8) | ||
538 | return false; | ||
539 | |||
540 | MHD_gl_des_setkey (ctx, key); | ||
541 | |||
542 | return !MHD_gl_des_is_weak_key (key); | ||
543 | } | ||
544 | |||
545 | void | 498 | void |
546 | MHD_gl_des_ecb_crypt (MHD_gl_des_ctx * ctx, const char *_from, char *_to, | 499 | MHD_gl_des_ecb_crypt (MHD_gl_des_ctx * ctx, const char *_from, char *_to, |
547 | int mode) | 500 | int mode) |
@@ -566,54 +519,6 @@ READ_64BIT_DATA (from, left, right) | |||
566 | FINAL_PERMUTATION (right, work, left) WRITE_64BIT_DATA (to, right, left)} | 519 | FINAL_PERMUTATION (right, work, left) WRITE_64BIT_DATA (to, right, left)} |
567 | 520 | ||
568 | void | 521 | void |
569 | MHD_gl_3des_set2keys (MHD_gl_3des_ctx * ctx, const char *key1, | ||
570 | const char *key2) | ||
571 | { | ||
572 | int i; | ||
573 | |||
574 | des_key_schedule (key1, ctx->encrypt_subkeys); | ||
575 | des_key_schedule (key2, &(ctx->decrypt_subkeys[32])); | ||
576 | |||
577 | for (i = 0; i < 32; i += 2) | ||
578 | { | ||
579 | ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[30 - i]; | ||
580 | ctx->decrypt_subkeys[i + 1] = ctx->encrypt_subkeys[31 - i]; | ||
581 | |||
582 | ctx->encrypt_subkeys[i + 32] = ctx->decrypt_subkeys[62 - i]; | ||
583 | ctx->encrypt_subkeys[i + 33] = ctx->decrypt_subkeys[63 - i]; | ||
584 | |||
585 | ctx->encrypt_subkeys[i + 64] = ctx->encrypt_subkeys[i]; | ||
586 | ctx->encrypt_subkeys[i + 65] = ctx->encrypt_subkeys[i + 1]; | ||
587 | |||
588 | ctx->decrypt_subkeys[i + 64] = ctx->decrypt_subkeys[i]; | ||
589 | ctx->decrypt_subkeys[i + 65] = ctx->decrypt_subkeys[i + 1]; | ||
590 | } | ||
591 | } | ||
592 | |||
593 | void | ||
594 | MHD_gl_3des_set3keys (MHD_gl_3des_ctx * ctx, const char *key1, | ||
595 | const char *key2, const char *key3) | ||
596 | { | ||
597 | int i; | ||
598 | |||
599 | des_key_schedule (key1, ctx->encrypt_subkeys); | ||
600 | des_key_schedule (key2, &(ctx->decrypt_subkeys[32])); | ||
601 | des_key_schedule (key3, &(ctx->encrypt_subkeys[64])); | ||
602 | |||
603 | for (i = 0; i < 32; i += 2) | ||
604 | { | ||
605 | ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[94 - i]; | ||
606 | ctx->decrypt_subkeys[i + 1] = ctx->encrypt_subkeys[95 - i]; | ||
607 | |||
608 | ctx->encrypt_subkeys[i + 32] = ctx->decrypt_subkeys[62 - i]; | ||
609 | ctx->encrypt_subkeys[i + 33] = ctx->decrypt_subkeys[63 - i]; | ||
610 | |||
611 | ctx->decrypt_subkeys[i + 64] = ctx->encrypt_subkeys[30 - i]; | ||
612 | ctx->decrypt_subkeys[i + 65] = ctx->encrypt_subkeys[31 - i]; | ||
613 | } | ||
614 | } | ||
615 | |||
616 | void | ||
617 | MHD_gl_3des_ecb_crypt (MHD_gl_3des_ctx * ctx, const char *_from, char *_to, | 522 | MHD_gl_3des_ecb_crypt (MHD_gl_3des_ctx * ctx, const char *_from, char *_to, |
618 | int mode) | 523 | int mode) |
619 | { | 524 | { |
@@ -652,15 +557,3 @@ READ_64BIT_DATA (from, left, right) | |||
652 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) | 557 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
653 | FINAL_PERMUTATION (right, work, left) WRITE_64BIT_DATA (to, right, left)} | 558 | FINAL_PERMUTATION (right, work, left) WRITE_64BIT_DATA (to, right, left)} |
654 | 559 | ||
655 | bool | ||
656 | MHD_gl_3des_makekey (MHD_gl_3des_ctx * ctx, const char *key, size_t keylen) | ||
657 | { | ||
658 | if (keylen != 24) | ||
659 | return false; | ||
660 | |||
661 | MHD_gl_3des_set3keys (ctx, key, key + 8, key + 16); | ||
662 | |||
663 | return !(MHD_gl_des_is_weak_key (key) | ||
664 | || MHD_gl_des_is_weak_key (key + 8) | ||
665 | || MHD_gl_des_is_weak_key (key + 16)); | ||
666 | } | ||