^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * DES & Triple DES EDE Cipher Algorithms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __CRYPTO_DES_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __CRYPTO_DES_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define DES_KEY_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define DES_EXPKEY_WORDS 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define DES_BLOCK_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct des_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u32 expkey[DES_EXPKEY_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct des3_ede_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u32 expkey[DES3_EDE_EXPKEY_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) void des_encrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) void des_decrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) void des3_ede_encrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void des3_ede_decrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * des_expand_key - Expand a DES input key into a key schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @ctx: the key schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * @key: buffer containing the input key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * @len: size of the buffer contents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * the key is accepted but has been found to be weak.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int des_expand_key(struct des_ctx *ctx, const u8 *key, unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * des3_ede_expand_key - Expand a triple DES input key into a key schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @ctx: the key schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @key: buffer containing the input key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @len: size of the buffer contents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * the key is accepted but has been found to be weak. Note that weak keys will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * be rejected (and -EINVAL will be returned) when running in FIPS mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int des3_ede_expand_key(struct des3_ede_ctx *ctx, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #endif /* __CRYPTO_DES_H */