blob: edd2089b4558b3223c41d11387494629fb7bbae0 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Qualcomm Crypto Engine driver API
2 *
3 * Copyright (c) 2010-2011, Code Aurora Forum. 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
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 Hossaind90ea0e2011-08-11 16:51:07 -070051#define QCE_MAX_OPER_DATA 0xFF00
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052
53/* Maximum Nonce bytes */
54#define MAX_NONCE 16
55
56typedef void (*qce_comp_func_ptr_t)(void *areq,
57 unsigned char *icv, unsigned char *iv, int ret);
58
59/* Cipher algorithms supported */
60enum 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 */
68enum 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,
74 QCE_HASH_LAST
75};
76
77/* Cipher encryption/decryption operations */
78enum qce_cipher_dir_enum {
79 QCE_ENCRYPT = 0,
80 QCE_DECRYPT = 1,
81 QCE_CIPHER_DIR_LAST
82};
83
84/* Cipher algorithms modes */
85enum qce_cipher_mode_enum {
86 QCE_MODE_CBC = 0,
87 QCE_MODE_ECB = 1,
88 QCE_MODE_CTR = 2,
89 QCE_MODE_XTS = 3,
90 QCE_MODE_CCM = 4,
91 QCE_CIPHER_MODE_LAST
92};
93
94/* Cipher operation type */
95enum qce_req_op_enum {
96 QCE_REQ_ABLK_CIPHER = 0,
97 QCE_REQ_ABLK_CIPHER_NO_KEY = 1,
98 QCE_REQ_AEAD = 2,
99 QCE_REQ_LAST
100};
101
102/* Algorithms/features supported in CE HW engine */
103struct ce_hw_support {
104 bool sha1_hmac_20; /* Supports 20 bytes of HMAC key*/
105 bool sha1_hmac; /* supports max HMAC key of 64 bytes*/
106 bool sha256_hmac; /* supports max HMAC key of 64 bytes*/
107 bool sha_hmac; /* supports SHA1 and SHA256 MAX HMAC key of 64 bytes*/
108 bool cmac;
109 bool aes_key_192;
110 bool aes_xts;
111 bool aes_ccm;
112 bool ota;
113};
114
115/* Sha operation parameters */
116struct qce_sha_req {
117 qce_comp_func_ptr_t qce_cb; /* call back */
118 enum qce_hash_alg_enum alg; /* sha algorithm */
119 unsigned char *digest; /* sha digest */
120 struct scatterlist *src; /* pointer to scatter list entry */
121 uint32_t auth_data[4]; /* byte count */
122 unsigned char *authkey; /* auth key */
123 unsigned int authklen; /* auth key length */
124 bool first_blk; /* first block indicator */
125 bool last_blk; /* last block indicator */
126 unsigned int size; /* data length in bytes */
127 void *areq;
128};
129
130struct qce_req {
131 enum qce_req_op_enum op; /* operation type */
132 qce_comp_func_ptr_t qce_cb; /* call back */
133 void *areq;
134 enum qce_cipher_alg_enum alg; /* cipher algorithms*/
135 enum qce_cipher_dir_enum dir; /* encryption? decryption? */
136 enum qce_cipher_mode_enum mode; /* algorithm mode */
137 unsigned char *authkey; /* authentication key */
138 unsigned int authklen; /* authentication key kength */
139 unsigned int authsize; /* authentication key kength */
140 unsigned char nonce[MAX_NONCE];/* nonce for ccm mode */
141 unsigned char *assoc; /* Ptr to formatted associated data */
142 unsigned int assoclen; /* Formatted associated data length */
143 struct scatterlist *asg; /* Formatted associated data sg */
144 unsigned char *enckey; /* cipher key */
145 unsigned int encklen; /* cipher key length */
146 unsigned char *iv; /* initialization vector */
147 unsigned int ivsize; /* initialization vector size*/
148 unsigned int cryptlen; /* data length */
149 unsigned int use_pmem; /* is source of data PMEM allocated? */
150 struct qcedev_pmem_info *pmem; /* pointer to pmem_info structure*/
151};
152
153void *qce_open(struct platform_device *pdev, int *rc);
154int qce_close(void *handle);
155int qce_aead_req(void *handle, struct qce_req *req);
156int qce_ablk_cipher_req(void *handle, struct qce_req *req);
157int qce_hw_support(void *handle, struct ce_hw_support *support);
158int qce_process_sha_req(void *handle, struct qce_sha_req *s_req);
159
160#endif /* __CRYPTO_MSM_QCE_H */