qce.h 5.7 KB

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