key_gen.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * CAAM/SEC 4.x definitions for handling key-generation jobs
  4. *
  5. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  6. *
  7. */
  8. /**
  9. * split_key_len - Compute MDHA split key length for a given algorithm
  10. * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1,
  11. * SHA224, SHA384, SHA512.
  12. *
  13. * Return: MDHA split key length
  14. */
  15. static inline u32 split_key_len(u32 hash)
  16. {
  17. /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */
  18. static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 };
  19. u32 idx;
  20. idx = (hash & OP_ALG_ALGSEL_SUBMASK) >> OP_ALG_ALGSEL_SHIFT;
  21. return (u32)(mdpadlen[idx] * 2);
  22. }
  23. /**
  24. * split_key_pad_len - Compute MDHA split key pad length for a given algorithm
  25. * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1,
  26. * SHA224, SHA384, SHA512.
  27. *
  28. * Return: MDHA split key pad length
  29. */
  30. static inline u32 split_key_pad_len(u32 hash)
  31. {
  32. return ALIGN(split_key_len(hash), 16);
  33. }
  34. struct split_key_result {
  35. struct completion completion;
  36. int err;
  37. };
  38. void split_key_done(struct device *dev, u32 *desc, u32 err, void *context);
  39. int gen_split_key(struct device *jrdev, u8 *key_out,
  40. struct alginfo * const adata, const u8 *key_in, u32 keylen,
  41. int max_keylen);