btrfs: migrate the block group ref counting stuff
[linux/fpc-iii.git] / include / crypto / des.h
blob72c7c8e5a5a7aa28b1e34661383d2721ef410d17
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * DES & Triple DES EDE Cipher Algorithms.
4 */
6 #ifndef __CRYPTO_DES_H
7 #define __CRYPTO_DES_H
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)
24 int err = -EINVAL;
25 u32 K[6];
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]))) &&
31 (fips_enabled ||
32 (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)))
33 goto bad;
35 if (unlikely(!((K[0] ^ K[4]) | (K[1] ^ K[5]))) && fips_enabled)
36 goto bad;
38 err = 0;
40 out:
41 memzero_explicit(K, DES3_EDE_KEY_SIZE);
43 return err;
45 bad:
46 *flags |= CRYPTO_TFM_RES_WEAK_KEY;
47 goto out;
50 static inline int des3_verify_key(struct crypto_skcipher *tfm, const u8 *key)
52 u32 flags;
53 int err;
55 flags = crypto_skcipher_get_flags(tfm);
56 err = __des3_verify_key(&flags, key);
57 crypto_skcipher_set_flags(tfm, flags);
58 return err;
61 extern unsigned long des_ekey(u32 *pe, const u8 *k);
63 extern int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key,
64 unsigned int keylen);
66 #endif /* __CRYPTO_DES_H */