skcipher.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Symmetric key ciphers.
  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_SKCIPHER_H
  13. #define _CRYPTO_INTERNAL_SKCIPHER_H
  14. #include <crypto/algapi.h>
  15. #include <crypto/skcipher.h>
  16. #include <linux/init.h>
  17. #include <linux/types.h>
  18. struct rtattr;
  19. struct crypto_skcipher_spawn {
  20. struct crypto_spawn base;
  21. };
  22. extern const struct crypto_type crypto_givcipher_type;
  23. static inline void crypto_set_skcipher_spawn(
  24. struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
  25. {
  26. crypto_set_spawn(&spawn->base, inst);
  27. }
  28. int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
  29. u32 type, u32 mask);
  30. static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
  31. {
  32. crypto_drop_spawn(&spawn->base);
  33. }
  34. static inline struct crypto_alg *crypto_skcipher_spawn_alg(
  35. struct crypto_skcipher_spawn *spawn)
  36. {
  37. return spawn->base.alg;
  38. }
  39. static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
  40. struct crypto_skcipher_spawn *spawn)
  41. {
  42. return __crypto_ablkcipher_cast(
  43. crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0),
  44. crypto_skcipher_mask(0)));
  45. }
  46. int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req);
  47. int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req);
  48. const char *crypto_default_geniv(const struct crypto_alg *alg);
  49. struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
  50. struct rtattr **tb, u32 type,
  51. u32 mask);
  52. void skcipher_geniv_free(struct crypto_instance *inst);
  53. int skcipher_geniv_init(struct crypto_tfm *tfm);
  54. void skcipher_geniv_exit(struct crypto_tfm *tfm);
  55. int __init eseqiv_module_init(void);
  56. void __exit eseqiv_module_exit(void);
  57. int __init chainiv_module_init(void);
  58. void chainiv_module_exit(void);
  59. static inline struct crypto_ablkcipher *skcipher_geniv_cipher(
  60. struct crypto_ablkcipher *geniv)
  61. {
  62. return crypto_ablkcipher_crt(geniv)->base;
  63. }
  64. static inline int skcipher_enqueue_givcrypt(
  65. struct crypto_queue *queue, struct skcipher_givcrypt_request *request)
  66. {
  67. return ablkcipher_enqueue_request(queue, &request->creq);
  68. }
  69. static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt(
  70. struct crypto_queue *queue)
  71. {
  72. return container_of(ablkcipher_dequeue_request(queue),
  73. struct skcipher_givcrypt_request, creq);
  74. }
  75. static inline void *skcipher_givcrypt_reqctx(
  76. struct skcipher_givcrypt_request *req)
  77. {
  78. return ablkcipher_request_ctx(&req->creq);
  79. }
  80. static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
  81. int err)
  82. {
  83. req->base.complete(&req->base, err);
  84. }
  85. static inline void skcipher_givcrypt_complete(
  86. struct skcipher_givcrypt_request *req, int err)
  87. {
  88. ablkcipher_request_complete(&req->creq, err);
  89. }
  90. static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
  91. {
  92. return req->base.flags;
  93. }
  94. #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */