ccp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. struct scatterlist *key;
  158. u32 key_len; /* In bytes */
  159. struct scatterlist *iv;
  160. u32 iv_len; /* In bytes */
  161. struct scatterlist *src, *dst;
  162. u64 src_len; /* In bytes */
  163. u32 cmac_final; /* Indicates final cmac cmd */
  164. struct scatterlist *cmac_key; /* K1/K2 cmac key required for
  165. * final cmac cmd */
  166. u32 cmac_key_len; /* In bytes */
  167. u32 aad_len; /* In bytes */
  168. };
  169. /***** XTS-AES engine *****/
  170. /**
  171. * ccp_xts_aes_unit_size - XTS unit size
  172. *
  173. * @CCP_XTS_AES_UNIT_SIZE_16: Unit size of 16 bytes
  174. * @CCP_XTS_AES_UNIT_SIZE_512: Unit size of 512 bytes
  175. * @CCP_XTS_AES_UNIT_SIZE_1024: Unit size of 1024 bytes
  176. * @CCP_XTS_AES_UNIT_SIZE_2048: Unit size of 2048 bytes
  177. * @CCP_XTS_AES_UNIT_SIZE_4096: Unit size of 4096 bytes
  178. */
  179. enum ccp_xts_aes_unit_size {
  180. CCP_XTS_AES_UNIT_SIZE_16 = 0,
  181. CCP_XTS_AES_UNIT_SIZE_512,
  182. CCP_XTS_AES_UNIT_SIZE_1024,
  183. CCP_XTS_AES_UNIT_SIZE_2048,
  184. CCP_XTS_AES_UNIT_SIZE_4096,
  185. CCP_XTS_AES_UNIT_SIZE__LAST,
  186. };
  187. /**
  188. * struct ccp_xts_aes_engine - CCP XTS AES operation
  189. * @action: AES operation (decrypt/encrypt)
  190. * @unit_size: unit size of the XTS operation
  191. * @key: key to be used for this XTS AES operation
  192. * @key_len: length in bytes of key
  193. * @iv: IV to be used for this XTS AES operation
  194. * @iv_len: length in bytes of iv
  195. * @src: data to be used for this operation
  196. * @dst: data produced by this operation
  197. * @src_len: length in bytes of data used for this operation
  198. * @final: indicates final XTS operation
  199. *
  200. * Variables required to be set when calling ccp_enqueue_cmd():
  201. * - action, unit_size, key, key_len, iv, iv_len, src, dst, src_len, final
  202. *
  203. * The iv variable is used as both input and output. On completion of the
  204. * AES operation the new IV overwrites the old IV.
  205. */
  206. struct ccp_xts_aes_engine {
  207. enum ccp_aes_type type;
  208. enum ccp_aes_action action;
  209. enum ccp_xts_aes_unit_size unit_size;
  210. struct scatterlist *key;
  211. u32 key_len; /* In bytes */
  212. struct scatterlist *iv;
  213. u32 iv_len; /* In bytes */
  214. struct scatterlist *src, *dst;
  215. u64 src_len; /* In bytes */
  216. u32 final;
  217. };
  218. /***** SHA engine *****/
  219. /**
  220. * ccp_sha_type - type of SHA operation
  221. *
  222. * @CCP_SHA_TYPE_1: SHA-1 operation
  223. * @CCP_SHA_TYPE_224: SHA-224 operation
  224. * @CCP_SHA_TYPE_256: SHA-256 operation
  225. */
  226. enum ccp_sha_type {
  227. CCP_SHA_TYPE_1 = 1,
  228. CCP_SHA_TYPE_224,
  229. CCP_SHA_TYPE_256,
  230. CCP_SHA_TYPE_384,
  231. CCP_SHA_TYPE_512,
  232. CCP_SHA_TYPE__LAST,
  233. };
  234. /**
  235. * struct ccp_sha_engine - CCP SHA operation
  236. * @type: Type of SHA operation
  237. * @ctx: current hash value
  238. * @ctx_len: length in bytes of hash value
  239. * @src: data to be used for this operation
  240. * @src_len: length in bytes of data used for this operation
  241. * @opad: data to be used for final HMAC operation
  242. * @opad_len: length in bytes of data used for final HMAC operation
  243. * @first: indicates first SHA operation
  244. * @final: indicates final SHA operation
  245. * @msg_bits: total length of the message in bits used in final SHA operation
  246. *
  247. * Variables required to be set when calling ccp_enqueue_cmd():
  248. * - type, ctx, ctx_len, src, src_len, final
  249. * - msg_bits if final is non-zero
  250. *
  251. * The ctx variable is used as both input and output. On completion of the
  252. * SHA operation the new hash value overwrites the old hash value.
  253. */
  254. struct ccp_sha_engine {
  255. enum ccp_sha_type type;
  256. struct scatterlist *ctx;
  257. u32 ctx_len; /* In bytes */
  258. struct scatterlist *src;
  259. u64 src_len; /* In bytes */
  260. struct scatterlist *opad;
  261. u32 opad_len; /* In bytes */
  262. u32 first; /* Indicates first sha cmd */
  263. u32 final; /* Indicates final sha cmd */
  264. u64 msg_bits; /* Message length in bits required for
  265. * final sha cmd */
  266. };
  267. /***** 3DES engine *****/
  268. enum ccp_des3_mode {
  269. CCP_DES3_MODE_ECB = 0,
  270. CCP_DES3_MODE_CBC,
  271. CCP_DES3_MODE_CFB,
  272. CCP_DES3_MODE__LAST,
  273. };
  274. enum ccp_des3_type {
  275. CCP_DES3_TYPE_168 = 1,
  276. CCP_DES3_TYPE__LAST,
  277. };
  278. enum ccp_des3_action {
  279. CCP_DES3_ACTION_DECRYPT = 0,
  280. CCP_DES3_ACTION_ENCRYPT,
  281. CCP_DES3_ACTION__LAST,
  282. };
  283. /**
  284. * struct ccp_des3_engine - CCP SHA operation
  285. * @type: Type of 3DES operation
  286. * @mode: cipher mode
  287. * @action: 3DES operation (decrypt/encrypt)
  288. * @key: key to be used for this 3DES operation
  289. * @key_len: length of key (in bytes)
  290. * @iv: IV to be used for this AES operation
  291. * @iv_len: length in bytes of iv
  292. * @src: input data to be used for this operation
  293. * @src_len: length of input data used for this operation (in bytes)
  294. * @dst: output data produced by this operation
  295. *
  296. * Variables required to be set when calling ccp_enqueue_cmd():
  297. * - type, mode, action, key, key_len, src, dst, src_len
  298. * - iv, iv_len for any mode other than ECB
  299. *
  300. * The iv variable is used as both input and output. On completion of the
  301. * 3DES operation the new IV overwrites the old IV.
  302. */
  303. struct ccp_des3_engine {
  304. enum ccp_des3_type type;
  305. enum ccp_des3_mode mode;
  306. enum ccp_des3_action action;
  307. struct scatterlist *key;
  308. u32 key_len; /* In bytes */
  309. struct scatterlist *iv;
  310. u32 iv_len; /* In bytes */
  311. struct scatterlist *src, *dst;
  312. u64 src_len; /* In bytes */
  313. };
  314. /***** RSA engine *****/
  315. /**
  316. * struct ccp_rsa_engine - CCP RSA operation
  317. * @key_size: length in bits of RSA key
  318. * @exp: RSA exponent
  319. * @exp_len: length in bytes of exponent
  320. * @mod: RSA modulus
  321. * @mod_len: length in bytes of modulus
  322. * @src: data to be used for this operation
  323. * @dst: data produced by this operation
  324. * @src_len: length in bytes of data used for this operation
  325. *
  326. * Variables required to be set when calling ccp_enqueue_cmd():
  327. * - key_size, exp, exp_len, mod, mod_len, src, dst, src_len
  328. */
  329. struct ccp_rsa_engine {
  330. u32 key_size; /* In bits */
  331. struct scatterlist *exp;
  332. u32 exp_len; /* In bytes */
  333. struct scatterlist *mod;
  334. u32 mod_len; /* In bytes */
  335. struct scatterlist *src, *dst;
  336. u32 src_len; /* In bytes */
  337. };
  338. /***** Passthru engine *****/
  339. /**
  340. * ccp_passthru_bitwise - type of bitwise passthru operation
  341. *
  342. * @CCP_PASSTHRU_BITWISE_NOOP: no bitwise operation performed
  343. * @CCP_PASSTHRU_BITWISE_AND: perform bitwise AND of src with mask
  344. * @CCP_PASSTHRU_BITWISE_OR: perform bitwise OR of src with mask
  345. * @CCP_PASSTHRU_BITWISE_XOR: perform bitwise XOR of src with mask
  346. * @CCP_PASSTHRU_BITWISE_MASK: overwrite with mask
  347. */
  348. enum ccp_passthru_bitwise {
  349. CCP_PASSTHRU_BITWISE_NOOP = 0,
  350. CCP_PASSTHRU_BITWISE_AND,
  351. CCP_PASSTHRU_BITWISE_OR,
  352. CCP_PASSTHRU_BITWISE_XOR,
  353. CCP_PASSTHRU_BITWISE_MASK,
  354. CCP_PASSTHRU_BITWISE__LAST,
  355. };
  356. /**
  357. * ccp_passthru_byteswap - type of byteswap passthru operation
  358. *
  359. * @CCP_PASSTHRU_BYTESWAP_NOOP: no byte swapping performed
  360. * @CCP_PASSTHRU_BYTESWAP_32BIT: swap bytes within 32-bit words
  361. * @CCP_PASSTHRU_BYTESWAP_256BIT: swap bytes within 256-bit words
  362. */
  363. enum ccp_passthru_byteswap {
  364. CCP_PASSTHRU_BYTESWAP_NOOP = 0,
  365. CCP_PASSTHRU_BYTESWAP_32BIT,
  366. CCP_PASSTHRU_BYTESWAP_256BIT,
  367. CCP_PASSTHRU_BYTESWAP__LAST,
  368. };
  369. /**
  370. * struct ccp_passthru_engine - CCP pass-through operation
  371. * @bit_mod: bitwise operation to perform
  372. * @byte_swap: byteswap operation to perform
  373. * @mask: mask to be applied to data
  374. * @mask_len: length in bytes of mask
  375. * @src: data to be used for this operation
  376. * @dst: data produced by this operation
  377. * @src_len: length in bytes of data used for this operation
  378. * @final: indicate final pass-through operation
  379. *
  380. * Variables required to be set when calling ccp_enqueue_cmd():
  381. * - bit_mod, byte_swap, src, dst, src_len
  382. * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP
  383. */
  384. struct ccp_passthru_engine {
  385. enum ccp_passthru_bitwise bit_mod;
  386. enum ccp_passthru_byteswap byte_swap;
  387. struct scatterlist *mask;
  388. u32 mask_len; /* In bytes */
  389. struct scatterlist *src, *dst;
  390. u64 src_len; /* In bytes */
  391. u32 final;
  392. };
  393. /**
  394. * struct ccp_passthru_nomap_engine - CCP pass-through operation
  395. * without performing DMA mapping
  396. * @bit_mod: bitwise operation to perform
  397. * @byte_swap: byteswap operation to perform
  398. * @mask: mask to be applied to data
  399. * @mask_len: length in bytes of mask
  400. * @src: data to be used for this operation
  401. * @dst: data produced by this operation
  402. * @src_len: length in bytes of data used for this operation
  403. * @final: indicate final pass-through operation
  404. *
  405. * Variables required to be set when calling ccp_enqueue_cmd():
  406. * - bit_mod, byte_swap, src, dst, src_len
  407. * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP
  408. */
  409. struct ccp_passthru_nomap_engine {
  410. enum ccp_passthru_bitwise bit_mod;
  411. enum ccp_passthru_byteswap byte_swap;
  412. dma_addr_t mask;
  413. u32 mask_len; /* In bytes */
  414. dma_addr_t src_dma, dst_dma;
  415. u64 src_len; /* In bytes */
  416. u32 final;
  417. };
  418. /***** ECC engine *****/
  419. #define CCP_ECC_MODULUS_BYTES 48 /* 384-bits */
  420. #define CCP_ECC_MAX_OPERANDS 6
  421. #define CCP_ECC_MAX_OUTPUTS 3
  422. /**
  423. * ccp_ecc_function - type of ECC function
  424. *
  425. * @CCP_ECC_FUNCTION_MMUL_384BIT: 384-bit modular multiplication
  426. * @CCP_ECC_FUNCTION_MADD_384BIT: 384-bit modular addition
  427. * @CCP_ECC_FUNCTION_MINV_384BIT: 384-bit multiplicative inverse
  428. * @CCP_ECC_FUNCTION_PADD_384BIT: 384-bit point addition
  429. * @CCP_ECC_FUNCTION_PMUL_384BIT: 384-bit point multiplication
  430. * @CCP_ECC_FUNCTION_PDBL_384BIT: 384-bit point doubling
  431. */
  432. enum ccp_ecc_function {
  433. CCP_ECC_FUNCTION_MMUL_384BIT = 0,
  434. CCP_ECC_FUNCTION_MADD_384BIT,
  435. CCP_ECC_FUNCTION_MINV_384BIT,
  436. CCP_ECC_FUNCTION_PADD_384BIT,
  437. CCP_ECC_FUNCTION_PMUL_384BIT,
  438. CCP_ECC_FUNCTION_PDBL_384BIT,
  439. };
  440. /**
  441. * struct ccp_ecc_modular_math - CCP ECC modular math parameters
  442. * @operand_1: first operand for the modular math operation
  443. * @operand_1_len: length of the first operand
  444. * @operand_2: second operand for the modular math operation
  445. * (not used for CCP_ECC_FUNCTION_MINV_384BIT)
  446. * @operand_2_len: length of the second operand
  447. * (not used for CCP_ECC_FUNCTION_MINV_384BIT)
  448. * @result: result of the modular math operation
  449. * @result_len: length of the supplied result buffer
  450. */
  451. struct ccp_ecc_modular_math {
  452. struct scatterlist *operand_1;
  453. unsigned int operand_1_len; /* In bytes */
  454. struct scatterlist *operand_2;
  455. unsigned int operand_2_len; /* In bytes */
  456. struct scatterlist *result;
  457. unsigned int result_len; /* In bytes */
  458. };
  459. /**
  460. * struct ccp_ecc_point - CCP ECC point definition
  461. * @x: the x coordinate of the ECC point
  462. * @x_len: the length of the x coordinate
  463. * @y: the y coordinate of the ECC point
  464. * @y_len: the length of the y coordinate
  465. */
  466. struct ccp_ecc_point {
  467. struct scatterlist *x;
  468. unsigned int x_len; /* In bytes */
  469. struct scatterlist *y;
  470. unsigned int y_len; /* In bytes */
  471. };
  472. /**
  473. * struct ccp_ecc_point_math - CCP ECC point math parameters
  474. * @point_1: the first point of the ECC point math operation
  475. * @point_2: the second point of the ECC point math operation
  476. * (only used for CCP_ECC_FUNCTION_PADD_384BIT)
  477. * @domain_a: the a parameter of the ECC curve
  478. * @domain_a_len: the length of the a parameter
  479. * @scalar: the scalar parameter for the point match operation
  480. * (only used for CCP_ECC_FUNCTION_PMUL_384BIT)
  481. * @scalar_len: the length of the scalar parameter
  482. * (only used for CCP_ECC_FUNCTION_PMUL_384BIT)
  483. * @result: the point resulting from the point math operation
  484. */
  485. struct ccp_ecc_point_math {
  486. struct ccp_ecc_point point_1;
  487. struct ccp_ecc_point point_2;
  488. struct scatterlist *domain_a;
  489. unsigned int domain_a_len; /* In bytes */
  490. struct scatterlist *scalar;
  491. unsigned int scalar_len; /* In bytes */
  492. struct ccp_ecc_point result;
  493. };
  494. /**
  495. * struct ccp_ecc_engine - CCP ECC operation
  496. * @function: ECC function to perform
  497. * @mod: ECC modulus
  498. * @mod_len: length in bytes of modulus
  499. * @mm: module math parameters
  500. * @pm: point math parameters
  501. * @ecc_result: result of the ECC operation
  502. *
  503. * Variables required to be set when calling ccp_enqueue_cmd():
  504. * - function, mod, mod_len
  505. * - operand, operand_len, operand_count, output, output_len, output_count
  506. * - ecc_result
  507. */
  508. struct ccp_ecc_engine {
  509. enum ccp_ecc_function function;
  510. struct scatterlist *mod;
  511. u32 mod_len; /* In bytes */
  512. union {
  513. struct ccp_ecc_modular_math mm;
  514. struct ccp_ecc_point_math pm;
  515. } u;
  516. u16 ecc_result;
  517. };
  518. /**
  519. * ccp_engine - CCP operation identifiers
  520. *
  521. * @CCP_ENGINE_AES: AES operation
  522. * @CCP_ENGINE_XTS_AES: 128-bit XTS AES operation
  523. * @CCP_ENGINE_RSVD1: unused
  524. * @CCP_ENGINE_SHA: SHA operation
  525. * @CCP_ENGINE_RSA: RSA operation
  526. * @CCP_ENGINE_PASSTHRU: pass-through operation
  527. * @CCP_ENGINE_ZLIB_DECOMPRESS: unused
  528. * @CCP_ENGINE_ECC: ECC operation
  529. */
  530. enum ccp_engine {
  531. CCP_ENGINE_AES = 0,
  532. CCP_ENGINE_XTS_AES_128,
  533. CCP_ENGINE_DES3,
  534. CCP_ENGINE_SHA,
  535. CCP_ENGINE_RSA,
  536. CCP_ENGINE_PASSTHRU,
  537. CCP_ENGINE_ZLIB_DECOMPRESS,
  538. CCP_ENGINE_ECC,
  539. CCP_ENGINE__LAST,
  540. };
  541. /* Flag values for flags member of ccp_cmd */
  542. #define CCP_CMD_MAY_BACKLOG 0x00000001
  543. #define CCP_CMD_PASSTHRU_NO_DMA_MAP 0x00000002
  544. /**
  545. * struct ccp_cmd - CCP operation request
  546. * @entry: list element (ccp driver use only)
  547. * @work: work element used for callbacks (ccp driver use only)
  548. * @ccp: CCP device to be run on
  549. * @ret: operation return code (ccp driver use only)
  550. * @flags: cmd processing flags
  551. * @engine: CCP operation to perform
  552. * @engine_error: CCP engine return code
  553. * @u: engine specific structures, refer to specific engine struct below
  554. * @callback: operation completion callback function
  555. * @data: parameter value to be supplied to the callback function
  556. *
  557. * Variables required to be set when calling ccp_enqueue_cmd():
  558. * - engine, callback
  559. * - See the operation structures below for what is required for each
  560. * operation.
  561. */
  562. struct ccp_cmd {
  563. /* The list_head, work_struct, ccp and ret variables are for use
  564. * by the CCP driver only.
  565. */
  566. struct list_head entry;
  567. struct work_struct work;
  568. struct ccp_device *ccp;
  569. int ret;
  570. u32 flags;
  571. enum ccp_engine engine;
  572. u32 engine_error;
  573. union {
  574. struct ccp_aes_engine aes;
  575. struct ccp_xts_aes_engine xts;
  576. struct ccp_des3_engine des3;
  577. struct ccp_sha_engine sha;
  578. struct ccp_rsa_engine rsa;
  579. struct ccp_passthru_engine passthru;
  580. struct ccp_passthru_nomap_engine passthru_nomap;
  581. struct ccp_ecc_engine ecc;
  582. } u;
  583. /* Completion callback support */
  584. void (*callback)(void *data, int err);
  585. void *data;
  586. };
  587. #endif