sig.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Public Key Signature Algorithm
  4. *
  5. * Copyright (c) 2023 Herbert Xu <herbert@gondor.apana.org.au>
  6. */
  7. #ifndef _CRYPTO_INTERNAL_SIG_H
  8. #define _CRYPTO_INTERNAL_SIG_H
  9. #include <crypto/algapi.h>
  10. #include <crypto/sig.h>
  11. struct sig_instance {
  12. void (*free)(struct sig_instance *inst);
  13. union {
  14. struct {
  15. char head[offsetof(struct sig_alg, base)];
  16. struct crypto_instance base;
  17. };
  18. struct sig_alg alg;
  19. };
  20. };
  21. struct crypto_sig_spawn {
  22. struct crypto_spawn base;
  23. };
  24. static inline void *crypto_sig_ctx(struct crypto_sig *tfm)
  25. {
  26. return crypto_tfm_ctx(&tfm->base);
  27. }
  28. /**
  29. * crypto_register_sig() -- Register public key signature algorithm
  30. *
  31. * Function registers an implementation of a public key signature algorithm
  32. *
  33. * @alg: algorithm definition
  34. *
  35. * Return: zero on success; error code in case of error
  36. */
  37. int crypto_register_sig(struct sig_alg *alg);
  38. /**
  39. * crypto_unregister_sig() -- Unregister public key signature algorithm
  40. *
  41. * Function unregisters an implementation of a public key signature algorithm
  42. *
  43. * @alg: algorithm definition
  44. */
  45. void crypto_unregister_sig(struct sig_alg *alg);
  46. int sig_register_instance(struct crypto_template *tmpl,
  47. struct sig_instance *inst);
  48. static inline struct sig_instance *sig_instance(struct crypto_instance *inst)
  49. {
  50. return container_of(&inst->alg, struct sig_instance, alg.base);
  51. }
  52. static inline struct sig_instance *sig_alg_instance(struct crypto_sig *tfm)
  53. {
  54. return sig_instance(crypto_tfm_alg_instance(&tfm->base));
  55. }
  56. static inline struct crypto_instance *sig_crypto_instance(struct sig_instance
  57. *inst)
  58. {
  59. return container_of(&inst->alg.base, struct crypto_instance, alg);
  60. }
  61. static inline void *sig_instance_ctx(struct sig_instance *inst)
  62. {
  63. return crypto_instance_ctx(sig_crypto_instance(inst));
  64. }
  65. int crypto_grab_sig(struct crypto_sig_spawn *spawn,
  66. struct crypto_instance *inst,
  67. const char *name, u32 type, u32 mask);
  68. static inline struct crypto_sig *crypto_spawn_sig(struct crypto_sig_spawn
  69. *spawn)
  70. {
  71. return crypto_spawn_tfm2(&spawn->base);
  72. }
  73. static inline void crypto_drop_sig(struct crypto_sig_spawn *spawn)
  74. {
  75. crypto_drop_spawn(&spawn->base);
  76. }
  77. static inline struct sig_alg *crypto_spawn_sig_alg(struct crypto_sig_spawn
  78. *spawn)
  79. {
  80. return container_of(spawn->base.alg, struct sig_alg, base);
  81. }
  82. #endif