hash.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_shash(struct shash_alg *alg);
  42. int crypto_unregister_shash(struct shash_alg *alg);
  43. int shash_register_instance(struct crypto_template *tmpl,
  44. struct shash_instance *inst);
  45. void shash_free_instance(struct crypto_instance *inst);
  46. int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn,
  47. struct shash_alg *alg,
  48. struct crypto_instance *inst);
  49. struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
  50. static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
  51. {
  52. return crypto_tfm_ctx(&tfm->base);
  53. }
  54. static inline struct ahash_alg *crypto_ahash_alg(
  55. struct crypto_ahash *tfm)
  56. {
  57. return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash;
  58. }
  59. static inline int ahash_enqueue_request(struct crypto_queue *queue,
  60. struct ahash_request *request)
  61. {
  62. return crypto_enqueue_request(queue, &request->base);
  63. }
  64. static inline struct ahash_request *ahash_dequeue_request(
  65. struct crypto_queue *queue)
  66. {
  67. return ahash_request_cast(crypto_dequeue_request(queue));
  68. }
  69. static inline int ahash_tfm_in_queue(struct crypto_queue *queue,
  70. struct crypto_ahash *tfm)
  71. {
  72. return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm));
  73. }
  74. static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
  75. {
  76. return crypto_tfm_ctx(&tfm->base);
  77. }
  78. static inline struct crypto_instance *shash_crypto_instance(
  79. struct shash_instance *inst)
  80. {
  81. return container_of(&inst->alg.base, struct crypto_instance, alg);
  82. }
  83. static inline struct shash_instance *shash_instance(
  84. struct crypto_instance *inst)
  85. {
  86. return container_of(__crypto_shash_alg(&inst->alg),
  87. struct shash_instance, alg);
  88. }
  89. static inline void *shash_instance_ctx(struct shash_instance *inst)
  90. {
  91. return crypto_instance_ctx(shash_crypto_instance(inst));
  92. }
  93. static inline struct shash_instance *shash_alloc_instance(
  94. const char *name, struct crypto_alg *alg)
  95. {
  96. return crypto_alloc_instance2(name, alg,
  97. sizeof(struct shash_alg) - sizeof(*alg));
  98. }
  99. static inline struct crypto_shash *crypto_spawn_shash(
  100. struct crypto_shash_spawn *spawn)
  101. {
  102. return crypto_spawn_tfm2(&spawn->base);
  103. }
  104. static inline void *crypto_shash_ctx_aligned(struct crypto_shash *tfm)
  105. {
  106. return crypto_tfm_ctx_aligned(&tfm->base);
  107. }
  108. static inline struct crypto_shash *__crypto_shash_cast(struct crypto_tfm *tfm)
  109. {
  110. return container_of(tfm, struct crypto_shash, base);
  111. }
  112. #endif /* _CRYPTO_INTERNAL_HASH_H */