Lines Matching +full:a +full:- +full:b

1 // SPDX-License-Identifier: GPL-2.0-or-later
360 /* S-box lookup tables */
582 #define ROUND(L, R, A, B, K, d) \ argument
583 B = K[0]; A = K[1]; K += d; \
584 B ^= R; A ^= R; \
585 B &= 0x3f3f3f3f; ROR(A, 4); \
586 L ^= S8[0xff & B]; A &= 0x3f3f3f3f; \
587 L ^= S6[0xff & (B >> 8)]; B >>= 16; \
588 L ^= S7[0xff & A]; \
589 L ^= S5[0xff & (A >> 8)]; A >>= 16; \
590 L ^= S4[0xff & B]; \
591 L ^= S2[0xff & (B >> 8)]; \
592 L ^= S3[0xff & A]; \
593 L ^= S1[0xff & (A >> 8)];
598 * the 4 interleaved tables correspond to four 7-bit subsets of C_i or D_i.
600 * After PC1 each of the variables a,b,c,d contains a 7 bit subset of C_i
601 * or D_i in bits 7-1 (bit 0 being the least significant).
609 #define DES_PC2(a, b, c, d) (T4(d) | T3(c) | T2(b) | T1(a)) argument
619 * alternating zero-one patterns in the C and D registers after Permuted
626 unsigned long a, b, c, d, w; in des_ekey() local
631 b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; in des_ekey()
632 a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; in des_ekey()
634 pe[15 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; in des_ekey()
635 pe[14 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in des_ekey()
636 pe[13 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in des_ekey()
637 pe[12 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in des_ekey()
638 pe[11 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in des_ekey()
639 pe[10 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in des_ekey()
640 pe[ 9 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in des_ekey()
641 pe[ 8 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; in des_ekey()
642 pe[ 7 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in des_ekey()
643 pe[ 6 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in des_ekey()
644 pe[ 5 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in des_ekey()
645 pe[ 4 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in des_ekey()
646 pe[ 3 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in des_ekey()
647 pe[ 2 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in des_ekey()
648 pe[ 1 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; in des_ekey()
649 pe[ 0 * 2 + 0] = DES_PC2(b, c, d, a); in des_ekey()
652 w = (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); in des_ekey()
659 b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; in des_ekey()
660 a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; in des_ekey()
663 w |= (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); in des_ekey()
665 pe[15 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; in des_ekey()
666 pe[14 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in des_ekey()
667 pe[13 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in des_ekey()
668 pe[12 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in des_ekey()
669 pe[11 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in des_ekey()
670 pe[10 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in des_ekey()
671 pe[ 9 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in des_ekey()
672 pe[ 8 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; in des_ekey()
673 pe[ 7 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in des_ekey()
674 pe[ 6 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in des_ekey()
675 pe[ 5 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in des_ekey()
676 pe[ 4 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in des_ekey()
677 pe[ 3 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in des_ekey()
678 pe[ 2 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in des_ekey()
679 pe[ 1 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; in des_ekey()
680 pe[ 0 * 2 + 1] = DES_PC2(b, c, d, a); in des_ekey()
682 /* Fixup: 2413 5768 -> 1357 2468 */ in des_ekey()
684 a = pe[2 * d]; in des_ekey()
685 b = pe[2 * d + 1]; in des_ekey()
686 c = a ^ b; in des_ekey()
688 a ^= c; in des_ekey()
689 b ^= c; in des_ekey()
690 ROL(b, 18); in des_ekey()
691 pe[2 * d] = a; in des_ekey()
692 pe[2 * d + 1] = b; in des_ekey()
702 return -EINVAL; in des_expand_key()
704 return des_ekey(ctx->expkey, key) ? 0 : -ENOKEY; in des_expand_key()
717 unsigned long a, b, c, d; in dkey() local
722 b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; in dkey()
723 a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; in dkey()
725 pe[ 0 * 2] = DES_PC2(a, b, c, d); d = rs[d]; in dkey()
726 pe[ 1 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in dkey()
727 pe[ 2 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in dkey()
728 pe[ 3 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in dkey()
729 pe[ 4 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in dkey()
730 pe[ 5 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in dkey()
731 pe[ 6 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in dkey()
732 pe[ 7 * 2] = DES_PC2(d, a, b, c); c = rs[c]; in dkey()
733 pe[ 8 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in dkey()
734 pe[ 9 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in dkey()
735 pe[10 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in dkey()
736 pe[11 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in dkey()
737 pe[12 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in dkey()
738 pe[13 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in dkey()
739 pe[14 * 2] = DES_PC2(c, d, a, b); b = rs[b]; in dkey()
740 pe[15 * 2] = DES_PC2(b, c, d, a); in dkey()
747 b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; in dkey()
748 a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; in dkey()
750 pe[ 0 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; in dkey()
751 pe[ 1 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in dkey()
752 pe[ 2 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in dkey()
753 pe[ 3 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in dkey()
754 pe[ 4 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in dkey()
755 pe[ 5 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; in dkey()
756 pe[ 6 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; in dkey()
757 pe[ 7 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; in dkey()
758 pe[ 8 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in dkey()
759 pe[ 9 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in dkey()
760 pe[10 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in dkey()
761 pe[11 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in dkey()
762 pe[12 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; in dkey()
763 pe[13 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; in dkey()
764 pe[14 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; in dkey()
765 pe[15 * 2 + 1] = DES_PC2(b, c, d, a); in dkey()
767 /* Fixup: 2413 5768 -> 1357 2468 */ in dkey()
769 a = pe[2 * d]; in dkey()
770 b = pe[2 * d + 1]; in dkey()
771 c = a ^ b; in dkey()
773 a ^= c; in dkey()
774 b ^= c; in dkey()
775 ROL(b, 18); in dkey()
776 pe[2 * d] = a; in dkey()
777 pe[2 * d + 1] = b; in dkey()
783 const u32 *K = ctx->expkey; in des_encrypt()
784 u32 L, R, A, B; in des_encrypt() local
790 IP(L, R, A); in des_encrypt()
792 ROUND(L, R, A, B, K, 2); in des_encrypt()
793 ROUND(R, L, A, B, K, 2); in des_encrypt()
795 FP(R, L, A); in des_encrypt()
804 const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2; in des_decrypt()
805 u32 L, R, A, B; in des_decrypt() local
811 IP(L, R, A); in des_decrypt()
813 ROUND(L, R, A, B, K, -2); in des_decrypt()
814 ROUND(R, L, A, B, K, -2); in des_decrypt()
816 FP(R, L, A); in des_decrypt()
826 u32 *pe = ctx->expkey; in des3_ede_expand_key()
830 return -EINVAL; in des3_ede_expand_key()
833 if (err && err != -ENOKEY) in des3_ede_expand_key()
846 const u32 *K = dctx->expkey; in des3_ede_encrypt()
847 u32 L, R, A, B; in des3_ede_encrypt() local
853 IP(L, R, A); in des3_ede_encrypt()
855 ROUND(L, R, A, B, K, 2); in des3_ede_encrypt()
856 ROUND(R, L, A, B, K, 2); in des3_ede_encrypt()
859 ROUND(R, L, A, B, K, 2); in des3_ede_encrypt()
860 ROUND(L, R, A, B, K, 2); in des3_ede_encrypt()
863 ROUND(L, R, A, B, K, 2); in des3_ede_encrypt()
864 ROUND(R, L, A, B, K, 2); in des3_ede_encrypt()
866 FP(R, L, A); in des3_ede_encrypt()
875 const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2; in des3_ede_decrypt()
876 u32 L, R, A, B; in des3_ede_decrypt() local
882 IP(L, R, A); in des3_ede_decrypt()
884 ROUND(L, R, A, B, K, -2); in des3_ede_decrypt()
885 ROUND(R, L, A, B, K, -2); in des3_ede_decrypt()
888 ROUND(R, L, A, B, K, -2); in des3_ede_decrypt()
889 ROUND(L, R, A, B, K, -2); in des3_ede_decrypt()
892 ROUND(L, R, A, B, K, -2); in des3_ede_decrypt()
893 ROUND(R, L, A, B, K, -2); in des3_ede_decrypt()
895 FP(R, L, A); in des3_ede_decrypt()