qce.h 5.3 KB

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