Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* 
0003  * DES & Triple DES EDE Cipher Algorithms.
0004  */
0005 
0006 #ifndef __CRYPTO_DES_H
0007 #define __CRYPTO_DES_H
0008 
0009 #include <linux/types.h>
0010 
0011 #define DES_KEY_SIZE        8
0012 #define DES_EXPKEY_WORDS    32
0013 #define DES_BLOCK_SIZE      8
0014 
0015 #define DES3_EDE_KEY_SIZE   (3 * DES_KEY_SIZE)
0016 #define DES3_EDE_EXPKEY_WORDS   (3 * DES_EXPKEY_WORDS)
0017 #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
0018 
0019 struct des_ctx {
0020     u32 expkey[DES_EXPKEY_WORDS];
0021 };
0022 
0023 struct des3_ede_ctx {
0024     u32 expkey[DES3_EDE_EXPKEY_WORDS];
0025 };
0026 
0027 void des_encrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
0028 void des_decrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src);
0029 
0030 void des3_ede_encrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
0031 void des3_ede_decrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src);
0032 
0033 /**
0034  * des_expand_key - Expand a DES input key into a key schedule
0035  * @ctx: the key schedule
0036  * @key: buffer containing the input key
0037  * @len: size of the buffer contents
0038  *
0039  * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
0040  * the key is accepted but has been found to be weak.
0041  */
0042 int des_expand_key(struct des_ctx *ctx, const u8 *key, unsigned int keylen);
0043 
0044 /**
0045  * des3_ede_expand_key - Expand a triple DES input key into a key schedule
0046  * @ctx: the key schedule
0047  * @key: buffer containing the input key
0048  * @len: size of the buffer contents
0049  *
0050  * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if
0051  * the key is accepted but has been found to be weak. Note that weak keys will
0052  * be rejected (and -EINVAL will be returned) when running in FIPS mode.
0053  */
0054 int des3_ede_expand_key(struct des3_ede_ctx *ctx, const u8 *key,
0055             unsigned int keylen);
0056 
0057 #endif /* __CRYPTO_DES_H */