aead.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * AEAD: Authenticated Encryption with Associated Data
  4. *
  5. * Copyright (c) 2007-2015 Herbert Xu <[email protected]>
  6. */
  7. #ifndef _CRYPTO_INTERNAL_AEAD_H
  8. #define _CRYPTO_INTERNAL_AEAD_H
  9. #include <crypto/aead.h>
  10. #include <crypto/algapi.h>
  11. #include <linux/stddef.h>
  12. #include <linux/types.h>
  13. struct rtattr;
  14. struct aead_instance {
  15. void (*free)(struct aead_instance *inst);
  16. union {
  17. struct {
  18. char head[offsetof(struct aead_alg, base)];
  19. struct crypto_instance base;
  20. } s;
  21. struct aead_alg alg;
  22. };
  23. };
  24. struct crypto_aead_spawn {
  25. struct crypto_spawn base;
  26. };
  27. struct aead_queue {
  28. struct crypto_queue base;
  29. };
  30. static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
  31. {
  32. return crypto_tfm_ctx(&tfm->base);
  33. }
  34. static inline struct crypto_instance *aead_crypto_instance(
  35. struct aead_instance *inst)
  36. {
  37. return container_of(&inst->alg.base, struct crypto_instance, alg);
  38. }
  39. static inline struct aead_instance *aead_instance(struct crypto_instance *inst)
  40. {
  41. return container_of(&inst->alg, struct aead_instance, alg.base);
  42. }
  43. static inline struct aead_instance *aead_alg_instance(struct crypto_aead *aead)
  44. {
  45. return aead_instance(crypto_tfm_alg_instance(&aead->base));
  46. }
  47. static inline void *aead_instance_ctx(struct aead_instance *inst)
  48. {
  49. return crypto_instance_ctx(aead_crypto_instance(inst));
  50. }
  51. static inline void *aead_request_ctx(struct aead_request *req)
  52. {
  53. return req->__ctx;
  54. }
  55. static inline void aead_request_complete(struct aead_request *req, int err)
  56. {
  57. req->base.complete(&req->base, err);
  58. }
  59. static inline u32 aead_request_flags(struct aead_request *req)
  60. {
  61. return req->base.flags;
  62. }
  63. static inline struct aead_request *aead_request_cast(
  64. struct crypto_async_request *req)
  65. {
  66. return container_of(req, struct aead_request, base);
  67. }
  68. int crypto_grab_aead(struct crypto_aead_spawn *spawn,
  69. struct crypto_instance *inst,
  70. const char *name, u32 type, u32 mask);
  71. static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
  72. {
  73. crypto_drop_spawn(&spawn->base);
  74. }
  75. static inline struct aead_alg *crypto_spawn_aead_alg(
  76. struct crypto_aead_spawn *spawn)
  77. {
  78. return container_of(spawn->base.alg, struct aead_alg, base);
  79. }
  80. static inline struct crypto_aead *crypto_spawn_aead(
  81. struct crypto_aead_spawn *spawn)
  82. {
  83. return crypto_spawn_tfm2(&spawn->base);
  84. }
  85. static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
  86. unsigned int reqsize)
  87. {
  88. aead->reqsize = reqsize;
  89. }
  90. static inline void aead_init_queue(struct aead_queue *queue,
  91. unsigned int max_qlen)
  92. {
  93. crypto_init_queue(&queue->base, max_qlen);
  94. }
  95. static inline unsigned int crypto_aead_alg_chunksize(struct aead_alg *alg)
  96. {
  97. return alg->chunksize;
  98. }
  99. /**
  100. * crypto_aead_chunksize() - obtain chunk size
  101. * @tfm: cipher handle
  102. *
  103. * The block size is set to one for ciphers such as CCM. However,
  104. * you still need to provide incremental updates in multiples of
  105. * the underlying block size as the IV does not have sub-block
  106. * granularity. This is known in this API as the chunk size.
  107. *
  108. * Return: chunk size in bytes
  109. */
  110. static inline unsigned int crypto_aead_chunksize(struct crypto_aead *tfm)
  111. {
  112. return crypto_aead_alg_chunksize(crypto_aead_alg(tfm));
  113. }
  114. int crypto_register_aead(struct aead_alg *alg);
  115. void crypto_unregister_aead(struct aead_alg *alg);
  116. int crypto_register_aeads(struct aead_alg *algs, int count);
  117. void crypto_unregister_aeads(struct aead_alg *algs, int count);
  118. int aead_register_instance(struct crypto_template *tmpl,
  119. struct aead_instance *inst);
  120. #endif /* _CRYPTO_INTERNAL_AEAD_H */