akcipher.h 3.6 KB

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