skcipher.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 skcipher_instance {
  19. void (*free)(struct skcipher_instance *inst);
  20. union {
  21. struct {
  22. char head[offsetof(struct skcipher_alg, base)];
  23. struct crypto_instance base;
  24. } s;
  25. struct skcipher_alg alg;
  26. };
  27. };
  28. struct crypto_skcipher_spawn {
  29. struct crypto_spawn base;
  30. };
  31. extern const struct crypto_type crypto_givcipher_type;
  32. static inline struct crypto_instance *skcipher_crypto_instance(
  33. struct skcipher_instance *inst)
  34. {
  35. return &inst->s.base;
  36. }
  37. static inline struct skcipher_instance *skcipher_alg_instance(
  38. struct crypto_skcipher *skcipher)
  39. {
  40. return container_of(crypto_skcipher_alg(skcipher),
  41. struct skcipher_instance, alg);
  42. }
  43. static inline void *skcipher_instance_ctx(struct skcipher_instance *inst)
  44. {
  45. return crypto_instance_ctx(skcipher_crypto_instance(inst));
  46. }
  47. static inline void skcipher_request_complete(struct skcipher_request *req, int err)
  48. {
  49. req->base.complete(&req->base, err);
  50. }
  51. static inline void crypto_set_skcipher_spawn(
  52. struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
  53. {
  54. crypto_set_spawn(&spawn->base, inst);
  55. }
  56. int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
  57. u32 type, u32 mask);
  58. static inline int crypto_grab_skcipher2(struct crypto_skcipher_spawn *spawn,
  59. const char *name, u32 type, u32 mask)
  60. {
  61. return crypto_grab_skcipher(spawn, name, type, mask);
  62. }
  63. struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask);
  64. static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
  65. {
  66. crypto_drop_spawn(&spawn->base);
  67. }
  68. static inline struct skcipher_alg *crypto_skcipher_spawn_alg(
  69. struct crypto_skcipher_spawn *spawn)
  70. {
  71. return container_of(spawn->base.alg, struct skcipher_alg, base);
  72. }
  73. static inline struct skcipher_alg *crypto_spawn_skcipher_alg(
  74. struct crypto_skcipher_spawn *spawn)
  75. {
  76. return crypto_skcipher_spawn_alg(spawn);
  77. }
  78. static inline struct crypto_skcipher *crypto_spawn_skcipher(
  79. struct crypto_skcipher_spawn *spawn)
  80. {
  81. return crypto_spawn_tfm2(&spawn->base);
  82. }
  83. static inline struct crypto_skcipher *crypto_spawn_skcipher2(
  84. struct crypto_skcipher_spawn *spawn)
  85. {
  86. return crypto_spawn_skcipher(spawn);
  87. }
  88. static inline void crypto_skcipher_set_reqsize(
  89. struct crypto_skcipher *skcipher, unsigned int reqsize)
  90. {
  91. skcipher->reqsize = reqsize;
  92. }
  93. int crypto_register_skcipher(struct skcipher_alg *alg);
  94. void crypto_unregister_skcipher(struct skcipher_alg *alg);
  95. int crypto_register_skciphers(struct skcipher_alg *algs, int count);
  96. void crypto_unregister_skciphers(struct skcipher_alg *algs, int count);
  97. int skcipher_register_instance(struct crypto_template *tmpl,
  98. struct skcipher_instance *inst);
  99. static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
  100. int err)
  101. {
  102. req->base.complete(&req->base, err);
  103. }
  104. static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
  105. {
  106. return req->base.flags;
  107. }
  108. static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm)
  109. {
  110. return crypto_tfm_ctx(&tfm->base);
  111. }
  112. static inline void *skcipher_request_ctx(struct skcipher_request *req)
  113. {
  114. return req->__ctx;
  115. }
  116. static inline u32 skcipher_request_flags(struct skcipher_request *req)
  117. {
  118. return req->base.flags;
  119. }
  120. static inline unsigned int crypto_skcipher_alg_min_keysize(
  121. struct skcipher_alg *alg)
  122. {
  123. if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
  124. CRYPTO_ALG_TYPE_BLKCIPHER)
  125. return alg->base.cra_blkcipher.min_keysize;
  126. if (alg->base.cra_ablkcipher.encrypt)
  127. return alg->base.cra_ablkcipher.min_keysize;
  128. return alg->min_keysize;
  129. }
  130. static inline unsigned int crypto_skcipher_alg_max_keysize(
  131. struct skcipher_alg *alg)
  132. {
  133. if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
  134. CRYPTO_ALG_TYPE_BLKCIPHER)
  135. return alg->base.cra_blkcipher.max_keysize;
  136. if (alg->base.cra_ablkcipher.encrypt)
  137. return alg->base.cra_ablkcipher.max_keysize;
  138. return alg->max_keysize;
  139. }
  140. #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */