diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libc/crypt/blowfish.c | 140 |
1 files changed, 139 insertions, 1 deletions
diff --git a/src/lib/libc/crypt/blowfish.c b/src/lib/libc/crypt/blowfish.c index 5ffc634efa..d946655624 100644 --- a/src/lib/libc/crypt/blowfish.c +++ b/src/lib/libc/crypt/blowfish.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: blowfish.c,v 1.8 1998/03/04 00:34:17 deraadt Exp $ */ | 1 | /* $OpenBSD: blowfish.c,v 1.9 1998/08/10 18:40:59 provos Exp $ */ |
2 | /* | 2 | /* |
3 | * Blowfish block cipher for OpenBSD | 3 | * Blowfish block cipher for OpenBSD |
4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
@@ -584,6 +584,144 @@ blf_dec(c, data, blocks) | |||
584 | d += 2; | 584 | d += 2; |
585 | } | 585 | } |
586 | } | 586 | } |
587 | |||
588 | /* Repeating operations for little endian machines */ | ||
589 | |||
590 | #define BLF_BLK_ENC l = ntohl (*(u_int32_t *)data); \ | ||
591 | r = ntohl (*(u_int32_t *)(data+4)); \ | ||
592 | Blowfish_encipher(c, &l, &r); \ | ||
593 | *(u_int32_t *)data = htonl (l); \ | ||
594 | *(u_int32_t *)(data + 4) = htonl (r); | ||
595 | |||
596 | #define BLF_BLK_DEC l = ntohl (*(u_int32_t *)data); \ | ||
597 | r = ntohl (*(u_int32_t *)(data+4)); \ | ||
598 | Blowfish_decipher(c, &l, &r); \ | ||
599 | *(u_int32_t *)data = htonl (l); \ | ||
600 | *(u_int32_t *)(data + 4) = htonl (r); | ||
601 | |||
602 | |||
603 | #if __STDC__ | ||
604 | void | ||
605 | blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) | ||
606 | #else | ||
607 | void | ||
608 | blf_ecb_encrypt(c, data, len) | ||
609 | blf_ctx *c; | ||
610 | u_int8_t *data; | ||
611 | u_int32_t len; | ||
612 | #endif | ||
613 | { | ||
614 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
615 | u_int32_t l, r; | ||
616 | #endif | ||
617 | u_int32_t i; | ||
618 | |||
619 | for (i = 0; i < len; i += 8) { | ||
620 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
621 | BLF_BLK_ENC; | ||
622 | #else | ||
623 | Blowfish_encipher(c, data, data + 4); | ||
624 | #endif | ||
625 | data += 8; | ||
626 | } | ||
627 | } | ||
628 | |||
629 | #if __STDC__ | ||
630 | void | ||
631 | blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) | ||
632 | #else | ||
633 | void | ||
634 | blf_ecb_decrypt(c, data, len) | ||
635 | blf_ctx *c; | ||
636 | u_int8_t *data; | ||
637 | u_int32_t len; | ||
638 | #endif | ||
639 | { | ||
640 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
641 | u_int32_t l, r; | ||
642 | #endif | ||
643 | u_int32_t i; | ||
644 | |||
645 | for (i = 0; i < len; i += 8) { | ||
646 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
647 | BLF_BLK_DEC; | ||
648 | #else | ||
649 | Blowfish_decipher(c, data, data + 4); | ||
650 | #endif | ||
651 | data += 8; | ||
652 | } | ||
653 | } | ||
654 | |||
655 | #if __STDC__ | ||
656 | void | ||
657 | blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len) | ||
658 | #else | ||
659 | void | ||
660 | blf_cbc_encrypt(c, iv, data, len) | ||
661 | blf_ctx *c; | ||
662 | u_int8_t *iv; | ||
663 | u_int8_t *data; | ||
664 | u_int32_t len; | ||
665 | #endif | ||
666 | { | ||
667 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
668 | u_int32_t l, r; | ||
669 | #endif | ||
670 | u_int32_t i; | ||
671 | |||
672 | for (i = 0; i < len; i += 8) { | ||
673 | *(u_int32_t *)data ^= *(u_int32_t *)iv; | ||
674 | *(u_int32_t *)(data + 4) ^= *(u_int32_t *)(iv + 4); | ||
675 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
676 | BLF_BLK_ENC; | ||
677 | #else | ||
678 | Blowfish_encipher(c, data, data + 4); | ||
679 | #endif | ||
680 | iv = data; | ||
681 | data += 8; | ||
682 | } | ||
683 | } | ||
684 | |||
685 | #if __STDC__ | ||
686 | void | ||
687 | blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len) | ||
688 | #else | ||
689 | void | ||
690 | blf_cbc_decrypt(c, iva, data, len) | ||
691 | blf_ctx *c; | ||
692 | u_int8_t *iva; | ||
693 | u_int8_t *data; | ||
694 | u_int32_t len; | ||
695 | #endif | ||
696 | { | ||
697 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
698 | u_int32_t l, r; | ||
699 | #endif | ||
700 | u_int8_t *iv; | ||
701 | u_int32_t i; | ||
702 | |||
703 | iv = data + len - 16; | ||
704 | data = data + len - 8; | ||
705 | for (i = len - 8; i >= 8; i -= 8) { | ||
706 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
707 | BLF_BLK_DEC; | ||
708 | #else | ||
709 | Blowfish_decipher(c, data, data + 4); | ||
710 | #endif | ||
711 | *(u_int32_t *)data ^= *(u_int32_t *)iv; | ||
712 | *(u_int32_t *)(data + 4) ^= *(u_int32_t *)(iv + 4); | ||
713 | iv = data; | ||
714 | data -= 8; | ||
715 | } | ||
716 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
717 | BLF_BLK_DEC; | ||
718 | #else | ||
719 | Blowfish_decipher(c, data, data + 4); | ||
720 | #endif | ||
721 | *(u_int32_t *)data ^= *(u_int32_t *)iva; | ||
722 | *(u_int32_t *)(data + 4) ^= *(u_int32_t *)(iva + 4); | ||
723 | } | ||
724 | |||
587 | #if 0 | 725 | #if 0 |
588 | void | 726 | void |
589 | report(u_int32_t data[], u_int16_t len) | 727 | report(u_int32_t data[], u_int16_t len) |