Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Qualcomm Crypto Engine driver API |
| 2 | * |
Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 3 | * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | |
| 15 | |
| 16 | #ifndef __CRYPTO_MSM_QCE_H |
| 17 | #define __CRYPTO_MSM_QCE_H |
| 18 | |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/crypto.h> |
| 22 | |
| 23 | #include <crypto/algapi.h> |
| 24 | #include <crypto/aes.h> |
| 25 | #include <crypto/des.h> |
| 26 | #include <crypto/sha.h> |
| 27 | #include <crypto/aead.h> |
| 28 | #include <crypto/authenc.h> |
| 29 | #include <crypto/scatterwalk.h> |
| 30 | |
| 31 | /* SHA digest size in bytes */ |
| 32 | #define SHA256_DIGESTSIZE 32 |
| 33 | #define SHA1_DIGESTSIZE 20 |
| 34 | |
| 35 | /* key size in bytes */ |
| 36 | #define HMAC_KEY_SIZE (SHA1_DIGESTSIZE) /* hmac-sha1 */ |
| 37 | #define SHA_HMAC_KEY_SIZE 64 |
| 38 | #define DES_KEY_SIZE 8 |
| 39 | #define TRIPLE_DES_KEY_SIZE 24 |
| 40 | #define AES128_KEY_SIZE 16 |
| 41 | #define AES192_KEY_SIZE 24 |
| 42 | #define AES256_KEY_SIZE 32 |
| 43 | #define MAX_CIPHER_KEY_SIZE AES256_KEY_SIZE |
| 44 | |
| 45 | /* iv length in bytes */ |
| 46 | #define AES_IV_LENGTH 16 |
| 47 | #define DES_IV_LENGTH 8 |
| 48 | #define MAX_IV_LENGTH AES_IV_LENGTH |
| 49 | |
| 50 | /* Maximum number of bytes per transfer */ |
Mona Hossain | d90ea0e | 2011-08-11 16:51:07 -0700 | [diff] [blame] | 51 | #define QCE_MAX_OPER_DATA 0xFF00 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | |
| 53 | /* Maximum Nonce bytes */ |
| 54 | #define MAX_NONCE 16 |
| 55 | |
| 56 | typedef void (*qce_comp_func_ptr_t)(void *areq, |
| 57 | unsigned char *icv, unsigned char *iv, int ret); |
| 58 | |
| 59 | /* Cipher algorithms supported */ |
| 60 | enum qce_cipher_alg_enum { |
| 61 | CIPHER_ALG_DES = 0, |
| 62 | CIPHER_ALG_3DES = 1, |
| 63 | CIPHER_ALG_AES = 2, |
| 64 | CIPHER_ALG_LAST |
| 65 | }; |
| 66 | |
| 67 | /* Hash and hmac algorithms supported */ |
| 68 | enum qce_hash_alg_enum { |
| 69 | QCE_HASH_SHA1 = 0, |
| 70 | QCE_HASH_SHA256 = 1, |
| 71 | QCE_HASH_SHA1_HMAC = 2, |
| 72 | QCE_HASH_SHA256_HMAC = 3, |
| 73 | QCE_HASH_AES_CMAC = 4, |
Mona Hossain | b43e94b | 2012-05-07 08:52:06 -0700 | [diff] [blame] | 74 | QCE_AEAD_SHA1_HMAC = 5, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | QCE_HASH_LAST |
| 76 | }; |
| 77 | |
| 78 | /* Cipher encryption/decryption operations */ |
| 79 | enum qce_cipher_dir_enum { |
| 80 | QCE_ENCRYPT = 0, |
| 81 | QCE_DECRYPT = 1, |
| 82 | QCE_CIPHER_DIR_LAST |
| 83 | }; |
| 84 | |
| 85 | /* Cipher algorithms modes */ |
| 86 | enum qce_cipher_mode_enum { |
| 87 | QCE_MODE_CBC = 0, |
| 88 | QCE_MODE_ECB = 1, |
| 89 | QCE_MODE_CTR = 2, |
| 90 | QCE_MODE_XTS = 3, |
| 91 | QCE_MODE_CCM = 4, |
| 92 | QCE_CIPHER_MODE_LAST |
| 93 | }; |
| 94 | |
| 95 | /* Cipher operation type */ |
| 96 | enum qce_req_op_enum { |
| 97 | QCE_REQ_ABLK_CIPHER = 0, |
| 98 | QCE_REQ_ABLK_CIPHER_NO_KEY = 1, |
| 99 | QCE_REQ_AEAD = 2, |
| 100 | QCE_REQ_LAST |
| 101 | }; |
| 102 | |
| 103 | /* Algorithms/features supported in CE HW engine */ |
| 104 | struct ce_hw_support { |
| 105 | bool sha1_hmac_20; /* Supports 20 bytes of HMAC key*/ |
| 106 | bool sha1_hmac; /* supports max HMAC key of 64 bytes*/ |
| 107 | bool sha256_hmac; /* supports max HMAC key of 64 bytes*/ |
| 108 | bool sha_hmac; /* supports SHA1 and SHA256 MAX HMAC key of 64 bytes*/ |
| 109 | bool cmac; |
| 110 | bool aes_key_192; |
| 111 | bool aes_xts; |
| 112 | bool aes_ccm; |
| 113 | bool ota; |
Mona Hossain | b43e94b | 2012-05-07 08:52:06 -0700 | [diff] [blame] | 114 | bool aligned_only; |
| 115 | bool bam; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | /* Sha operation parameters */ |
| 119 | struct qce_sha_req { |
| 120 | qce_comp_func_ptr_t qce_cb; /* call back */ |
| 121 | enum qce_hash_alg_enum alg; /* sha algorithm */ |
| 122 | unsigned char *digest; /* sha digest */ |
| 123 | struct scatterlist *src; /* pointer to scatter list entry */ |
| 124 | uint32_t auth_data[4]; /* byte count */ |
| 125 | unsigned char *authkey; /* auth key */ |
| 126 | unsigned int authklen; /* auth key length */ |
| 127 | bool first_blk; /* first block indicator */ |
| 128 | bool last_blk; /* last block indicator */ |
| 129 | unsigned int size; /* data length in bytes */ |
| 130 | void *areq; |
| 131 | }; |
| 132 | |
| 133 | struct qce_req { |
| 134 | enum qce_req_op_enum op; /* operation type */ |
| 135 | qce_comp_func_ptr_t qce_cb; /* call back */ |
| 136 | void *areq; |
| 137 | enum qce_cipher_alg_enum alg; /* cipher algorithms*/ |
| 138 | enum qce_cipher_dir_enum dir; /* encryption? decryption? */ |
| 139 | enum qce_cipher_mode_enum mode; /* algorithm mode */ |
| 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 | }; |
| 155 | |
| 156 | void *qce_open(struct platform_device *pdev, int *rc); |
| 157 | int qce_close(void *handle); |
| 158 | int qce_aead_req(void *handle, struct qce_req *req); |
| 159 | int qce_ablk_cipher_req(void *handle, struct qce_req *req); |
| 160 | int qce_hw_support(void *handle, struct ce_hw_support *support); |
| 161 | int qce_process_sha_req(void *handle, struct qce_sha_req *s_req); |
| 162 | |
| 163 | #endif /* __CRYPTO_MSM_QCE_H */ |