cc_hash.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
  3. /* \file cc_hash.h
  4. * ARM CryptoCell Hash Crypto API
  5. */
  6. #ifndef __CC_HASH_H__
  7. #define __CC_HASH_H__
  8. #include "cc_buffer_mgr.h"
  9. #define HMAC_IPAD_CONST 0x36363636
  10. #define HMAC_OPAD_CONST 0x5C5C5C5C
  11. #define HASH_LEN_SIZE_712 16
  12. #define HASH_LEN_SIZE_630 8
  13. #define HASH_MAX_LEN_SIZE HASH_LEN_SIZE_712
  14. #define CC_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
  15. #define CC_MAX_HASH_BLCK_SIZE SHA512_BLOCK_SIZE
  16. #define XCBC_MAC_K1_OFFSET 0
  17. #define XCBC_MAC_K2_OFFSET 16
  18. #define XCBC_MAC_K3_OFFSET 32
  19. #define CC_EXPORT_MAGIC 0xC2EE1070U
  20. /* this struct was taken from drivers/crypto/nx/nx-aes-xcbc.c and it is used
  21. * for xcbc/cmac statesize
  22. */
  23. struct aeshash_state {
  24. u8 state[AES_BLOCK_SIZE];
  25. unsigned int count;
  26. u8 buffer[AES_BLOCK_SIZE];
  27. };
  28. /* ahash state */
  29. struct ahash_req_ctx {
  30. u8 buffers[2][CC_MAX_HASH_BLCK_SIZE] ____cacheline_aligned;
  31. u8 digest_result_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
  32. u8 digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
  33. u8 opad_digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
  34. u8 digest_bytes_len[HASH_MAX_LEN_SIZE] ____cacheline_aligned;
  35. struct async_gen_req_ctx gen_ctx ____cacheline_aligned;
  36. enum cc_req_dma_buf_type data_dma_buf_type;
  37. dma_addr_t opad_digest_dma_addr;
  38. dma_addr_t digest_buff_dma_addr;
  39. dma_addr_t digest_bytes_len_dma_addr;
  40. dma_addr_t digest_result_dma_addr;
  41. u32 buf_cnt[2];
  42. u32 buff_index;
  43. u32 xcbc_count; /* count xcbc update operatations */
  44. struct scatterlist buff_sg[2];
  45. struct scatterlist *curr_sg;
  46. u32 in_nents;
  47. u32 mlli_nents;
  48. struct mlli_params mlli_params;
  49. };
  50. static inline u32 *cc_hash_buf_cnt(struct ahash_req_ctx *state)
  51. {
  52. return &state->buf_cnt[state->buff_index];
  53. }
  54. static inline u8 *cc_hash_buf(struct ahash_req_ctx *state)
  55. {
  56. return state->buffers[state->buff_index];
  57. }
  58. static inline u32 *cc_next_buf_cnt(struct ahash_req_ctx *state)
  59. {
  60. return &state->buf_cnt[state->buff_index ^ 1];
  61. }
  62. static inline u8 *cc_next_buf(struct ahash_req_ctx *state)
  63. {
  64. return state->buffers[state->buff_index ^ 1];
  65. }
  66. int cc_hash_alloc(struct cc_drvdata *drvdata);
  67. int cc_init_hash_sram(struct cc_drvdata *drvdata);
  68. int cc_hash_free(struct cc_drvdata *drvdata);
  69. /*!
  70. * Gets the initial digest length
  71. *
  72. * \param drvdata
  73. * \param mode The Hash mode. Supported modes:
  74. * MD5/SHA1/SHA224/SHA256/SHA384/SHA512
  75. *
  76. * \return u32 returns the address of the initial digest length in SRAM
  77. */
  78. cc_sram_addr_t
  79. cc_digest_len_addr(void *drvdata, u32 mode);
  80. /*!
  81. * Gets the address of the initial digest in SRAM
  82. * according to the given hash mode
  83. *
  84. * \param drvdata
  85. * \param mode The Hash mode. Supported modes:
  86. * MD5/SHA1/SHA224/SHA256/SHA384/SHA512
  87. *
  88. * \return u32 The address of the initial digest in SRAM
  89. */
  90. cc_sram_addr_t cc_larval_digest_addr(void *drvdata, u32 mode);
  91. void cc_hash_global_init(void);
  92. #endif /*__CC_HASH_H__*/