mcryptd.h 2.3 KB

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