akcipher.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Public Key Encryption
  4. *
  5. * Copyright (c) 2015, Intel Corporation
  6. * Authors: Tadeusz Struk <[email protected]>
  7. */
  8. #ifndef _CRYPTO_AKCIPHER_INT_H
  9. #define _CRYPTO_AKCIPHER_INT_H
  10. #include <crypto/akcipher.h>
  11. #include <crypto/algapi.h>
  12. struct akcipher_instance {
  13. void (*free)(struct akcipher_instance *inst);
  14. union {
  15. struct {
  16. char head[offsetof(struct akcipher_alg, base)];
  17. struct crypto_instance base;
  18. } s;
  19. struct akcipher_alg alg;
  20. };
  21. };
  22. struct crypto_akcipher_spawn {
  23. struct crypto_spawn base;
  24. };
  25. /*
  26. * Transform internal helpers.
  27. */
  28. static inline void *akcipher_request_ctx(struct akcipher_request *req)
  29. {
  30. return req->__ctx;
  31. }
  32. static inline void akcipher_set_reqsize(struct crypto_akcipher *akcipher,
  33. unsigned int reqsize)
  34. {
  35. crypto_akcipher_alg(akcipher)->reqsize = reqsize;
  36. }
  37. static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm)
  38. {
  39. return tfm->base.__crt_ctx;
  40. }
  41. static inline void akcipher_request_complete(struct akcipher_request *req,
  42. int err)
  43. {
  44. req->base.complete(&req->base, err);
  45. }
  46. static inline const char *akcipher_alg_name(struct crypto_akcipher *tfm)
  47. {
  48. return crypto_akcipher_tfm(tfm)->__crt_alg->cra_name;
  49. }
  50. static inline struct crypto_instance *akcipher_crypto_instance(
  51. struct akcipher_instance *inst)
  52. {
  53. return container_of(&inst->alg.base, struct crypto_instance, alg);
  54. }
  55. static inline struct akcipher_instance *akcipher_instance(
  56. struct crypto_instance *inst)
  57. {
  58. return container_of(&inst->alg, struct akcipher_instance, alg.base);
  59. }
  60. static inline struct akcipher_instance *akcipher_alg_instance(
  61. struct crypto_akcipher *akcipher)
  62. {
  63. return akcipher_instance(crypto_tfm_alg_instance(&akcipher->base));
  64. }
  65. static inline void *akcipher_instance_ctx(struct akcipher_instance *inst)
  66. {
  67. return crypto_instance_ctx(akcipher_crypto_instance(inst));
  68. }
  69. int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn,
  70. struct crypto_instance *inst,
  71. const char *name, u32 type, u32 mask);
  72. static inline struct crypto_akcipher *crypto_spawn_akcipher(
  73. struct crypto_akcipher_spawn *spawn)
  74. {
  75. return crypto_spawn_tfm2(&spawn->base);
  76. }
  77. static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn *spawn)
  78. {
  79. crypto_drop_spawn(&spawn->base);
  80. }
  81. static inline struct akcipher_alg *crypto_spawn_akcipher_alg(
  82. struct crypto_akcipher_spawn *spawn)
  83. {
  84. return container_of(spawn->base.alg, struct akcipher_alg, base);
  85. }
  86. /**
  87. * crypto_register_akcipher() -- Register public key algorithm
  88. *
  89. * Function registers an implementation of a public key verify algorithm
  90. *
  91. * @alg: algorithm definition
  92. *
  93. * Return: zero on success; error code in case of error
  94. */
  95. int crypto_register_akcipher(struct akcipher_alg *alg);
  96. /**
  97. * crypto_unregister_akcipher() -- Unregister public key algorithm
  98. *
  99. * Function unregisters an implementation of a public key verify algorithm
  100. *
  101. * @alg: algorithm definition
  102. */
  103. void crypto_unregister_akcipher(struct akcipher_alg *alg);
  104. /**
  105. * akcipher_register_instance() -- Unregister public key template instance
  106. *
  107. * Function registers an implementation of an asymmetric key algorithm
  108. * created from a template
  109. *
  110. * @tmpl: the template from which the algorithm was created
  111. * @inst: the template instance
  112. */
  113. int akcipher_register_instance(struct crypto_template *tmpl,
  114. struct akcipher_instance *inst);
  115. #endif