Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
63b94509 TL |
2 | /* |
3 | * AMD Cryptographic Coprocessor (CCP) driver | |
4 | * | |
e652399e | 5 | * Copyright (C) 2013,2017 Advanced Micro Devices, Inc. |
63b94509 TL |
6 | * |
7 | * Author: Tom Lendacky <thomas.lendacky@amd.com> | |
58ea8abf | 8 | * Author: Gary R Hook <gary.hook@amd.com> |
63b94509 TL |
9 | */ |
10 | ||
c8d283ff PB |
11 | #ifndef __CCP_H__ |
12 | #define __CCP_H__ | |
63b94509 TL |
13 | |
14 | #include <linux/scatterlist.h> | |
15 | #include <linux/workqueue.h> | |
16 | #include <linux/list.h> | |
17 | #include <crypto/aes.h> | |
18 | #include <crypto/sha.h> | |
19 | ||
63b94509 TL |
20 | struct ccp_device; |
21 | struct ccp_cmd; | |
22 | ||
720419f0 | 23 | #if defined(CONFIG_CRYPTO_DEV_SP_CCP) |
db34cf91 | 24 | |
c9f21cb6 TL |
25 | /** |
26 | * ccp_present - check if a CCP device is present | |
27 | * | |
28 | * Returns zero if a CCP device is present, -ENODEV otherwise. | |
29 | */ | |
30 | int ccp_present(void); | |
31 | ||
c7019c4d GH |
32 | #define CCP_VSIZE 16 |
33 | #define CCP_VMASK ((unsigned int)((1 << CCP_VSIZE) - 1)) | |
34 | #define CCP_VERSION(v, r) ((unsigned int)((v << CCP_VSIZE) \ | |
35 | | (r & CCP_VMASK))) | |
36 | ||
37 | /** | |
38 | * ccp_version - get the version of the CCP | |
39 | * | |
40 | * Returns a positive version number, or zero if no CCP | |
41 | */ | |
42 | unsigned int ccp_version(void); | |
43 | ||
63b94509 TL |
44 | /** |
45 | * ccp_enqueue_cmd - queue an operation for processing by the CCP | |
46 | * | |
47 | * @cmd: ccp_cmd struct to be processed | |
48 | * | |
49 | * Refer to the ccp_cmd struct below for required fields. | |
50 | * | |
51 | * Queue a cmd to be processed by the CCP. If queueing the cmd | |
52 | * would exceed the defined length of the cmd queue the cmd will | |
53 | * only be queued if the CCP_CMD_MAY_BACKLOG flag is set and will | |
54 | * result in a return code of -EBUSY. | |
55 | * | |
56 | * The callback routine specified in the ccp_cmd struct will be | |
57 | * called to notify the caller of completion (if the cmd was not | |
58 | * backlogged) or advancement out of the backlog. If the cmd has | |
59 | * advanced out of the backlog the "err" value of the callback | |
60 | * will be -EINPROGRESS. Any other "err" value during callback is | |
61 | * the result of the operation. | |
62 | * | |
63 | * The cmd has been successfully queued if: | |
64 | * the return code is -EINPROGRESS or | |
65 | * the return code is -EBUSY and CCP_CMD_MAY_BACKLOG flag is set | |
66 | */ | |
67 | int ccp_enqueue_cmd(struct ccp_cmd *cmd); | |
68 | ||
720419f0 | 69 | #else /* CONFIG_CRYPTO_DEV_CCP_SP_DEV is not enabled */ |
db34cf91 | 70 | |
c9f21cb6 TL |
71 | static inline int ccp_present(void) |
72 | { | |
73 | return -ENODEV; | |
74 | } | |
75 | ||
c7019c4d GH |
76 | static inline unsigned int ccp_version(void) |
77 | { | |
78 | return 0; | |
79 | } | |
80 | ||
db34cf91 TL |
81 | static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd) |
82 | { | |
83 | return -ENODEV; | |
84 | } | |
85 | ||
720419f0 | 86 | #endif /* CONFIG_CRYPTO_DEV_SP_CCP */ |
db34cf91 | 87 | |
63b94509 TL |
88 | |
89 | /***** AES engine *****/ | |
90 | /** | |
91 | * ccp_aes_type - AES key size | |
92 | * | |
93 | * @CCP_AES_TYPE_128: 128-bit key | |
94 | * @CCP_AES_TYPE_192: 192-bit key | |
95 | * @CCP_AES_TYPE_256: 256-bit key | |
96 | */ | |
97 | enum ccp_aes_type { | |
98 | CCP_AES_TYPE_128 = 0, | |
99 | CCP_AES_TYPE_192, | |
100 | CCP_AES_TYPE_256, | |
101 | CCP_AES_TYPE__LAST, | |
102 | }; | |
103 | ||
104 | /** | |
105 | * ccp_aes_mode - AES operation mode | |
106 | * | |
107 | * @CCP_AES_MODE_ECB: ECB mode | |
108 | * @CCP_AES_MODE_CBC: CBC mode | |
109 | * @CCP_AES_MODE_OFB: OFB mode | |
110 | * @CCP_AES_MODE_CFB: CFB mode | |
111 | * @CCP_AES_MODE_CTR: CTR mode | |
112 | * @CCP_AES_MODE_CMAC: CMAC mode | |
113 | */ | |
114 | enum ccp_aes_mode { | |
115 | CCP_AES_MODE_ECB = 0, | |
116 | CCP_AES_MODE_CBC, | |
117 | CCP_AES_MODE_OFB, | |
118 | CCP_AES_MODE_CFB, | |
119 | CCP_AES_MODE_CTR, | |
120 | CCP_AES_MODE_CMAC, | |
36cf515b GH |
121 | CCP_AES_MODE_GHASH, |
122 | CCP_AES_MODE_GCTR, | |
123 | CCP_AES_MODE_GCM, | |
124 | CCP_AES_MODE_GMAC, | |
63b94509 TL |
125 | CCP_AES_MODE__LAST, |
126 | }; | |
127 | ||
128 | /** | |
129 | * ccp_aes_mode - AES operation mode | |
130 | * | |
131 | * @CCP_AES_ACTION_DECRYPT: AES decrypt operation | |
132 | * @CCP_AES_ACTION_ENCRYPT: AES encrypt operation | |
133 | */ | |
134 | enum ccp_aes_action { | |
135 | CCP_AES_ACTION_DECRYPT = 0, | |
136 | CCP_AES_ACTION_ENCRYPT, | |
137 | CCP_AES_ACTION__LAST, | |
138 | }; | |
36cf515b GH |
139 | /* Overloaded field */ |
140 | #define CCP_AES_GHASHAAD CCP_AES_ACTION_DECRYPT | |
141 | #define CCP_AES_GHASHFINAL CCP_AES_ACTION_ENCRYPT | |
63b94509 TL |
142 | |
143 | /** | |
144 | * struct ccp_aes_engine - CCP AES operation | |
145 | * @type: AES operation key size | |
146 | * @mode: AES operation mode | |
147 | * @action: AES operation (decrypt/encrypt) | |
148 | * @key: key to be used for this AES operation | |
149 | * @key_len: length in bytes of key | |
150 | * @iv: IV to be used for this AES operation | |
151 | * @iv_len: length in bytes of iv | |
152 | * @src: data to be used for this operation | |
153 | * @dst: data produced by this operation | |
154 | * @src_len: length in bytes of data used for this operation | |
155 | * @cmac_final: indicates final operation when running in CMAC mode | |
156 | * @cmac_key: K1/K2 key used in final CMAC operation | |
157 | * @cmac_key_len: length in bytes of cmac_key | |
158 | * | |
159 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
160 | * - type, mode, action, key, key_len, src, dst, src_len | |
161 | * - iv, iv_len for any mode other than ECB | |
162 | * - cmac_final for CMAC mode | |
163 | * - cmac_key, cmac_key_len for CMAC mode if cmac_final is non-zero | |
164 | * | |
165 | * The iv variable is used as both input and output. On completion of the | |
166 | * AES operation the new IV overwrites the old IV. | |
167 | */ | |
168 | struct ccp_aes_engine { | |
169 | enum ccp_aes_type type; | |
170 | enum ccp_aes_mode mode; | |
171 | enum ccp_aes_action action; | |
172 | ||
173 | struct scatterlist *key; | |
174 | u32 key_len; /* In bytes */ | |
175 | ||
176 | struct scatterlist *iv; | |
177 | u32 iv_len; /* In bytes */ | |
178 | ||
179 | struct scatterlist *src, *dst; | |
81a59f00 | 180 | u64 src_len; /* In bytes */ |
63b94509 TL |
181 | |
182 | u32 cmac_final; /* Indicates final cmac cmd */ | |
183 | struct scatterlist *cmac_key; /* K1/K2 cmac key required for | |
184 | * final cmac cmd */ | |
185 | u32 cmac_key_len; /* In bytes */ | |
36cf515b GH |
186 | |
187 | u32 aad_len; /* In bytes */ | |
63b94509 TL |
188 | }; |
189 | ||
190 | /***** XTS-AES engine *****/ | |
191 | /** | |
192 | * ccp_xts_aes_unit_size - XTS unit size | |
193 | * | |
194 | * @CCP_XTS_AES_UNIT_SIZE_16: Unit size of 16 bytes | |
195 | * @CCP_XTS_AES_UNIT_SIZE_512: Unit size of 512 bytes | |
196 | * @CCP_XTS_AES_UNIT_SIZE_1024: Unit size of 1024 bytes | |
197 | * @CCP_XTS_AES_UNIT_SIZE_2048: Unit size of 2048 bytes | |
198 | * @CCP_XTS_AES_UNIT_SIZE_4096: Unit size of 4096 bytes | |
199 | */ | |
200 | enum ccp_xts_aes_unit_size { | |
201 | CCP_XTS_AES_UNIT_SIZE_16 = 0, | |
202 | CCP_XTS_AES_UNIT_SIZE_512, | |
203 | CCP_XTS_AES_UNIT_SIZE_1024, | |
204 | CCP_XTS_AES_UNIT_SIZE_2048, | |
205 | CCP_XTS_AES_UNIT_SIZE_4096, | |
206 | CCP_XTS_AES_UNIT_SIZE__LAST, | |
207 | }; | |
208 | ||
209 | /** | |
210 | * struct ccp_xts_aes_engine - CCP XTS AES operation | |
211 | * @action: AES operation (decrypt/encrypt) | |
212 | * @unit_size: unit size of the XTS operation | |
213 | * @key: key to be used for this XTS AES operation | |
214 | * @key_len: length in bytes of key | |
215 | * @iv: IV to be used for this XTS AES operation | |
216 | * @iv_len: length in bytes of iv | |
217 | * @src: data to be used for this operation | |
218 | * @dst: data produced by this operation | |
219 | * @src_len: length in bytes of data used for this operation | |
220 | * @final: indicates final XTS operation | |
221 | * | |
222 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
223 | * - action, unit_size, key, key_len, iv, iv_len, src, dst, src_len, final | |
224 | * | |
225 | * The iv variable is used as both input and output. On completion of the | |
226 | * AES operation the new IV overwrites the old IV. | |
227 | */ | |
228 | struct ccp_xts_aes_engine { | |
e652399e | 229 | enum ccp_aes_type type; |
63b94509 TL |
230 | enum ccp_aes_action action; |
231 | enum ccp_xts_aes_unit_size unit_size; | |
232 | ||
233 | struct scatterlist *key; | |
234 | u32 key_len; /* In bytes */ | |
235 | ||
236 | struct scatterlist *iv; | |
237 | u32 iv_len; /* In bytes */ | |
238 | ||
239 | struct scatterlist *src, *dst; | |
81a59f00 | 240 | u64 src_len; /* In bytes */ |
63b94509 TL |
241 | |
242 | u32 final; | |
243 | }; | |
244 | ||
245 | /***** SHA engine *****/ | |
63b94509 TL |
246 | /** |
247 | * ccp_sha_type - type of SHA operation | |
248 | * | |
249 | * @CCP_SHA_TYPE_1: SHA-1 operation | |
250 | * @CCP_SHA_TYPE_224: SHA-224 operation | |
251 | * @CCP_SHA_TYPE_256: SHA-256 operation | |
252 | */ | |
253 | enum ccp_sha_type { | |
254 | CCP_SHA_TYPE_1 = 1, | |
255 | CCP_SHA_TYPE_224, | |
256 | CCP_SHA_TYPE_256, | |
ccebcf3f GH |
257 | CCP_SHA_TYPE_384, |
258 | CCP_SHA_TYPE_512, | |
63b94509 TL |
259 | CCP_SHA_TYPE__LAST, |
260 | }; | |
261 | ||
262 | /** | |
263 | * struct ccp_sha_engine - CCP SHA operation | |
264 | * @type: Type of SHA operation | |
265 | * @ctx: current hash value | |
266 | * @ctx_len: length in bytes of hash value | |
267 | * @src: data to be used for this operation | |
268 | * @src_len: length in bytes of data used for this operation | |
c11baa02 TL |
269 | * @opad: data to be used for final HMAC operation |
270 | * @opad_len: length in bytes of data used for final HMAC operation | |
271 | * @first: indicates first SHA operation | |
63b94509 TL |
272 | * @final: indicates final SHA operation |
273 | * @msg_bits: total length of the message in bits used in final SHA operation | |
274 | * | |
275 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
276 | * - type, ctx, ctx_len, src, src_len, final | |
277 | * - msg_bits if final is non-zero | |
278 | * | |
279 | * The ctx variable is used as both input and output. On completion of the | |
280 | * SHA operation the new hash value overwrites the old hash value. | |
281 | */ | |
282 | struct ccp_sha_engine { | |
283 | enum ccp_sha_type type; | |
284 | ||
285 | struct scatterlist *ctx; | |
286 | u32 ctx_len; /* In bytes */ | |
287 | ||
288 | struct scatterlist *src; | |
81a59f00 | 289 | u64 src_len; /* In bytes */ |
63b94509 | 290 | |
c11baa02 TL |
291 | struct scatterlist *opad; |
292 | u32 opad_len; /* In bytes */ | |
293 | ||
294 | u32 first; /* Indicates first sha cmd */ | |
63b94509 TL |
295 | u32 final; /* Indicates final sha cmd */ |
296 | u64 msg_bits; /* Message length in bits required for | |
297 | * final sha cmd */ | |
298 | }; | |
299 | ||
990672d4 GH |
300 | /***** 3DES engine *****/ |
301 | enum ccp_des3_mode { | |
302 | CCP_DES3_MODE_ECB = 0, | |
303 | CCP_DES3_MODE_CBC, | |
304 | CCP_DES3_MODE_CFB, | |
305 | CCP_DES3_MODE__LAST, | |
306 | }; | |
307 | ||
308 | enum ccp_des3_type { | |
309 | CCP_DES3_TYPE_168 = 1, | |
310 | CCP_DES3_TYPE__LAST, | |
311 | }; | |
312 | ||
313 | enum ccp_des3_action { | |
314 | CCP_DES3_ACTION_DECRYPT = 0, | |
315 | CCP_DES3_ACTION_ENCRYPT, | |
316 | CCP_DES3_ACTION__LAST, | |
317 | }; | |
318 | ||
319 | /** | |
320 | * struct ccp_des3_engine - CCP SHA operation | |
321 | * @type: Type of 3DES operation | |
322 | * @mode: cipher mode | |
323 | * @action: 3DES operation (decrypt/encrypt) | |
324 | * @key: key to be used for this 3DES operation | |
325 | * @key_len: length of key (in bytes) | |
326 | * @iv: IV to be used for this AES operation | |
327 | * @iv_len: length in bytes of iv | |
328 | * @src: input data to be used for this operation | |
329 | * @src_len: length of input data used for this operation (in bytes) | |
330 | * @dst: output data produced by this operation | |
331 | * | |
332 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
333 | * - type, mode, action, key, key_len, src, dst, src_len | |
334 | * - iv, iv_len for any mode other than ECB | |
335 | * | |
336 | * The iv variable is used as both input and output. On completion of the | |
337 | * 3DES operation the new IV overwrites the old IV. | |
338 | */ | |
339 | struct ccp_des3_engine { | |
340 | enum ccp_des3_type type; | |
341 | enum ccp_des3_mode mode; | |
342 | enum ccp_des3_action action; | |
343 | ||
344 | struct scatterlist *key; | |
345 | u32 key_len; /* In bytes */ | |
346 | ||
347 | struct scatterlist *iv; | |
348 | u32 iv_len; /* In bytes */ | |
349 | ||
350 | struct scatterlist *src, *dst; | |
351 | u64 src_len; /* In bytes */ | |
352 | }; | |
353 | ||
63b94509 TL |
354 | /***** RSA engine *****/ |
355 | /** | |
356 | * struct ccp_rsa_engine - CCP RSA operation | |
357 | * @key_size: length in bits of RSA key | |
358 | * @exp: RSA exponent | |
359 | * @exp_len: length in bytes of exponent | |
360 | * @mod: RSA modulus | |
361 | * @mod_len: length in bytes of modulus | |
362 | * @src: data to be used for this operation | |
363 | * @dst: data produced by this operation | |
364 | * @src_len: length in bytes of data used for this operation | |
365 | * | |
366 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
367 | * - key_size, exp, exp_len, mod, mod_len, src, dst, src_len | |
368 | */ | |
369 | struct ccp_rsa_engine { | |
370 | u32 key_size; /* In bits */ | |
371 | ||
372 | struct scatterlist *exp; | |
373 | u32 exp_len; /* In bytes */ | |
374 | ||
375 | struct scatterlist *mod; | |
376 | u32 mod_len; /* In bytes */ | |
377 | ||
378 | struct scatterlist *src, *dst; | |
379 | u32 src_len; /* In bytes */ | |
380 | }; | |
381 | ||
382 | /***** Passthru engine *****/ | |
383 | /** | |
384 | * ccp_passthru_bitwise - type of bitwise passthru operation | |
385 | * | |
386 | * @CCP_PASSTHRU_BITWISE_NOOP: no bitwise operation performed | |
387 | * @CCP_PASSTHRU_BITWISE_AND: perform bitwise AND of src with mask | |
388 | * @CCP_PASSTHRU_BITWISE_OR: perform bitwise OR of src with mask | |
389 | * @CCP_PASSTHRU_BITWISE_XOR: perform bitwise XOR of src with mask | |
390 | * @CCP_PASSTHRU_BITWISE_MASK: overwrite with mask | |
391 | */ | |
392 | enum ccp_passthru_bitwise { | |
393 | CCP_PASSTHRU_BITWISE_NOOP = 0, | |
394 | CCP_PASSTHRU_BITWISE_AND, | |
395 | CCP_PASSTHRU_BITWISE_OR, | |
396 | CCP_PASSTHRU_BITWISE_XOR, | |
397 | CCP_PASSTHRU_BITWISE_MASK, | |
398 | CCP_PASSTHRU_BITWISE__LAST, | |
399 | }; | |
400 | ||
401 | /** | |
402 | * ccp_passthru_byteswap - type of byteswap passthru operation | |
403 | * | |
404 | * @CCP_PASSTHRU_BYTESWAP_NOOP: no byte swapping performed | |
405 | * @CCP_PASSTHRU_BYTESWAP_32BIT: swap bytes within 32-bit words | |
406 | * @CCP_PASSTHRU_BYTESWAP_256BIT: swap bytes within 256-bit words | |
407 | */ | |
408 | enum ccp_passthru_byteswap { | |
409 | CCP_PASSTHRU_BYTESWAP_NOOP = 0, | |
410 | CCP_PASSTHRU_BYTESWAP_32BIT, | |
411 | CCP_PASSTHRU_BYTESWAP_256BIT, | |
412 | CCP_PASSTHRU_BYTESWAP__LAST, | |
413 | }; | |
414 | ||
415 | /** | |
416 | * struct ccp_passthru_engine - CCP pass-through operation | |
417 | * @bit_mod: bitwise operation to perform | |
418 | * @byte_swap: byteswap operation to perform | |
419 | * @mask: mask to be applied to data | |
420 | * @mask_len: length in bytes of mask | |
421 | * @src: data to be used for this operation | |
422 | * @dst: data produced by this operation | |
423 | * @src_len: length in bytes of data used for this operation | |
424 | * @final: indicate final pass-through operation | |
425 | * | |
426 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
427 | * - bit_mod, byte_swap, src, dst, src_len | |
428 | * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP | |
429 | */ | |
430 | struct ccp_passthru_engine { | |
431 | enum ccp_passthru_bitwise bit_mod; | |
432 | enum ccp_passthru_byteswap byte_swap; | |
433 | ||
434 | struct scatterlist *mask; | |
435 | u32 mask_len; /* In bytes */ | |
436 | ||
437 | struct scatterlist *src, *dst; | |
81a59f00 | 438 | u64 src_len; /* In bytes */ |
63b94509 TL |
439 | |
440 | u32 final; | |
441 | }; | |
442 | ||
58ea8abf GH |
443 | /** |
444 | * struct ccp_passthru_nomap_engine - CCP pass-through operation | |
445 | * without performing DMA mapping | |
446 | * @bit_mod: bitwise operation to perform | |
447 | * @byte_swap: byteswap operation to perform | |
448 | * @mask: mask to be applied to data | |
449 | * @mask_len: length in bytes of mask | |
450 | * @src: data to be used for this operation | |
451 | * @dst: data produced by this operation | |
452 | * @src_len: length in bytes of data used for this operation | |
453 | * @final: indicate final pass-through operation | |
454 | * | |
455 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
456 | * - bit_mod, byte_swap, src, dst, src_len | |
457 | * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP | |
458 | */ | |
459 | struct ccp_passthru_nomap_engine { | |
460 | enum ccp_passthru_bitwise bit_mod; | |
461 | enum ccp_passthru_byteswap byte_swap; | |
462 | ||
463 | dma_addr_t mask; | |
464 | u32 mask_len; /* In bytes */ | |
465 | ||
466 | dma_addr_t src_dma, dst_dma; | |
467 | u64 src_len; /* In bytes */ | |
468 | ||
469 | u32 final; | |
470 | }; | |
471 | ||
63b94509 TL |
472 | /***** ECC engine *****/ |
473 | #define CCP_ECC_MODULUS_BYTES 48 /* 384-bits */ | |
474 | #define CCP_ECC_MAX_OPERANDS 6 | |
475 | #define CCP_ECC_MAX_OUTPUTS 3 | |
476 | ||
477 | /** | |
478 | * ccp_ecc_function - type of ECC function | |
479 | * | |
480 | * @CCP_ECC_FUNCTION_MMUL_384BIT: 384-bit modular multiplication | |
481 | * @CCP_ECC_FUNCTION_MADD_384BIT: 384-bit modular addition | |
482 | * @CCP_ECC_FUNCTION_MINV_384BIT: 384-bit multiplicative inverse | |
483 | * @CCP_ECC_FUNCTION_PADD_384BIT: 384-bit point addition | |
484 | * @CCP_ECC_FUNCTION_PMUL_384BIT: 384-bit point multiplication | |
485 | * @CCP_ECC_FUNCTION_PDBL_384BIT: 384-bit point doubling | |
486 | */ | |
487 | enum ccp_ecc_function { | |
488 | CCP_ECC_FUNCTION_MMUL_384BIT = 0, | |
489 | CCP_ECC_FUNCTION_MADD_384BIT, | |
490 | CCP_ECC_FUNCTION_MINV_384BIT, | |
491 | CCP_ECC_FUNCTION_PADD_384BIT, | |
492 | CCP_ECC_FUNCTION_PMUL_384BIT, | |
493 | CCP_ECC_FUNCTION_PDBL_384BIT, | |
494 | }; | |
495 | ||
496 | /** | |
497 | * struct ccp_ecc_modular_math - CCP ECC modular math parameters | |
498 | * @operand_1: first operand for the modular math operation | |
499 | * @operand_1_len: length of the first operand | |
500 | * @operand_2: second operand for the modular math operation | |
501 | * (not used for CCP_ECC_FUNCTION_MINV_384BIT) | |
502 | * @operand_2_len: length of the second operand | |
503 | * (not used for CCP_ECC_FUNCTION_MINV_384BIT) | |
504 | * @result: result of the modular math operation | |
505 | * @result_len: length of the supplied result buffer | |
506 | */ | |
507 | struct ccp_ecc_modular_math { | |
508 | struct scatterlist *operand_1; | |
509 | unsigned int operand_1_len; /* In bytes */ | |
510 | ||
511 | struct scatterlist *operand_2; | |
512 | unsigned int operand_2_len; /* In bytes */ | |
513 | ||
514 | struct scatterlist *result; | |
515 | unsigned int result_len; /* In bytes */ | |
516 | }; | |
517 | ||
518 | /** | |
519 | * struct ccp_ecc_point - CCP ECC point definition | |
520 | * @x: the x coordinate of the ECC point | |
521 | * @x_len: the length of the x coordinate | |
522 | * @y: the y coordinate of the ECC point | |
523 | * @y_len: the length of the y coordinate | |
524 | */ | |
525 | struct ccp_ecc_point { | |
526 | struct scatterlist *x; | |
527 | unsigned int x_len; /* In bytes */ | |
528 | ||
529 | struct scatterlist *y; | |
530 | unsigned int y_len; /* In bytes */ | |
531 | }; | |
532 | ||
533 | /** | |
534 | * struct ccp_ecc_point_math - CCP ECC point math parameters | |
535 | * @point_1: the first point of the ECC point math operation | |
536 | * @point_2: the second point of the ECC point math operation | |
537 | * (only used for CCP_ECC_FUNCTION_PADD_384BIT) | |
538 | * @domain_a: the a parameter of the ECC curve | |
539 | * @domain_a_len: the length of the a parameter | |
540 | * @scalar: the scalar parameter for the point match operation | |
541 | * (only used for CCP_ECC_FUNCTION_PMUL_384BIT) | |
542 | * @scalar_len: the length of the scalar parameter | |
543 | * (only used for CCP_ECC_FUNCTION_PMUL_384BIT) | |
544 | * @result: the point resulting from the point math operation | |
545 | */ | |
546 | struct ccp_ecc_point_math { | |
547 | struct ccp_ecc_point point_1; | |
548 | struct ccp_ecc_point point_2; | |
549 | ||
550 | struct scatterlist *domain_a; | |
551 | unsigned int domain_a_len; /* In bytes */ | |
552 | ||
553 | struct scatterlist *scalar; | |
554 | unsigned int scalar_len; /* In bytes */ | |
555 | ||
556 | struct ccp_ecc_point result; | |
557 | }; | |
558 | ||
559 | /** | |
560 | * struct ccp_ecc_engine - CCP ECC operation | |
561 | * @function: ECC function to perform | |
562 | * @mod: ECC modulus | |
563 | * @mod_len: length in bytes of modulus | |
564 | * @mm: module math parameters | |
565 | * @pm: point math parameters | |
566 | * @ecc_result: result of the ECC operation | |
567 | * | |
568 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
569 | * - function, mod, mod_len | |
570 | * - operand, operand_len, operand_count, output, output_len, output_count | |
571 | * - ecc_result | |
572 | */ | |
573 | struct ccp_ecc_engine { | |
574 | enum ccp_ecc_function function; | |
575 | ||
576 | struct scatterlist *mod; | |
577 | u32 mod_len; /* In bytes */ | |
578 | ||
579 | union { | |
580 | struct ccp_ecc_modular_math mm; | |
581 | struct ccp_ecc_point_math pm; | |
582 | } u; | |
583 | ||
584 | u16 ecc_result; | |
585 | }; | |
586 | ||
587 | ||
588 | /** | |
589 | * ccp_engine - CCP operation identifiers | |
590 | * | |
591 | * @CCP_ENGINE_AES: AES operation | |
592 | * @CCP_ENGINE_XTS_AES: 128-bit XTS AES operation | |
593 | * @CCP_ENGINE_RSVD1: unused | |
594 | * @CCP_ENGINE_SHA: SHA operation | |
595 | * @CCP_ENGINE_RSA: RSA operation | |
596 | * @CCP_ENGINE_PASSTHRU: pass-through operation | |
597 | * @CCP_ENGINE_ZLIB_DECOMPRESS: unused | |
598 | * @CCP_ENGINE_ECC: ECC operation | |
599 | */ | |
600 | enum ccp_engine { | |
601 | CCP_ENGINE_AES = 0, | |
602 | CCP_ENGINE_XTS_AES_128, | |
990672d4 | 603 | CCP_ENGINE_DES3, |
63b94509 TL |
604 | CCP_ENGINE_SHA, |
605 | CCP_ENGINE_RSA, | |
606 | CCP_ENGINE_PASSTHRU, | |
607 | CCP_ENGINE_ZLIB_DECOMPRESS, | |
608 | CCP_ENGINE_ECC, | |
609 | CCP_ENGINE__LAST, | |
610 | }; | |
611 | ||
612 | /* Flag values for flags member of ccp_cmd */ | |
58ea8abf GH |
613 | #define CCP_CMD_MAY_BACKLOG 0x00000001 |
614 | #define CCP_CMD_PASSTHRU_NO_DMA_MAP 0x00000002 | |
63b94509 TL |
615 | |
616 | /** | |
c8d283ff | 617 | * struct ccp_cmd - CCP operation request |
63b94509 TL |
618 | * @entry: list element (ccp driver use only) |
619 | * @work: work element used for callbacks (ccp driver use only) | |
7c468447 | 620 | * @ccp: CCP device to be run on |
63b94509 TL |
621 | * @ret: operation return code (ccp driver use only) |
622 | * @flags: cmd processing flags | |
623 | * @engine: CCP operation to perform | |
624 | * @engine_error: CCP engine return code | |
625 | * @u: engine specific structures, refer to specific engine struct below | |
626 | * @callback: operation completion callback function | |
627 | * @data: parameter value to be supplied to the callback function | |
628 | * | |
629 | * Variables required to be set when calling ccp_enqueue_cmd(): | |
630 | * - engine, callback | |
631 | * - See the operation structures below for what is required for each | |
632 | * operation. | |
633 | */ | |
634 | struct ccp_cmd { | |
635 | /* The list_head, work_struct, ccp and ret variables are for use | |
636 | * by the CCP driver only. | |
637 | */ | |
638 | struct list_head entry; | |
639 | struct work_struct work; | |
640 | struct ccp_device *ccp; | |
641 | int ret; | |
642 | ||
643 | u32 flags; | |
644 | ||
645 | enum ccp_engine engine; | |
646 | u32 engine_error; | |
647 | ||
648 | union { | |
649 | struct ccp_aes_engine aes; | |
650 | struct ccp_xts_aes_engine xts; | |
990672d4 | 651 | struct ccp_des3_engine des3; |
63b94509 TL |
652 | struct ccp_sha_engine sha; |
653 | struct ccp_rsa_engine rsa; | |
654 | struct ccp_passthru_engine passthru; | |
58ea8abf | 655 | struct ccp_passthru_nomap_engine passthru_nomap; |
63b94509 TL |
656 | struct ccp_ecc_engine ecc; |
657 | } u; | |
658 | ||
659 | /* Completion callback support */ | |
660 | void (*callback)(void *data, int err); | |
661 | void *data; | |
662 | }; | |
663 | ||
664 | #endif |