sha.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _SHA_H_
  14. #define _SHA_H_
  15. #include <crypto/scatterwalk.h>
  16. #include <crypto/sha.h>
  17. #include "common.h"
  18. #include "core.h"
  19. #define QCE_SHA_MAX_BLOCKSIZE SHA256_BLOCK_SIZE
  20. #define QCE_SHA_MAX_DIGESTSIZE SHA256_DIGEST_SIZE
  21. struct qce_sha_ctx {
  22. u8 authkey[QCE_SHA_MAX_BLOCKSIZE];
  23. };
  24. /**
  25. * struct qce_sha_reqctx - holds private ahash objects per request
  26. * @buf: used during update, import and export
  27. * @tmpbuf: buffer for internal use
  28. * @digest: calculated digest buffer
  29. * @buflen: length of the buffer
  30. * @flags: operation flags
  31. * @src_orig: original request sg list
  32. * @nbytes_orig: original request number of bytes
  33. * @src_chained: is source scatterlist chained
  34. * @src_nents: source number of entries
  35. * @byte_count: byte count
  36. * @count: save count in states during update, import and export
  37. * @first_blk: is it the first block
  38. * @last_blk: is it the last block
  39. * @sg: used to chain sg lists
  40. * @authkey: pointer to auth key in sha ctx
  41. * @authklen: auth key length
  42. * @result_sg: scatterlist used for result buffer
  43. */
  44. struct qce_sha_reqctx {
  45. u8 buf[QCE_SHA_MAX_BLOCKSIZE];
  46. u8 tmpbuf[QCE_SHA_MAX_BLOCKSIZE];
  47. u8 digest[QCE_SHA_MAX_DIGESTSIZE];
  48. unsigned int buflen;
  49. unsigned long flags;
  50. struct scatterlist *src_orig;
  51. unsigned int nbytes_orig;
  52. bool src_chained;
  53. int src_nents;
  54. __be32 byte_count[2];
  55. u64 count;
  56. bool first_blk;
  57. bool last_blk;
  58. struct scatterlist sg[2];
  59. u8 *authkey;
  60. unsigned int authklen;
  61. struct scatterlist result_sg;
  62. };
  63. static inline struct qce_alg_template *to_ahash_tmpl(struct crypto_tfm *tfm)
  64. {
  65. struct crypto_ahash *ahash = __crypto_ahash_cast(tfm);
  66. struct ahash_alg *alg = container_of(crypto_hash_alg_common(ahash),
  67. struct ahash_alg, halg);
  68. return container_of(alg, struct qce_alg_template, alg.ahash);
  69. }
  70. extern const struct qce_algo_ops ahash_ops;
  71. #endif /* _SHA_H_ */