cc_aead.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
  3. /* \file cc_aead.h
  4. * ARM CryptoCell AEAD Crypto API
  5. */
  6. #ifndef __CC_AEAD_H__
  7. #define __CC_AEAD_H__
  8. #include <linux/kernel.h>
  9. #include <crypto/algapi.h>
  10. #include <crypto/ctr.h>
  11. /* mac_cmp - HW writes 8 B but all bytes hold the same value */
  12. #define ICV_CMP_SIZE 8
  13. #define CCM_CONFIG_BUF_SIZE (AES_BLOCK_SIZE * 3)
  14. #define MAX_MAC_SIZE SHA256_DIGEST_SIZE
  15. /* defines for AES GCM configuration buffer */
  16. #define GCM_BLOCK_LEN_SIZE 8
  17. #define GCM_BLOCK_RFC4_IV_OFFSET 4
  18. #define GCM_BLOCK_RFC4_IV_SIZE 8 /* IV size for rfc's */
  19. #define GCM_BLOCK_RFC4_NONCE_OFFSET 0
  20. #define GCM_BLOCK_RFC4_NONCE_SIZE 4
  21. /* Offsets into AES CCM configuration buffer */
  22. #define CCM_B0_OFFSET 0
  23. #define CCM_A0_OFFSET 16
  24. #define CCM_CTR_COUNT_0_OFFSET 32
  25. /* CCM B0 and CTR_COUNT constants. */
  26. #define CCM_BLOCK_NONCE_OFFSET 1 /* Nonce offset inside B0 and CTR_COUNT */
  27. #define CCM_BLOCK_NONCE_SIZE 3 /* Nonce size inside B0 and CTR_COUNT */
  28. #define CCM_BLOCK_IV_OFFSET 4 /* IV offset inside B0 and CTR_COUNT */
  29. #define CCM_BLOCK_IV_SIZE 8 /* IV size inside B0 and CTR_COUNT */
  30. enum aead_ccm_header_size {
  31. ccm_header_size_null = -1,
  32. ccm_header_size_zero = 0,
  33. ccm_header_size_2 = 2,
  34. ccm_header_size_6 = 6,
  35. ccm_header_size_max = S32_MAX
  36. };
  37. struct aead_req_ctx {
  38. /* Allocate cache line although only 4 bytes are needed to
  39. * assure next field falls @ cache line
  40. * Used for both: digest HW compare and CCM/GCM MAC value
  41. */
  42. u8 mac_buf[MAX_MAC_SIZE] ____cacheline_aligned;
  43. u8 ctr_iv[AES_BLOCK_SIZE] ____cacheline_aligned;
  44. //used in gcm
  45. u8 gcm_iv_inc1[AES_BLOCK_SIZE] ____cacheline_aligned;
  46. u8 gcm_iv_inc2[AES_BLOCK_SIZE] ____cacheline_aligned;
  47. u8 hkey[AES_BLOCK_SIZE] ____cacheline_aligned;
  48. struct {
  49. u8 len_a[GCM_BLOCK_LEN_SIZE] ____cacheline_aligned;
  50. u8 len_c[GCM_BLOCK_LEN_SIZE];
  51. } gcm_len_block;
  52. u8 ccm_config[CCM_CONFIG_BUF_SIZE] ____cacheline_aligned;
  53. /* HW actual size input */
  54. unsigned int hw_iv_size ____cacheline_aligned;
  55. /* used to prevent cache coherence problem */
  56. u8 backup_mac[MAX_MAC_SIZE];
  57. u8 *backup_iv; /* store orig iv */
  58. u32 assoclen; /* internal assoclen */
  59. dma_addr_t mac_buf_dma_addr; /* internal ICV DMA buffer */
  60. /* buffer for internal ccm configurations */
  61. dma_addr_t ccm_iv0_dma_addr;
  62. dma_addr_t icv_dma_addr; /* Phys. address of ICV */
  63. //used in gcm
  64. /* buffer for internal gcm configurations */
  65. dma_addr_t gcm_iv_inc1_dma_addr;
  66. /* buffer for internal gcm configurations */
  67. dma_addr_t gcm_iv_inc2_dma_addr;
  68. dma_addr_t hkey_dma_addr; /* Phys. address of hkey */
  69. dma_addr_t gcm_block_len_dma_addr; /* Phys. address of gcm block len */
  70. bool is_gcm4543;
  71. u8 *icv_virt_addr; /* Virt. address of ICV */
  72. struct async_gen_req_ctx gen_ctx;
  73. struct cc_mlli assoc;
  74. struct cc_mlli src;
  75. struct cc_mlli dst;
  76. struct scatterlist *src_sgl;
  77. struct scatterlist *dst_sgl;
  78. unsigned int src_offset;
  79. unsigned int dst_offset;
  80. enum cc_req_dma_buf_type assoc_buff_type;
  81. enum cc_req_dma_buf_type data_buff_type;
  82. struct mlli_params mlli_params;
  83. unsigned int cryptlen;
  84. struct scatterlist ccm_adata_sg;
  85. enum aead_ccm_header_size ccm_hdr_size;
  86. unsigned int req_authsize;
  87. enum drv_cipher_mode cipher_mode;
  88. bool is_icv_fragmented;
  89. bool is_single_pass;
  90. bool plaintext_authenticate_only; //for gcm_rfc4543
  91. };
  92. int cc_aead_alloc(struct cc_drvdata *drvdata);
  93. int cc_aead_free(struct cc_drvdata *drvdata);
  94. #endif /*__CC_AEAD_H__*/