internal.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Cryptographic API.
  4. *
  5. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  6. * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
  7. */
  8. #ifndef _CRYPTO_INTERNAL_H
  9. #define _CRYPTO_INTERNAL_H
  10. #include <crypto/algapi.h>
  11. #include <linux/completion.h>
  12. #include <linux/list.h>
  13. #include <linux/module.h>
  14. #include <linux/notifier.h>
  15. #include <linux/numa.h>
  16. #include <linux/refcount.h>
  17. #include <linux/rwsem.h>
  18. #include <linux/sched.h>
  19. #include <linux/types.h>
  20. struct crypto_instance;
  21. struct crypto_template;
  22. struct crypto_larval {
  23. struct crypto_alg alg;
  24. struct crypto_alg *adult;
  25. struct completion completion;
  26. u32 mask;
  27. };
  28. extern struct list_head crypto_alg_list;
  29. extern struct rw_semaphore crypto_alg_sem;
  30. extern struct blocking_notifier_head crypto_chain;
  31. #ifdef CONFIG_PROC_FS
  32. void __init crypto_init_proc(void);
  33. void __exit crypto_exit_proc(void);
  34. #else
  35. static inline void crypto_init_proc(void)
  36. { }
  37. static inline void crypto_exit_proc(void)
  38. { }
  39. #endif
  40. static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg)
  41. {
  42. return alg->cra_ctxsize;
  43. }
  44. static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg)
  45. {
  46. return alg->cra_ctxsize;
  47. }
  48. struct crypto_alg *crypto_mod_get(struct crypto_alg *alg);
  49. struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask);
  50. struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask);
  51. void crypto_larval_kill(struct crypto_alg *alg);
  52. void crypto_alg_tested(const char *name, int err);
  53. void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
  54. struct crypto_alg *nalg);
  55. void crypto_remove_final(struct list_head *list);
  56. void crypto_shoot_alg(struct crypto_alg *alg);
  57. struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
  58. u32 mask);
  59. void *crypto_create_tfm_node(struct crypto_alg *alg,
  60. const struct crypto_type *frontend, int node);
  61. static inline void *crypto_create_tfm(struct crypto_alg *alg,
  62. const struct crypto_type *frontend)
  63. {
  64. return crypto_create_tfm_node(alg, frontend, NUMA_NO_NODE);
  65. }
  66. struct crypto_alg *crypto_find_alg(const char *alg_name,
  67. const struct crypto_type *frontend,
  68. u32 type, u32 mask);
  69. void *crypto_alloc_tfm_node(const char *alg_name,
  70. const struct crypto_type *frontend, u32 type, u32 mask,
  71. int node);
  72. static inline void *crypto_alloc_tfm(const char *alg_name,
  73. const struct crypto_type *frontend, u32 type, u32 mask)
  74. {
  75. return crypto_alloc_tfm_node(alg_name, frontend, type, mask, NUMA_NO_NODE);
  76. }
  77. int crypto_probing_notify(unsigned long val, void *v);
  78. unsigned int crypto_alg_extsize(struct crypto_alg *alg);
  79. int crypto_type_has_alg(const char *name, const struct crypto_type *frontend,
  80. u32 type, u32 mask);
  81. static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
  82. {
  83. refcount_inc(&alg->cra_refcnt);
  84. return alg;
  85. }
  86. static inline void crypto_alg_put(struct crypto_alg *alg)
  87. {
  88. if (refcount_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
  89. alg->cra_destroy(alg);
  90. }
  91. static inline int crypto_tmpl_get(struct crypto_template *tmpl)
  92. {
  93. return try_module_get(tmpl->module);
  94. }
  95. static inline void crypto_tmpl_put(struct crypto_template *tmpl)
  96. {
  97. module_put(tmpl->module);
  98. }
  99. static inline int crypto_is_larval(struct crypto_alg *alg)
  100. {
  101. return alg->cra_flags & CRYPTO_ALG_LARVAL;
  102. }
  103. static inline int crypto_is_dead(struct crypto_alg *alg)
  104. {
  105. return alg->cra_flags & CRYPTO_ALG_DEAD;
  106. }
  107. static inline int crypto_is_moribund(struct crypto_alg *alg)
  108. {
  109. return alg->cra_flags & (CRYPTO_ALG_DEAD | CRYPTO_ALG_DYING);
  110. }
  111. static inline void crypto_notify(unsigned long val, void *v)
  112. {
  113. blocking_notifier_call_chain(&crypto_chain, val, v);
  114. }
  115. static inline void crypto_yield(u32 flags)
  116. {
  117. if (flags & CRYPTO_TFM_REQ_MAY_SLEEP)
  118. cond_resched();
  119. }
  120. #endif /* _CRYPTO_INTERNAL_H */