ccp.h 18 KB

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