des.h 1.7 KB

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