hash.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. extern const struct crypto_type crypto_ahash_type;
  32. int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err);
  33. int crypto_hash_walk_first(struct ahash_request *req,
  34. struct crypto_hash_walk *walk);
  35. int crypto_hash_walk_first_compat(struct hash_desc *hdesc,
  36. struct crypto_hash_walk *walk,
  37. struct scatterlist *sg, unsigned int len);
  38. int crypto_register_shash(struct shash_alg *alg);
  39. int crypto_unregister_shash(struct shash_alg *alg);
  40. void shash_free_instance(struct crypto_instance *inst);
  41. static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
  42. {
  43. return crypto_tfm_ctx(&tfm->base);
  44. }
  45. static inline struct ahash_alg *crypto_ahash_alg(
  46. struct crypto_ahash *tfm)
  47. {
  48. return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash;
  49. }
  50. static inline int ahash_enqueue_request(struct crypto_queue *queue,
  51. struct ahash_request *request)
  52. {
  53. return crypto_enqueue_request(queue, &request->base);
  54. }
  55. static inline struct ahash_request *ahash_dequeue_request(
  56. struct crypto_queue *queue)
  57. {
  58. return ahash_request_cast(crypto_dequeue_request(queue));
  59. }
  60. static inline int ahash_tfm_in_queue(struct crypto_queue *queue,
  61. struct crypto_ahash *tfm)
  62. {
  63. return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm));
  64. }
  65. static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
  66. {
  67. return crypto_tfm_ctx(&tfm->base);
  68. }
  69. static inline struct crypto_instance *shash_crypto_instance(
  70. struct shash_instance *inst)
  71. {
  72. return container_of(&inst->alg.base, struct crypto_instance, alg);
  73. }
  74. static inline struct shash_instance *shash_instance(
  75. struct crypto_instance *inst)
  76. {
  77. return container_of(__crypto_shash_alg(&inst->alg),
  78. struct shash_instance, alg);
  79. }
  80. static inline struct shash_instance *shash_alloc_instance(
  81. const char *name, struct crypto_alg *alg)
  82. {
  83. return crypto_alloc_instance2(name, alg,
  84. sizeof(struct shash_alg) - sizeof(*alg));
  85. }
  86. #endif /* _CRYPTO_INTERNAL_HASH_H */