hash.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc);
  51. int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc);
  52. static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
  53. {
  54. return crypto_tfm_ctx(&tfm->base);
  55. }
  56. static inline struct ahash_alg *crypto_ahash_alg(
  57. struct crypto_ahash *tfm)
  58. {
  59. return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash;
  60. }
  61. static inline void crypto_ahash_set_reqsize(struct crypto_ahash *tfm,
  62. unsigned int reqsize)
  63. {
  64. crypto_ahash_crt(tfm)->reqsize = reqsize;
  65. }
  66. static inline int ahash_enqueue_request(struct crypto_queue *queue,
  67. struct ahash_request *request)
  68. {
  69. return crypto_enqueue_request(queue, &request->base);
  70. }
  71. static inline struct ahash_request *ahash_dequeue_request(
  72. struct crypto_queue *queue)
  73. {
  74. return ahash_request_cast(crypto_dequeue_request(queue));
  75. }
  76. static inline int ahash_tfm_in_queue(struct crypto_queue *queue,
  77. struct crypto_ahash *tfm)
  78. {
  79. return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm));
  80. }
  81. static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
  82. {
  83. return crypto_tfm_ctx(&tfm->base);
  84. }
  85. static inline struct crypto_instance *shash_crypto_instance(
  86. struct shash_instance *inst)
  87. {
  88. return container_of(&inst->alg.base, struct crypto_instance, alg);
  89. }
  90. static inline struct shash_instance *shash_instance(
  91. struct crypto_instance *inst)
  92. {
  93. return container_of(__crypto_shash_alg(&inst->alg),
  94. struct shash_instance, alg);
  95. }
  96. static inline void *shash_instance_ctx(struct shash_instance *inst)
  97. {
  98. return crypto_instance_ctx(shash_crypto_instance(inst));
  99. }
  100. static inline struct shash_instance *shash_alloc_instance(
  101. const char *name, struct crypto_alg *alg)
  102. {
  103. return crypto_alloc_instance2(name, alg,
  104. sizeof(struct shash_alg) - sizeof(*alg));
  105. }
  106. static inline struct crypto_shash *crypto_spawn_shash(
  107. struct crypto_shash_spawn *spawn)
  108. {
  109. return crypto_spawn_tfm2(&spawn->base);
  110. }
  111. static inline void *crypto_shash_ctx_aligned(struct crypto_shash *tfm)
  112. {
  113. return crypto_tfm_ctx_aligned(&tfm->base);
  114. }
  115. static inline struct crypto_shash *__crypto_shash_cast(struct crypto_tfm *tfm)
  116. {
  117. return container_of(tfm, struct crypto_shash, base);
  118. }
  119. #endif /* _CRYPTO_INTERNAL_HASH_H */