aead.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * AEAD: Authenticated Encryption with Associated Data
  3. *
  4. * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. */
  12. #ifndef _CRYPTO_INTERNAL_AEAD_H
  13. #define _CRYPTO_INTERNAL_AEAD_H
  14. #include <crypto/aead.h>
  15. #include <crypto/algapi.h>
  16. #include <linux/stddef.h>
  17. #include <linux/types.h>
  18. struct rtattr;
  19. struct aead_instance {
  20. union {
  21. struct {
  22. char head[offsetof(struct aead_alg, base)];
  23. struct crypto_instance base;
  24. } s;
  25. struct aead_alg alg;
  26. };
  27. };
  28. struct crypto_aead_spawn {
  29. struct crypto_spawn base;
  30. };
  31. extern const struct crypto_type crypto_aead_type;
  32. extern const struct crypto_type crypto_nivaead_type;
  33. static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
  34. {
  35. return crypto_tfm_ctx(&tfm->base);
  36. }
  37. static inline struct crypto_instance *crypto_aead_alg_instance(
  38. struct crypto_aead *aead)
  39. {
  40. return crypto_tfm_alg_instance(&aead->base);
  41. }
  42. static inline struct crypto_instance *aead_crypto_instance(
  43. struct aead_instance *inst)
  44. {
  45. return container_of(&inst->alg.base, struct crypto_instance, alg);
  46. }
  47. static inline struct aead_instance *aead_instance(struct crypto_instance *inst)
  48. {
  49. return container_of(&inst->alg, struct aead_instance, alg.base);
  50. }
  51. static inline struct aead_instance *aead_alg_instance(struct crypto_aead *aead)
  52. {
  53. return aead_instance(crypto_aead_alg_instance(aead));
  54. }
  55. static inline void *aead_instance_ctx(struct aead_instance *inst)
  56. {
  57. return crypto_instance_ctx(aead_crypto_instance(inst));
  58. }
  59. static inline void *aead_request_ctx(struct aead_request *req)
  60. {
  61. return req->__ctx;
  62. }
  63. static inline void aead_request_complete(struct aead_request *req, int err)
  64. {
  65. req->base.complete(&req->base, err);
  66. }
  67. static inline u32 aead_request_flags(struct aead_request *req)
  68. {
  69. return req->base.flags;
  70. }
  71. static inline void crypto_set_aead_spawn(
  72. struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
  73. {
  74. crypto_set_spawn(&spawn->base, inst);
  75. }
  76. struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask);
  77. int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
  78. u32 type, u32 mask);
  79. static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
  80. {
  81. crypto_drop_spawn(&spawn->base);
  82. }
  83. static inline struct crypto_alg *crypto_aead_spawn_alg(
  84. struct crypto_aead_spawn *spawn)
  85. {
  86. return spawn->base.alg;
  87. }
  88. static inline struct aead_alg *crypto_spawn_aead_alg(
  89. struct crypto_aead_spawn *spawn)
  90. {
  91. return container_of(spawn->base.alg, struct aead_alg, base);
  92. }
  93. static inline struct crypto_aead *crypto_spawn_aead(
  94. struct crypto_aead_spawn *spawn)
  95. {
  96. return crypto_spawn_tfm2(&spawn->base);
  97. }
  98. struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
  99. struct rtattr **tb, u32 type, u32 mask);
  100. void aead_geniv_free(struct aead_instance *inst);
  101. int aead_geniv_init(struct crypto_tfm *tfm);
  102. void aead_geniv_exit(struct crypto_tfm *tfm);
  103. static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
  104. {
  105. return geniv->child;
  106. }
  107. static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req)
  108. {
  109. return aead_request_ctx(&req->areq);
  110. }
  111. static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req,
  112. int err)
  113. {
  114. aead_request_complete(&req->areq, err);
  115. }
  116. static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
  117. unsigned int reqsize)
  118. {
  119. crypto_aead_crt(aead)->reqsize = reqsize;
  120. }
  121. static inline unsigned int crypto_aead_alg_maxauthsize(struct aead_alg *alg)
  122. {
  123. return alg->base.cra_aead.encrypt ? alg->base.cra_aead.maxauthsize :
  124. alg->maxauthsize;
  125. }
  126. static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead)
  127. {
  128. return crypto_aead_alg_maxauthsize(crypto_aead_alg(aead));
  129. }
  130. int crypto_register_aead(struct aead_alg *alg);
  131. void crypto_unregister_aead(struct aead_alg *alg);
  132. int crypto_register_aeads(struct aead_alg *algs, int count);
  133. void crypto_unregister_aeads(struct aead_alg *algs, int count);
  134. int aead_register_instance(struct crypto_template *tmpl,
  135. struct aead_instance *inst);
  136. #endif /* _CRYPTO_INTERNAL_AEAD_H */