1 /* SPDX-License-Identifier: GPL-2.0 */
3 * DES & Triple DES EDE Cipher Algorithms.
9 #include <crypto/skcipher.h>
10 #include <linux/compiler.h>
11 #include <linux/fips.h>
12 #include <linux/string.h>
14 #define DES_KEY_SIZE 8
15 #define DES_EXPKEY_WORDS 32
16 #define DES_BLOCK_SIZE 8
18 #define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
19 #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
20 #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
22 static inline int __des3_verify_key(u32
*flags
, const u8
*key
)
27 memcpy(K
, key
, DES3_EDE_KEY_SIZE
);
29 if (unlikely(!((K
[0] ^ K
[2]) | (K
[1] ^ K
[3])) ||
30 !((K
[2] ^ K
[4]) | (K
[3] ^ K
[5]))) &&
32 (*flags
& CRYPTO_TFM_REQ_FORBID_WEAK_KEYS
)))
35 if (unlikely(!((K
[0] ^ K
[4]) | (K
[1] ^ K
[5]))) && fips_enabled
)
41 memzero_explicit(K
, DES3_EDE_KEY_SIZE
);
46 *flags
|= CRYPTO_TFM_RES_WEAK_KEY
;
50 static inline int des3_verify_key(struct crypto_skcipher
*tfm
, const u8
*key
)
55 flags
= crypto_skcipher_get_flags(tfm
);
56 err
= __des3_verify_key(&flags
, key
);
57 crypto_skcipher_set_flags(tfm
, flags
);
61 extern unsigned long des_ekey(u32
*pe
, const u8
*k
);
63 extern int __des3_ede_setkey(u32
*expkey
, u32
*flags
, const u8
*key
,
66 #endif /* __CRYPTO_DES_H */