aead.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/types.h>
  17. struct rtattr;
  18. struct crypto_aead_spawn {
  19. struct crypto_spawn base;
  20. };
  21. extern const struct crypto_type crypto_aead_type;
  22. extern const struct crypto_type crypto_nivaead_type;
  23. static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm)
  24. {
  25. return &crypto_aead_tfm(tfm)->__crt_alg->cra_aead;
  26. }
  27. static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
  28. {
  29. return crypto_tfm_ctx(&tfm->base);
  30. }
  31. static inline struct crypto_instance *crypto_aead_alg_instance(
  32. struct crypto_aead *aead)
  33. {
  34. return crypto_tfm_alg_instance(&aead->base);
  35. }
  36. static inline void *aead_request_ctx(struct aead_request *req)
  37. {
  38. return req->__ctx;
  39. }
  40. static inline void aead_request_complete(struct aead_request *req, int err)
  41. {
  42. req->base.complete(&req->base, err);
  43. }
  44. static inline u32 aead_request_flags(struct aead_request *req)
  45. {
  46. return req->base.flags;
  47. }
  48. static inline void crypto_set_aead_spawn(
  49. struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
  50. {
  51. crypto_set_spawn(&spawn->base, inst);
  52. }
  53. struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask);
  54. int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
  55. u32 type, u32 mask);
  56. static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
  57. {
  58. crypto_drop_spawn(&spawn->base);
  59. }
  60. static inline struct crypto_alg *crypto_aead_spawn_alg(
  61. struct crypto_aead_spawn *spawn)
  62. {
  63. return spawn->base.alg;
  64. }
  65. static inline struct crypto_aead *crypto_spawn_aead(
  66. struct crypto_aead_spawn *spawn)
  67. {
  68. return crypto_spawn_tfm2(&spawn->base);
  69. }
  70. struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl,
  71. struct rtattr **tb, u32 type,
  72. u32 mask);
  73. void aead_geniv_free(struct crypto_instance *inst);
  74. int aead_geniv_init(struct crypto_tfm *tfm);
  75. void aead_geniv_exit(struct crypto_tfm *tfm);
  76. static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
  77. {
  78. return geniv->child;
  79. }
  80. static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req)
  81. {
  82. return aead_request_ctx(&req->areq);
  83. }
  84. static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req,
  85. int err)
  86. {
  87. aead_request_complete(&req->areq, err);
  88. }
  89. static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
  90. unsigned int reqsize)
  91. {
  92. crypto_aead_crt(aead)->reqsize = reqsize;
  93. }
  94. #endif /* _CRYPTO_INTERNAL_AEAD_H */