xref: /linux/include/crypto/des.h (revision 04007b0e6cbbab5836ac891626e91edf10d46341)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
216d004a2SEvgeniy Polyakov /*
316d004a2SEvgeniy Polyakov  * DES & Triple DES EDE Cipher Algorithms.
416d004a2SEvgeniy Polyakov  */
516d004a2SEvgeniy Polyakov 
616d004a2SEvgeniy Polyakov #ifndef __CRYPTO_DES_H
716d004a2SEvgeniy Polyakov #define __CRYPTO_DES_H
816d004a2SEvgeniy Polyakov 
9*04007b0eSArd Biesheuvel #include <linux/types.h>
10d7198ce4SHerbert Xu 
1116d004a2SEvgeniy Polyakov #define DES_KEY_SIZE		8
1216d004a2SEvgeniy Polyakov #define DES_EXPKEY_WORDS	32
1316d004a2SEvgeniy Polyakov #define DES_BLOCK_SIZE		8
1416d004a2SEvgeniy Polyakov 
1516d004a2SEvgeniy Polyakov #define DES3_EDE_KEY_SIZE	(3 * DES_KEY_SIZE)
1616d004a2SEvgeniy Polyakov #define DES3_EDE_EXPKEY_WORDS	(3 * DES_EXPKEY_WORDS)
1716d004a2SEvgeniy Polyakov #define DES3_EDE_BLOCK_SIZE	DES_BLOCK_SIZE
1816d004a2SEvgeniy Polyakov 
19*04007b0eSArd Biesheuvel struct des_ctx {
20*04007b0eSArd Biesheuvel 	u32 expkey[DES_EXPKEY_WORDS];
21*04007b0eSArd Biesheuvel };
22*04007b0eSArd Biesheuvel 
23*04007b0eSArd Biesheuvel struct des3_ede_ctx {
24*04007b0eSArd Biesheuvel 	u32 expkey[DES3_EDE_EXPKEY_WORDS];
25*04007b0eSArd Biesheuvel };
26*04007b0eSArd Biesheuvel 
27*04007b0eSArd Biesheuvel void des_encrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
28*04007b0eSArd Biesheuvel void des_decrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
29*04007b0eSArd Biesheuvel 
30*04007b0eSArd Biesheuvel void des3_ede_encrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
31*04007b0eSArd Biesheuvel void des3_ede_decrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
32*04007b0eSArd Biesheuvel 
33*04007b0eSArd Biesheuvel /**
34*04007b0eSArd Biesheuvel  * des_expand_key - Expand a DES input key into a key schedule
35*04007b0eSArd Biesheuvel  * @ctx: the key schedule
36*04007b0eSArd Biesheuvel  * @key: buffer containing the input key
37*04007b0eSArd Biesheuvel  * @len: size of the buffer contents
38*04007b0eSArd Biesheuvel  *
39*04007b0eSArd Biesheuvel  * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
40*04007b0eSArd Biesheuvel  * the key is accepted but has been found to be weak.
41*04007b0eSArd Biesheuvel  */
42*04007b0eSArd Biesheuvel int des_expand_key(struct des_ctx *ctx, const u8 *key, unsigned int keylen);
43*04007b0eSArd Biesheuvel 
44*04007b0eSArd Biesheuvel /**
45*04007b0eSArd Biesheuvel  * des3_ede_expand_key - Expand a triple DES input key into a key schedule
46*04007b0eSArd Biesheuvel  * @ctx: the key schedule
47*04007b0eSArd Biesheuvel  * @key: buffer containing the input key
48*04007b0eSArd Biesheuvel  * @len: size of the buffer contents
49*04007b0eSArd Biesheuvel  *
50*04007b0eSArd Biesheuvel  * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
51*04007b0eSArd Biesheuvel  * the key is accepted but has been found to be weak. Note that weak keys will
52*04007b0eSArd Biesheuvel  * be rejected (and -EINVAL will be returned) when running in FIPS mode.
53*04007b0eSArd Biesheuvel  */
54*04007b0eSArd Biesheuvel int des3_ede_expand_key(struct des3_ede_ctx *ctx, const u8 *key,
55*04007b0eSArd Biesheuvel 			unsigned int keylen);
56*04007b0eSArd Biesheuvel 
576574e6c6SJussi Kivilinna extern int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key,
586574e6c6SJussi Kivilinna 			     unsigned int keylen);
596574e6c6SJussi Kivilinna 
6016d004a2SEvgeniy Polyakov #endif /* __CRYPTO_DES_H */
61