des_generic.c (cf9ce948f47640797bd19980e1d99c6d17d0bdc3) | des_generic.c (6574e6c64e971c9adb629e81e497afdb52b1c9df) |
---|---|
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 --- 845 unchanged lines hidden (view full) --- 854 * multiple keys. 855 * 856 * However, if the first two or last two independent 64-bit keys are 857 * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the 858 * same as DES. Implementers MUST reject keys that exhibit this 859 * property. 860 * 861 */ | 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 --- 845 unchanged lines hidden (view full) --- 854 * multiple keys. 855 * 856 * However, if the first two or last two independent 64-bit keys are 857 * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the 858 * same as DES. Implementers MUST reject keys that exhibit this 859 * property. 860 * 861 */ |
862static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, 863 unsigned int keylen) | 862int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, 863 unsigned int keylen) |
864{ 865 const u32 *K = (const u32 *)key; | 864{ 865 const u32 *K = (const u32 *)key; |
866 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 867 u32 *expkey = dctx->expkey; 868 u32 *flags = &tfm->crt_flags; | |
869 870 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || 871 !((K[2] ^ K[4]) | (K[3] ^ K[5]))) && 872 (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { 873 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 874 return -EINVAL; 875 } 876 877 des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 878 dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 879 des_ekey(expkey, key); 880 881 return 0; 882} | 866 867 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || 868 !((K[2] ^ K[4]) | (K[3] ^ K[5]))) && 869 (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { 870 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 871 return -EINVAL; 872 } 873 874 des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 875 dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 876 des_ekey(expkey, key); 877 878 return 0; 879} |
880EXPORT_SYMBOL_GPL(__des3_ede_setkey); |
|
883 | 881 |
882static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, 883 unsigned int keylen) 884{ 885 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 886 u32 *flags = &tfm->crt_flags; 887 u32 *expkey = dctx->expkey; 888 889 return __des3_ede_setkey(expkey, flags, key, keylen); 890} 891 |
|
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; 888 const __le32 *s = (const __le32 *)src; 889 __le32 *d = (__le32 *)dst; 890 u32 L, R, A, B; 891 int i; --- 48 unchanged lines hidden (view full) --- 940 FP(R, L, A); 941 942 d[0] = cpu_to_le32(R); 943 d[1] = cpu_to_le32(L); 944} 945 946static struct crypto_alg des_algs[2] = { { 947 .cra_name = "des", | 892static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 893{ 894 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 895 const u32 *K = dctx->expkey; 896 const __le32 *s = (const __le32 *)src; 897 __le32 *d = (__le32 *)dst; 898 u32 L, R, A, B; 899 int i; --- 48 unchanged lines hidden (view full) --- 948 FP(R, L, A); 949 950 d[0] = cpu_to_le32(R); 951 d[1] = cpu_to_le32(L); 952} 953 954static struct crypto_alg des_algs[2] = { { 955 .cra_name = "des", |
956 .cra_driver_name = "des-generic", 957 .cra_priority = 100, |
|
948 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 949 .cra_blocksize = DES_BLOCK_SIZE, 950 .cra_ctxsize = sizeof(struct des_ctx), 951 .cra_module = THIS_MODULE, 952 .cra_alignmask = 3, 953 .cra_u = { .cipher = { 954 .cia_min_keysize = DES_KEY_SIZE, 955 .cia_max_keysize = DES_KEY_SIZE, 956 .cia_setkey = des_setkey, 957 .cia_encrypt = des_encrypt, 958 .cia_decrypt = des_decrypt } } 959}, { 960 .cra_name = "des3_ede", | 958 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 959 .cra_blocksize = DES_BLOCK_SIZE, 960 .cra_ctxsize = sizeof(struct des_ctx), 961 .cra_module = THIS_MODULE, 962 .cra_alignmask = 3, 963 .cra_u = { .cipher = { 964 .cia_min_keysize = DES_KEY_SIZE, 965 .cia_max_keysize = DES_KEY_SIZE, 966 .cia_setkey = des_setkey, 967 .cia_encrypt = des_encrypt, 968 .cia_decrypt = des_decrypt } } 969}, { 970 .cra_name = "des3_ede", |
971 .cra_driver_name = "des3_ede-generic", 972 .cra_priority = 100, |
|
961 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 962 .cra_blocksize = DES3_EDE_BLOCK_SIZE, 963 .cra_ctxsize = sizeof(struct des3_ede_ctx), 964 .cra_module = THIS_MODULE, 965 .cra_alignmask = 3, 966 .cra_u = { .cipher = { 967 .cia_min_keysize = DES3_EDE_KEY_SIZE, 968 .cia_max_keysize = DES3_EDE_KEY_SIZE, --- 24 unchanged lines hidden --- | 973 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 974 .cra_blocksize = DES3_EDE_BLOCK_SIZE, 975 .cra_ctxsize = sizeof(struct des3_ede_ctx), 976 .cra_module = THIS_MODULE, 977 .cra_alignmask = 3, 978 .cra_u = { .cipher = { 979 .cia_min_keysize = DES3_EDE_KEY_SIZE, 980 .cia_max_keysize = DES3_EDE_KEY_SIZE, --- 24 unchanged lines hidden --- |