akcipher.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_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. static inline void crypto_set_akcipher_spawn(
  70. struct crypto_akcipher_spawn *spawn,
  71. struct crypto_instance *inst)
  72. {
  73. crypto_set_spawn(&spawn->base, inst);
  74. }
  75. int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, const char *name,
  76. u32 type, u32 mask);
  77. static inline struct crypto_akcipher *crypto_spawn_akcipher(
  78. struct crypto_akcipher_spawn *spawn)
  79. {
  80. return crypto_spawn_tfm2(&spawn->base);
  81. }
  82. static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn *spawn)
  83. {
  84. crypto_drop_spawn(&spawn->base);
  85. }
  86. static inline struct akcipher_alg *crypto_spawn_akcipher_alg(
  87. struct crypto_akcipher_spawn *spawn)
  88. {
  89. return container_of(spawn->base.alg, struct akcipher_alg, base);
  90. }
  91. /**
  92. * crypto_register_akcipher() -- Register public key algorithm
  93. *
  94. * Function registers an implementation of a public key verify algorithm
  95. *
  96. * @alg: algorithm definition
  97. *
  98. * Return: zero on success; error code in case of error
  99. */
  100. int crypto_register_akcipher(struct akcipher_alg *alg);
  101. /**
  102. * crypto_unregister_akcipher() -- Unregister public key algorithm
  103. *
  104. * Function unregisters an implementation of a public key verify algorithm
  105. *
  106. * @alg: algorithm definition
  107. */
  108. void crypto_unregister_akcipher(struct akcipher_alg *alg);
  109. /**
  110. * akcipher_register_instance() -- Unregister public key template instance
  111. *
  112. * Function registers an implementation of an asymmetric key algorithm
  113. * created from a template
  114. *
  115. * @tmpl: the template from which the algorithm was created
  116. * @inst: the template instance
  117. */
  118. int akcipher_register_instance(struct crypto_template *tmpl,
  119. struct akcipher_instance *inst);
  120. #endif