sha.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _SHA_H_
  6. #define _SHA_H_
  7. #include <crypto/scatterwalk.h>
  8. #include <crypto/sha1.h>
  9. #include <crypto/sha2.h>
  10. #include "common.h"
  11. #include "core.h"
  12. #define QCE_SHA_MAX_BLOCKSIZE SHA256_BLOCK_SIZE
  13. #define QCE_SHA_MAX_DIGESTSIZE SHA256_DIGEST_SIZE
  14. struct qce_sha_ctx {
  15. u8 authkey[QCE_SHA_MAX_BLOCKSIZE];
  16. };
  17. /**
  18. * struct qce_sha_reqctx - holds private ahash objects per request
  19. * @buf: used during update, import and export
  20. * @tmpbuf: buffer for internal use
  21. * @digest: calculated digest buffer
  22. * @buflen: length of the buffer
  23. * @flags: operation flags
  24. * @src_orig: original request sg list
  25. * @nbytes_orig: original request number of bytes
  26. * @src_nents: source number of entries
  27. * @byte_count: byte count
  28. * @count: save count in states during update, import and export
  29. * @first_blk: is it the first block
  30. * @last_blk: is it the last block
  31. * @sg: used to chain sg lists
  32. * @authkey: pointer to auth key in sha ctx
  33. * @authklen: auth key length
  34. * @result_sg: scatterlist used for result buffer
  35. */
  36. struct qce_sha_reqctx {
  37. u8 buf[QCE_SHA_MAX_BLOCKSIZE];
  38. u8 tmpbuf[QCE_SHA_MAX_BLOCKSIZE];
  39. u8 digest[QCE_SHA_MAX_DIGESTSIZE];
  40. unsigned int buflen;
  41. unsigned long flags;
  42. struct scatterlist *src_orig;
  43. unsigned int nbytes_orig;
  44. int src_nents;
  45. __be32 byte_count[2];
  46. u64 count;
  47. bool first_blk;
  48. bool last_blk;
  49. struct scatterlist sg[2];
  50. u8 *authkey;
  51. unsigned int authklen;
  52. struct scatterlist result_sg;
  53. };
  54. static inline struct qce_alg_template *to_ahash_tmpl(struct crypto_tfm *tfm)
  55. {
  56. struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
  57. struct ahash_alg *alg = container_of(crypto_hash_alg_common(ahash),
  58. struct ahash_alg, halg);
  59. return container_of(alg, struct qce_alg_template, alg.ahash);
  60. }
  61. extern const struct qce_algo_ops ahash_ops;
  62. #endif /* _SHA_H_ */