qce.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * QTI Crypto Engine driver API
  4. *
  5. * Copyright (c) 2010-2021, The Linux Foundation. All rights reserved.
  6. */
  7. #ifndef __CRYPTO_MSM_QCE_H
  8. #define __CRYPTO_MSM_QCE_H
  9. #include <linux/types.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/crypto.h>
  12. #include <crypto/skcipher.h>
  13. #include <crypto/algapi.h>
  14. #include <crypto/aes.h>
  15. #include <crypto/des.h>
  16. #include <crypto/sha1.h>
  17. #include <crypto/sha2.h>
  18. #include <crypto/aead.h>
  19. #include <crypto/authenc.h>
  20. #include <crypto/scatterwalk.h>
  21. /* SHA digest size in bytes */
  22. #define SHA256_DIGESTSIZE 32
  23. #define SHA1_DIGESTSIZE 20
  24. #define AES_CE_BLOCK_SIZE 16
  25. /* key size in bytes */
  26. #define HMAC_KEY_SIZE (SHA1_DIGESTSIZE) /* hmac-sha1 */
  27. #define SHA_HMAC_KEY_SIZE 64
  28. #define DES_KEY_SIZE 8
  29. #define TRIPLE_DES_KEY_SIZE 24
  30. #define AES128_KEY_SIZE 16
  31. #define AES192_KEY_SIZE 24
  32. #define AES256_KEY_SIZE 32
  33. #define MAX_CIPHER_KEY_SIZE AES256_KEY_SIZE
  34. /* iv length in bytes */
  35. #define AES_IV_LENGTH 16
  36. #define DES_IV_LENGTH 8
  37. #define MAX_IV_LENGTH AES_IV_LENGTH
  38. /* Maximum number of bytes per transfer */
  39. #define QCE_MAX_OPER_DATA 0xFF00
  40. /* Maximum Nonce bytes */
  41. #define MAX_NONCE 16
  42. /* Crypto clock control flags */
  43. #define QCE_CLK_ENABLE_FIRST 1
  44. #define QCE_BW_REQUEST_FIRST 2
  45. #define QCE_CLK_DISABLE_FIRST 3
  46. #define QCE_BW_REQUEST_RESET_FIRST 4
  47. /* interconnect average and peak bw for crypto device */
  48. #define CRYPTO_AVG_BW 393600
  49. #define CRYPTO_PEAK_BW 393600
  50. typedef void (*qce_comp_func_ptr_t)(void *areq,
  51. unsigned char *icv, unsigned char *iv, int ret);
  52. /* Cipher algorithms supported */
  53. enum qce_cipher_alg_enum {
  54. CIPHER_ALG_DES = 0,
  55. CIPHER_ALG_3DES = 1,
  56. CIPHER_ALG_AES = 2,
  57. CIPHER_ALG_LAST
  58. };
  59. /* Hash and hmac algorithms supported */
  60. enum qce_hash_alg_enum {
  61. QCE_HASH_SHA1 = 0,
  62. QCE_HASH_SHA256 = 1,
  63. QCE_HASH_SHA1_HMAC = 2,
  64. QCE_HASH_SHA256_HMAC = 3,
  65. QCE_HASH_AES_CMAC = 4,
  66. QCE_HASH_LAST
  67. };
  68. /* Cipher encryption/decryption operations */
  69. enum qce_cipher_dir_enum {
  70. QCE_ENCRYPT = 0,
  71. QCE_DECRYPT = 1,
  72. QCE_CIPHER_DIR_LAST
  73. };
  74. /* Cipher algorithms modes */
  75. enum qce_cipher_mode_enum {
  76. QCE_MODE_CBC = 0,
  77. QCE_MODE_ECB = 1,
  78. QCE_MODE_CTR = 2,
  79. QCE_MODE_XTS = 3,
  80. QCE_MODE_CCM = 4,
  81. QCE_CIPHER_MODE_LAST
  82. };
  83. /* Cipher operation type */
  84. enum qce_req_op_enum {
  85. QCE_REQ_ABLK_CIPHER = 0,
  86. QCE_REQ_ABLK_CIPHER_NO_KEY = 1,
  87. QCE_REQ_AEAD = 2,
  88. QCE_REQ_LAST
  89. };
  90. /* Algorithms/features supported in CE HW engine */
  91. struct ce_hw_support {
  92. bool sha1_hmac_20; /* Supports 20 bytes of HMAC key*/
  93. bool sha1_hmac; /* supports max HMAC key of 64 bytes*/
  94. bool sha256_hmac; /* supports max HMAC key of 64 bytes*/
  95. bool sha_hmac; /* supports SHA1 and SHA256 MAX HMAC key of 64 bytes*/
  96. bool cmac;
  97. bool aes_key_192;
  98. bool aes_xts;
  99. bool aes_ccm;
  100. bool ota;
  101. bool aligned_only;
  102. bool bam;
  103. bool is_shared;
  104. bool hw_key;
  105. bool use_sw_aes_cbc_ecb_ctr_algo;
  106. bool use_sw_aead_algo;
  107. bool use_sw_aes_xts_algo;
  108. bool use_sw_ahash_algo;
  109. bool use_sw_hmac_algo;
  110. bool use_sw_aes_ccm_algo;
  111. bool clk_mgmt_sus_res;
  112. bool req_bw_before_clk;
  113. unsigned int ce_device;
  114. unsigned int ce_hw_instance;
  115. unsigned int max_request;
  116. };
  117. /* Sha operation parameters */
  118. struct qce_sha_req {
  119. qce_comp_func_ptr_t qce_cb; /* call back */
  120. enum qce_hash_alg_enum alg; /* sha algorithm */
  121. unsigned char *digest; /* sha digest */
  122. struct scatterlist *src; /* pointer to scatter list entry */
  123. uint32_t auth_data[4]; /* byte count */
  124. unsigned char *authkey; /* auth key */
  125. unsigned int authklen; /* auth key length */
  126. bool first_blk; /* first block indicator */
  127. bool last_blk; /* last block indicator */
  128. unsigned int size; /* data length in bytes */
  129. void *areq;
  130. unsigned int flags;
  131. };
  132. struct qce_req {
  133. enum qce_req_op_enum op; /* operation type */
  134. qce_comp_func_ptr_t qce_cb; /* call back */
  135. void *areq;
  136. enum qce_cipher_alg_enum alg; /* cipher algorithms*/
  137. enum qce_cipher_dir_enum dir; /* encryption? decryption? */
  138. enum qce_cipher_mode_enum mode; /* algorithm mode */
  139. enum qce_hash_alg_enum auth_alg;/* authentication algorithm for aead */
  140. unsigned char *authkey; /* authentication key */
  141. unsigned int authklen; /* authentication key kength */
  142. unsigned int authsize; /* authentication key kength */
  143. unsigned char nonce[MAX_NONCE];/* nonce for ccm mode */
  144. unsigned char *assoc; /* Ptr to formatted associated data */
  145. unsigned int assoclen; /* Formatted associated data length */
  146. struct scatterlist *asg; /* Formatted associated data sg */
  147. unsigned char *enckey; /* cipher key */
  148. unsigned int encklen; /* cipher key length */
  149. unsigned char *iv; /* initialization vector */
  150. unsigned int ivsize; /* initialization vector size*/
  151. unsigned int cryptlen; /* data length */
  152. unsigned int use_pmem; /* is source of data PMEM allocated? */
  153. struct qcedev_pmem_info *pmem; /* pointer to pmem_info structure*/
  154. unsigned int flags;
  155. };
  156. struct qce_pm_table {
  157. int (*suspend)(void *handle);
  158. int (*resume)(void *handle);
  159. };
  160. extern struct qce_pm_table qce_pm_table;
  161. void *qce_open(struct platform_device *pdev, int *rc);
  162. int qce_close(void *handle);
  163. int qce_aead_req(void *handle, struct qce_req *req);
  164. int qce_ablk_cipher_req(void *handle, struct qce_req *req);
  165. int qce_hw_support(void *handle, struct ce_hw_support *support);
  166. int qce_process_sha_req(void *handle, struct qce_sha_req *s_req);
  167. int qce_enable_clk(void *handle);
  168. int qce_disable_clk(void *handle);
  169. void qce_get_driver_stats(void *handle);
  170. void qce_clear_driver_stats(void *handle);
  171. void qce_dump_req(void *handle);
  172. #endif /* __CRYPTO_MSM_QCE_H */