skcipher.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
  64. {
  65. crypto_drop_spawn(&spawn->base);
  66. }
  67. static inline struct skcipher_alg *crypto_skcipher_spawn_alg(
  68. struct crypto_skcipher_spawn *spawn)
  69. {
  70. return container_of(spawn->base.alg, struct skcipher_alg, base);
  71. }
  72. static inline struct skcipher_alg *crypto_spawn_skcipher_alg(
  73. struct crypto_skcipher_spawn *spawn)
  74. {
  75. return crypto_skcipher_spawn_alg(spawn);
  76. }
  77. static inline struct crypto_skcipher *crypto_spawn_skcipher(
  78. struct crypto_skcipher_spawn *spawn)
  79. {
  80. return crypto_spawn_tfm2(&spawn->base);
  81. }
  82. static inline struct crypto_skcipher *crypto_spawn_skcipher2(
  83. struct crypto_skcipher_spawn *spawn)
  84. {
  85. return crypto_spawn_skcipher(spawn);
  86. }
  87. static inline void crypto_skcipher_set_reqsize(
  88. struct crypto_skcipher *skcipher, unsigned int reqsize)
  89. {
  90. skcipher->reqsize = reqsize;
  91. }
  92. int crypto_register_skcipher(struct skcipher_alg *alg);
  93. void crypto_unregister_skcipher(struct skcipher_alg *alg);
  94. int crypto_register_skciphers(struct skcipher_alg *algs, int count);
  95. void crypto_unregister_skciphers(struct skcipher_alg *algs, int count);
  96. int skcipher_register_instance(struct crypto_template *tmpl,
  97. struct skcipher_instance *inst);
  98. static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
  99. int err)
  100. {
  101. req->base.complete(&req->base, err);
  102. }
  103. static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
  104. {
  105. return req->base.flags;
  106. }
  107. static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm)
  108. {
  109. return crypto_tfm_ctx(&tfm->base);
  110. }
  111. static inline void *skcipher_request_ctx(struct skcipher_request *req)
  112. {
  113. return req->__ctx;
  114. }
  115. static inline u32 skcipher_request_flags(struct skcipher_request *req)
  116. {
  117. return req->base.flags;
  118. }
  119. static inline unsigned int crypto_skcipher_alg_min_keysize(
  120. struct skcipher_alg *alg)
  121. {
  122. if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
  123. CRYPTO_ALG_TYPE_BLKCIPHER)
  124. return alg->base.cra_blkcipher.min_keysize;
  125. if (alg->base.cra_ablkcipher.encrypt)
  126. return alg->base.cra_ablkcipher.min_keysize;
  127. return alg->min_keysize;
  128. }
  129. static inline unsigned int crypto_skcipher_alg_max_keysize(
  130. struct skcipher_alg *alg)
  131. {
  132. if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
  133. CRYPTO_ALG_TYPE_BLKCIPHER)
  134. return alg->base.cra_blkcipher.max_keysize;
  135. if (alg->base.cra_ablkcipher.encrypt)
  136. return alg->base.cra_ablkcipher.max_keysize;
  137. return alg->max_keysize;
  138. }
  139. #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */