hash.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Hash algorithms.
  3. *
  4. * Copyright (c) 2008 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_HASH_H
  13. #define _CRYPTO_INTERNAL_HASH_H
  14. #include <crypto/algapi.h>
  15. #include <crypto/hash.h>
  16. struct ahash_request;
  17. struct scatterlist;
  18. struct crypto_hash_walk {
  19. char *data;
  20. unsigned int offset;
  21. unsigned int alignmask;
  22. struct page *pg;
  23. unsigned int entrylen;
  24. unsigned int total;
  25. struct scatterlist *sg;
  26. unsigned int flags;
  27. };
  28. struct shash_instance {
  29. struct shash_alg alg;
  30. };
  31. struct crypto_shash_spawn {
  32. struct crypto_spawn base;
  33. };
  34. extern const struct crypto_type crypto_ahash_type;
  35. int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err);
  36. int crypto_hash_walk_first(struct ahash_request *req,
  37. struct crypto_hash_walk *walk);
  38. int crypto_hash_walk_first_compat(struct hash_desc *hdesc,
  39. struct crypto_hash_walk *walk,
  40. struct scatterlist *sg, unsigned int len);
  41. int crypto_register_ahash(struct ahash_alg *alg);
  42. int crypto_unregister_ahash(struct ahash_alg *alg);
  43. int crypto_register_shash(struct shash_alg *alg);
  44. int crypto_unregister_shash(struct shash_alg *alg);
  45. int shash_register_instance(struct crypto_template *tmpl,
  46. struct shash_instance *inst);
  47. void shash_free_instance(struct crypto_instance *inst);
  48. int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn,
  49. struct shash_alg *alg,
  50. struct crypto_instance *inst);
  51. struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
  52. int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc);
  53. int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc);
  54. int crypto_init_shash_ops_async(struct crypto_tfm *tfm);
  55. static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
  56. {
  57. return crypto_tfm_ctx(crypto_ahash_tfm(tfm));
  58. }
  59. static inline struct old_ahash_alg *crypto_old_ahash_alg(
  60. struct crypto_ahash *tfm)
  61. {
  62. return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash;
  63. }
  64. static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm,
  65. unsigned int reqsize)
  66. {
  67. tfm->reqsize = reqsize;
  68. }
  69. static inline int ahash_enqueue_request(struct crypto_queue *queue,
  70. struct ahash_request *request)
  71. {
  72. return crypto_enqueue_request(queue, &request->base);
  73. }
  74. static inline struct ahash_request *ahash_dequeue_request(
  75. struct crypto_queue *queue)
  76. {
  77. return ahash_request_cast(crypto_dequeue_request(queue));
  78. }
  79. static inline int ahash_tfm_in_queue(struct crypto_queue *queue,
  80. struct crypto_ahash *tfm)
  81. {
  82. return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm));
  83. }
  84. static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
  85. {
  86. return crypto_tfm_ctx(&tfm->base);
  87. }
  88. static inline struct crypto_instance *shash_crypto_instance(
  89. struct shash_instance *inst)
  90. {
  91. return container_of(&inst->alg.base, struct crypto_instance, alg);
  92. }
  93. static inline struct shash_instance *shash_instance(
  94. struct crypto_instance *inst)
  95. {
  96. return container_of(__crypto_shash_alg(&inst->alg),
  97. struct shash_instance, alg);
  98. }
  99. static inline void *shash_instance_ctx(struct shash_instance *inst)
  100. {
  101. return crypto_instance_ctx(shash_crypto_instance(inst));
  102. }
  103. static inline struct shash_instance *shash_alloc_instance(
  104. const char *name, struct crypto_alg *alg)
  105. {
  106. return crypto_alloc_instance2(name, alg,
  107. sizeof(struct shash_alg) - sizeof(*alg));
  108. }
  109. static inline struct crypto_shash *crypto_spawn_shash(
  110. struct crypto_shash_spawn *spawn)
  111. {
  112. return crypto_spawn_tfm2(&spawn->base);
  113. }
  114. static inline void *crypto_shash_ctx_aligned(struct crypto_shash *tfm)
  115. {
  116. return crypto_tfm_ctx_aligned(&tfm->base);
  117. }
  118. static inline struct crypto_shash *__crypto_shash_cast(struct crypto_tfm *tfm)
  119. {
  120. return container_of(tfm, struct crypto_shash, base);
  121. }
  122. #endif /* _CRYPTO_INTERNAL_HASH_H */