skcipher.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/types.h>
  17. struct rtattr;
  18. struct crypto_skcipher_spawn {
  19. struct crypto_spawn base;
  20. };
  21. extern const struct crypto_type crypto_givcipher_type;
  22. static inline void crypto_set_skcipher_spawn(
  23. struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
  24. {
  25. crypto_set_spawn(&spawn->base, inst);
  26. }
  27. int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
  28. u32 type, u32 mask);
  29. static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
  30. {
  31. crypto_drop_spawn(&spawn->base);
  32. }
  33. static inline struct crypto_alg *crypto_skcipher_spawn_alg(
  34. struct crypto_skcipher_spawn *spawn)
  35. {
  36. return spawn->base.alg;
  37. }
  38. static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
  39. struct crypto_skcipher_spawn *spawn)
  40. {
  41. return __crypto_ablkcipher_cast(
  42. crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0),
  43. crypto_skcipher_mask(0)));
  44. }
  45. int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req);
  46. int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req);
  47. const char *crypto_default_geniv(const struct crypto_alg *alg);
  48. struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
  49. struct rtattr **tb, u32 type,
  50. u32 mask);
  51. void skcipher_geniv_free(struct crypto_instance *inst);
  52. int skcipher_geniv_init(struct crypto_tfm *tfm);
  53. void skcipher_geniv_exit(struct crypto_tfm *tfm);
  54. static inline struct crypto_ablkcipher *skcipher_geniv_cipher(
  55. struct crypto_ablkcipher *geniv)
  56. {
  57. return crypto_ablkcipher_crt(geniv)->base;
  58. }
  59. static inline void *skcipher_givcrypt_reqctx(
  60. struct skcipher_givcrypt_request *req)
  61. {
  62. return ablkcipher_request_ctx(&req->creq);
  63. }
  64. static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
  65. int err)
  66. {
  67. req->base.complete(&req->base, err);
  68. }
  69. static inline void skcipher_givcrypt_complete(
  70. struct skcipher_givcrypt_request *req, int err)
  71. {
  72. ablkcipher_request_complete(&req->creq, err);
  73. }
  74. static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
  75. {
  76. return req->base.flags;
  77. }
  78. #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */