des_generic.c (16d004a2eda7be2c6a2de63eca2ad3c6b57307b3) | des_generic.c (c3041f9c93e31159f4e321abea7c1549d271e6a7) |
---|---|
1/* 2 * Cryptographic API. 3 * 4 * DES & Triple DES EDE Cipher Algorithms. 5 * 6 * Copyright (c) 2005 Dag Arne Osvik <da@osvik.no> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 614 unchanged lines hidden (view full) --- 623 * 624 * FIPS 74: 625 * 626 * Keys having duals are keys which produce all zeros, all ones, or 627 * alternating zero-one patterns in the C and D registers after Permuted 628 * Choice 1 has operated on the key. 629 * 630 */ | 1/* 2 * Cryptographic API. 3 * 4 * DES & Triple DES EDE Cipher Algorithms. 5 * 6 * Copyright (c) 2005 Dag Arne Osvik <da@osvik.no> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 614 unchanged lines hidden (view full) --- 623 * 624 * FIPS 74: 625 * 626 * Keys having duals are keys which produce all zeros, all ones, or 627 * alternating zero-one patterns in the C and D registers after Permuted 628 * Choice 1 has operated on the key. 629 * 630 */ |
631static unsigned long ekey(u32 *pe, const u8 *k) | 631unsigned long des_ekey(u32 *pe, const u8 *k) |
632{ 633 /* K&R: long is at least 32 bits */ 634 unsigned long a, b, c, d, w; 635 const u32 *pt = pc2; 636 637 d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; 638 c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; 639 b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; --- 58 unchanged lines hidden (view full) --- 698 ROL(b, 18); 699 pe[2 * d] = a; 700 pe[2 * d + 1] = b; 701 } 702 703 /* Zero if weak key */ 704 return w; 705} | 632{ 633 /* K&R: long is at least 32 bits */ 634 unsigned long a, b, c, d, w; 635 const u32 *pt = pc2; 636 637 d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; 638 c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; 639 b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; --- 58 unchanged lines hidden (view full) --- 698 ROL(b, 18); 699 pe[2 * d] = a; 700 pe[2 * d + 1] = b; 701 } 702 703 /* Zero if weak key */ 704 return w; 705} |
706EXPORT_SYMBOL_GPL(des_ekey); |
|
706 707/* 708 * Decryption key expansion 709 * 710 * No weak key checking is performed, as this is only used by triple DES 711 * 712 */ 713static void dkey(u32 *pe, const u8 *k) --- 67 unchanged lines hidden (view full) --- 781 unsigned int keylen) 782{ 783 struct des_ctx *dctx = crypto_tfm_ctx(tfm); 784 u32 *flags = &tfm->crt_flags; 785 u32 tmp[DES_EXPKEY_WORDS]; 786 int ret; 787 788 /* Expand to tmp */ | 707 708/* 709 * Decryption key expansion 710 * 711 * No weak key checking is performed, as this is only used by triple DES 712 * 713 */ 714static void dkey(u32 *pe, const u8 *k) --- 67 unchanged lines hidden (view full) --- 782 unsigned int keylen) 783{ 784 struct des_ctx *dctx = crypto_tfm_ctx(tfm); 785 u32 *flags = &tfm->crt_flags; 786 u32 tmp[DES_EXPKEY_WORDS]; 787 int ret; 788 789 /* Expand to tmp */ |
789 ret = ekey(tmp, key); | 790 ret = des_ekey(tmp, key); |
790 791 if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { 792 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 793 return -EINVAL; 794 } 795 796 /* Copy to output */ 797 memcpy(dctx->expkey, tmp, sizeof(dctx->expkey)); --- 70 unchanged lines hidden (view full) --- 868 869 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || 870 !((K[2] ^ K[4]) | (K[3] ^ K[5])))) 871 { 872 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; 873 return -EINVAL; 874 } 875 | 791 792 if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { 793 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 794 return -EINVAL; 795 } 796 797 /* Copy to output */ 798 memcpy(dctx->expkey, tmp, sizeof(dctx->expkey)); --- 70 unchanged lines hidden (view full) --- 869 870 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || 871 !((K[2] ^ K[4]) | (K[3] ^ K[5])))) 872 { 873 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; 874 return -EINVAL; 875 } 876 |
876 ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; | 877 des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; |
877 dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; | 878 dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; |
878 ekey(expkey, key); | 879 des_ekey(expkey, key); |
879 880 return 0; 881} 882 883static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 884{ 885 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 886 const u32 *K = dctx->expkey; --- 120 unchanged lines hidden --- | 880 881 return 0; 882} 883 884static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 885{ 886 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 887 const u32 *K = dctx->expkey; --- 120 unchanged lines hidden --- |