xref: /kernel/linux/linux-5.10/include/crypto/des.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * DES & Triple DES EDE Cipher Algorithms.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __CRYPTO_DES_H
78c2ecf20Sopenharmony_ci#define __CRYPTO_DES_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/types.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define DES_KEY_SIZE		8
128c2ecf20Sopenharmony_ci#define DES_EXPKEY_WORDS	32
138c2ecf20Sopenharmony_ci#define DES_BLOCK_SIZE		8
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define DES3_EDE_KEY_SIZE	(3 * DES_KEY_SIZE)
168c2ecf20Sopenharmony_ci#define DES3_EDE_EXPKEY_WORDS	(3 * DES_EXPKEY_WORDS)
178c2ecf20Sopenharmony_ci#define DES3_EDE_BLOCK_SIZE	DES_BLOCK_SIZE
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct des_ctx {
208c2ecf20Sopenharmony_ci	u32 expkey[DES_EXPKEY_WORDS];
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct des3_ede_ctx {
248c2ecf20Sopenharmony_ci	u32 expkey[DES3_EDE_EXPKEY_WORDS];
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_civoid des_encrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
288c2ecf20Sopenharmony_civoid des_decrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_civoid des3_ede_encrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
318c2ecf20Sopenharmony_civoid des3_ede_decrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/**
348c2ecf20Sopenharmony_ci * des_expand_key - Expand a DES input key into a key schedule
358c2ecf20Sopenharmony_ci * @ctx: the key schedule
368c2ecf20Sopenharmony_ci * @key: buffer containing the input key
378c2ecf20Sopenharmony_ci * @len: size of the buffer contents
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
408c2ecf20Sopenharmony_ci * the key is accepted but has been found to be weak.
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_ciint des_expand_key(struct des_ctx *ctx, const u8 *key, unsigned int keylen);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/**
458c2ecf20Sopenharmony_ci * des3_ede_expand_key - Expand a triple DES input key into a key schedule
468c2ecf20Sopenharmony_ci * @ctx: the key schedule
478c2ecf20Sopenharmony_ci * @key: buffer containing the input key
488c2ecf20Sopenharmony_ci * @len: size of the buffer contents
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
518c2ecf20Sopenharmony_ci * the key is accepted but has been found to be weak. Note that weak keys will
528c2ecf20Sopenharmony_ci * be rejected (and -EINVAL will be returned) when running in FIPS mode.
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_ciint des3_ede_expand_key(struct des3_ede_ctx *ctx, const u8 *key,
558c2ecf20Sopenharmony_ci			unsigned int keylen);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#endif /* __CRYPTO_DES_H */
58