mcryptd.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Software async multibuffer crypto daemon headers
  4. *
  5. * Author:
  6. * Tim Chen <tim.c.chen@linux.intel.com>
  7. *
  8. * Copyright (c) 2014, Intel Corporation.
  9. */
  10. #ifndef _CRYPTO_MCRYPT_H
  11. #define _CRYPTO_MCRYPT_H
  12. #include <linux/crypto.h>
  13. #include <linux/kernel.h>
  14. #include <crypto/hash.h>
  15. struct mcryptd_ahash {
  16. struct crypto_ahash base;
  17. };
  18. static inline struct mcryptd_ahash *__mcryptd_ahash_cast(
  19. struct crypto_ahash *tfm)
  20. {
  21. return (struct mcryptd_ahash *)tfm;
  22. }
  23. struct mcryptd_cpu_queue {
  24. struct crypto_queue queue;
  25. spinlock_t q_lock;
  26. struct work_struct work;
  27. };
  28. struct mcryptd_queue {
  29. struct mcryptd_cpu_queue __percpu *cpu_queue;
  30. };
  31. struct mcryptd_instance_ctx {
  32. struct crypto_spawn spawn;
  33. struct mcryptd_queue *queue;
  34. };
  35. struct mcryptd_hash_ctx {
  36. struct crypto_ahash *child;
  37. struct mcryptd_alg_state *alg_state;
  38. };
  39. struct mcryptd_tag {
  40. /* seq number of request */
  41. unsigned seq_num;
  42. /* arrival time of request */
  43. unsigned long arrival;
  44. unsigned long expire;
  45. int cpu;
  46. };
  47. struct mcryptd_hash_request_ctx {
  48. struct list_head waiter;
  49. crypto_completion_t complete;
  50. struct mcryptd_tag tag;
  51. struct crypto_hash_walk walk;
  52. u8 *out;
  53. int flag;
  54. struct ahash_request areq;
  55. };
  56. struct mcryptd_ahash *mcryptd_alloc_ahash(const char *alg_name,
  57. u32 type, u32 mask);
  58. struct crypto_ahash *mcryptd_ahash_child(struct mcryptd_ahash *tfm);
  59. struct ahash_request *mcryptd_ahash_desc(struct ahash_request *req);
  60. void mcryptd_free_ahash(struct mcryptd_ahash *tfm);
  61. void mcryptd_flusher(struct work_struct *work);
  62. enum mcryptd_req_type {
  63. MCRYPTD_NONE,
  64. MCRYPTD_UPDATE,
  65. MCRYPTD_FINUP,
  66. MCRYPTD_DIGEST,
  67. MCRYPTD_FINAL
  68. };
  69. struct mcryptd_alg_cstate {
  70. unsigned long next_flush;
  71. unsigned next_seq_num;
  72. bool flusher_engaged;
  73. struct delayed_work flush;
  74. int cpu;
  75. struct mcryptd_alg_state *alg_state;
  76. void *mgr;
  77. spinlock_t work_lock;
  78. struct list_head work_list;
  79. struct list_head flush_list;
  80. };
  81. struct mcryptd_alg_state {
  82. struct mcryptd_alg_cstate __percpu *alg_cstate;
  83. unsigned long (*flusher)(struct mcryptd_alg_cstate *cstate);
  84. };
  85. /* return delay in jiffies from current time */
  86. static inline unsigned long get_delay(unsigned long t)
  87. {
  88. long delay;
  89. delay = (long) t - (long) jiffies;
  90. if (delay <= 0)
  91. return 0;
  92. else
  93. return (unsigned long) delay;
  94. }
  95. void mcryptd_arm_flusher(struct mcryptd_alg_cstate *cstate, unsigned long delay);
  96. #endif