163b94509STom Lendacky /* 263b94509STom Lendacky * AMD Cryptographic Coprocessor (CCP) driver 363b94509STom Lendacky * 463b94509STom Lendacky * Copyright (C) 2013 Advanced Micro Devices, Inc. 563b94509STom Lendacky * 663b94509STom Lendacky * Author: Tom Lendacky <thomas.lendacky@amd.com> 763b94509STom Lendacky * 863b94509STom Lendacky * This program is free software; you can redistribute it and/or modify 963b94509STom Lendacky * it under the terms of the GNU General Public License version 2 as 1063b94509STom Lendacky * published by the Free Software Foundation. 1163b94509STom Lendacky */ 1263b94509STom Lendacky 1363b94509STom Lendacky #ifndef __CPP_H__ 1463b94509STom Lendacky #define __CPP_H__ 1563b94509STom Lendacky 1663b94509STom Lendacky #include <linux/scatterlist.h> 1763b94509STom Lendacky #include <linux/workqueue.h> 1863b94509STom Lendacky #include <linux/list.h> 1963b94509STom Lendacky #include <crypto/aes.h> 2063b94509STom Lendacky #include <crypto/sha.h> 2163b94509STom Lendacky 2263b94509STom Lendacky 2363b94509STom Lendacky struct ccp_device; 2463b94509STom Lendacky struct ccp_cmd; 2563b94509STom Lendacky 26db34cf91STom Lendacky #if defined(CONFIG_CRYPTO_DEV_CCP_DD) || \ 27db34cf91STom Lendacky defined(CONFIG_CRYPTO_DEV_CCP_DD_MODULE) 28db34cf91STom Lendacky 2963b94509STom Lendacky /** 3063b94509STom Lendacky * ccp_enqueue_cmd - queue an operation for processing by the CCP 3163b94509STom Lendacky * 3263b94509STom Lendacky * @cmd: ccp_cmd struct to be processed 3363b94509STom Lendacky * 3463b94509STom Lendacky * Refer to the ccp_cmd struct below for required fields. 3563b94509STom Lendacky * 3663b94509STom Lendacky * Queue a cmd to be processed by the CCP. If queueing the cmd 3763b94509STom Lendacky * would exceed the defined length of the cmd queue the cmd will 3863b94509STom Lendacky * only be queued if the CCP_CMD_MAY_BACKLOG flag is set and will 3963b94509STom Lendacky * result in a return code of -EBUSY. 4063b94509STom Lendacky * 4163b94509STom Lendacky * The callback routine specified in the ccp_cmd struct will be 4263b94509STom Lendacky * called to notify the caller of completion (if the cmd was not 4363b94509STom Lendacky * backlogged) or advancement out of the backlog. If the cmd has 4463b94509STom Lendacky * advanced out of the backlog the "err" value of the callback 4563b94509STom Lendacky * will be -EINPROGRESS. Any other "err" value during callback is 4663b94509STom Lendacky * the result of the operation. 4763b94509STom Lendacky * 4863b94509STom Lendacky * The cmd has been successfully queued if: 4963b94509STom Lendacky * the return code is -EINPROGRESS or 5063b94509STom Lendacky * the return code is -EBUSY and CCP_CMD_MAY_BACKLOG flag is set 5163b94509STom Lendacky */ 5263b94509STom Lendacky int ccp_enqueue_cmd(struct ccp_cmd *cmd); 5363b94509STom Lendacky 54db34cf91STom Lendacky #else /* CONFIG_CRYPTO_DEV_CCP_DD is not enabled */ 55db34cf91STom Lendacky 56db34cf91STom Lendacky static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd) 57db34cf91STom Lendacky { 58db34cf91STom Lendacky return -ENODEV; 59db34cf91STom Lendacky } 60db34cf91STom Lendacky 61db34cf91STom Lendacky #endif /* CONFIG_CRYPTO_DEV_CCP_DD */ 62db34cf91STom Lendacky 6363b94509STom Lendacky 6463b94509STom Lendacky /***** AES engine *****/ 6563b94509STom Lendacky /** 6663b94509STom Lendacky * ccp_aes_type - AES key size 6763b94509STom Lendacky * 6863b94509STom Lendacky * @CCP_AES_TYPE_128: 128-bit key 6963b94509STom Lendacky * @CCP_AES_TYPE_192: 192-bit key 7063b94509STom Lendacky * @CCP_AES_TYPE_256: 256-bit key 7163b94509STom Lendacky */ 7263b94509STom Lendacky enum ccp_aes_type { 7363b94509STom Lendacky CCP_AES_TYPE_128 = 0, 7463b94509STom Lendacky CCP_AES_TYPE_192, 7563b94509STom Lendacky CCP_AES_TYPE_256, 7663b94509STom Lendacky CCP_AES_TYPE__LAST, 7763b94509STom Lendacky }; 7863b94509STom Lendacky 7963b94509STom Lendacky /** 8063b94509STom Lendacky * ccp_aes_mode - AES operation mode 8163b94509STom Lendacky * 8263b94509STom Lendacky * @CCP_AES_MODE_ECB: ECB mode 8363b94509STom Lendacky * @CCP_AES_MODE_CBC: CBC mode 8463b94509STom Lendacky * @CCP_AES_MODE_OFB: OFB mode 8563b94509STom Lendacky * @CCP_AES_MODE_CFB: CFB mode 8663b94509STom Lendacky * @CCP_AES_MODE_CTR: CTR mode 8763b94509STom Lendacky * @CCP_AES_MODE_CMAC: CMAC mode 8863b94509STom Lendacky */ 8963b94509STom Lendacky enum ccp_aes_mode { 9063b94509STom Lendacky CCP_AES_MODE_ECB = 0, 9163b94509STom Lendacky CCP_AES_MODE_CBC, 9263b94509STom Lendacky CCP_AES_MODE_OFB, 9363b94509STom Lendacky CCP_AES_MODE_CFB, 9463b94509STom Lendacky CCP_AES_MODE_CTR, 9563b94509STom Lendacky CCP_AES_MODE_CMAC, 9663b94509STom Lendacky CCP_AES_MODE__LAST, 9763b94509STom Lendacky }; 9863b94509STom Lendacky 9963b94509STom Lendacky /** 10063b94509STom Lendacky * ccp_aes_mode - AES operation mode 10163b94509STom Lendacky * 10263b94509STom Lendacky * @CCP_AES_ACTION_DECRYPT: AES decrypt operation 10363b94509STom Lendacky * @CCP_AES_ACTION_ENCRYPT: AES encrypt operation 10463b94509STom Lendacky */ 10563b94509STom Lendacky enum ccp_aes_action { 10663b94509STom Lendacky CCP_AES_ACTION_DECRYPT = 0, 10763b94509STom Lendacky CCP_AES_ACTION_ENCRYPT, 10863b94509STom Lendacky CCP_AES_ACTION__LAST, 10963b94509STom Lendacky }; 11063b94509STom Lendacky 11163b94509STom Lendacky /** 11263b94509STom Lendacky * struct ccp_aes_engine - CCP AES operation 11363b94509STom Lendacky * @type: AES operation key size 11463b94509STom Lendacky * @mode: AES operation mode 11563b94509STom Lendacky * @action: AES operation (decrypt/encrypt) 11663b94509STom Lendacky * @key: key to be used for this AES operation 11763b94509STom Lendacky * @key_len: length in bytes of key 11863b94509STom Lendacky * @iv: IV to be used for this AES operation 11963b94509STom Lendacky * @iv_len: length in bytes of iv 12063b94509STom Lendacky * @src: data to be used for this operation 12163b94509STom Lendacky * @dst: data produced by this operation 12263b94509STom Lendacky * @src_len: length in bytes of data used for this operation 12363b94509STom Lendacky * @cmac_final: indicates final operation when running in CMAC mode 12463b94509STom Lendacky * @cmac_key: K1/K2 key used in final CMAC operation 12563b94509STom Lendacky * @cmac_key_len: length in bytes of cmac_key 12663b94509STom Lendacky * 12763b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd(): 12863b94509STom Lendacky * - type, mode, action, key, key_len, src, dst, src_len 12963b94509STom Lendacky * - iv, iv_len for any mode other than ECB 13063b94509STom Lendacky * - cmac_final for CMAC mode 13163b94509STom Lendacky * - cmac_key, cmac_key_len for CMAC mode if cmac_final is non-zero 13263b94509STom Lendacky * 13363b94509STom Lendacky * The iv variable is used as both input and output. On completion of the 13463b94509STom Lendacky * AES operation the new IV overwrites the old IV. 13563b94509STom Lendacky */ 13663b94509STom Lendacky struct ccp_aes_engine { 13763b94509STom Lendacky enum ccp_aes_type type; 13863b94509STom Lendacky enum ccp_aes_mode mode; 13963b94509STom Lendacky enum ccp_aes_action action; 14063b94509STom Lendacky 14163b94509STom Lendacky struct scatterlist *key; 14263b94509STom Lendacky u32 key_len; /* In bytes */ 14363b94509STom Lendacky 14463b94509STom Lendacky struct scatterlist *iv; 14563b94509STom Lendacky u32 iv_len; /* In bytes */ 14663b94509STom Lendacky 14763b94509STom Lendacky struct scatterlist *src, *dst; 14881a59f00STom Lendacky u64 src_len; /* In bytes */ 14963b94509STom Lendacky 15063b94509STom Lendacky u32 cmac_final; /* Indicates final cmac cmd */ 15163b94509STom Lendacky struct scatterlist *cmac_key; /* K1/K2 cmac key required for 15263b94509STom Lendacky * final cmac cmd */ 15363b94509STom Lendacky u32 cmac_key_len; /* In bytes */ 15463b94509STom Lendacky }; 15563b94509STom Lendacky 15663b94509STom Lendacky /***** XTS-AES engine *****/ 15763b94509STom Lendacky /** 15863b94509STom Lendacky * ccp_xts_aes_unit_size - XTS unit size 15963b94509STom Lendacky * 16063b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_16: Unit size of 16 bytes 16163b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_512: Unit size of 512 bytes 16263b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_1024: Unit size of 1024 bytes 16363b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_2048: Unit size of 2048 bytes 16463b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_4096: Unit size of 4096 bytes 16563b94509STom Lendacky */ 16663b94509STom Lendacky enum ccp_xts_aes_unit_size { 16763b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_16 = 0, 16863b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_512, 16963b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_1024, 17063b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_2048, 17163b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_4096, 17263b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE__LAST, 17363b94509STom Lendacky }; 17463b94509STom Lendacky 17563b94509STom Lendacky /** 17663b94509STom Lendacky * struct ccp_xts_aes_engine - CCP XTS AES operation 17763b94509STom Lendacky * @action: AES operation (decrypt/encrypt) 17863b94509STom Lendacky * @unit_size: unit size of the XTS operation 17963b94509STom Lendacky * @key: key to be used for this XTS AES operation 18063b94509STom Lendacky * @key_len: length in bytes of key 18163b94509STom Lendacky * @iv: IV to be used for this XTS AES operation 18263b94509STom Lendacky * @iv_len: length in bytes of iv 18363b94509STom Lendacky * @src: data to be used for this operation 18463b94509STom Lendacky * @dst: data produced by this operation 18563b94509STom Lendacky * @src_len: length in bytes of data used for this operation 18663b94509STom Lendacky * @final: indicates final XTS operation 18763b94509STom Lendacky * 18863b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd(): 18963b94509STom Lendacky * - action, unit_size, key, key_len, iv, iv_len, src, dst, src_len, final 19063b94509STom Lendacky * 19163b94509STom Lendacky * The iv variable is used as both input and output. On completion of the 19263b94509STom Lendacky * AES operation the new IV overwrites the old IV. 19363b94509STom Lendacky */ 19463b94509STom Lendacky struct ccp_xts_aes_engine { 19563b94509STom Lendacky enum ccp_aes_action action; 19663b94509STom Lendacky enum ccp_xts_aes_unit_size unit_size; 19763b94509STom Lendacky 19863b94509STom Lendacky struct scatterlist *key; 19963b94509STom Lendacky u32 key_len; /* In bytes */ 20063b94509STom Lendacky 20163b94509STom Lendacky struct scatterlist *iv; 20263b94509STom Lendacky u32 iv_len; /* In bytes */ 20363b94509STom Lendacky 20463b94509STom Lendacky struct scatterlist *src, *dst; 20581a59f00STom Lendacky u64 src_len; /* In bytes */ 20663b94509STom Lendacky 20763b94509STom Lendacky u32 final; 20863b94509STom Lendacky }; 20963b94509STom Lendacky 21063b94509STom Lendacky /***** SHA engine *****/ 21163b94509STom Lendacky #define CCP_SHA_BLOCKSIZE SHA256_BLOCK_SIZE 21263b94509STom Lendacky #define CCP_SHA_CTXSIZE SHA256_DIGEST_SIZE 21363b94509STom Lendacky 21463b94509STom Lendacky /** 21563b94509STom Lendacky * ccp_sha_type - type of SHA operation 21663b94509STom Lendacky * 21763b94509STom Lendacky * @CCP_SHA_TYPE_1: SHA-1 operation 21863b94509STom Lendacky * @CCP_SHA_TYPE_224: SHA-224 operation 21963b94509STom Lendacky * @CCP_SHA_TYPE_256: SHA-256 operation 22063b94509STom Lendacky */ 22163b94509STom Lendacky enum ccp_sha_type { 22263b94509STom Lendacky CCP_SHA_TYPE_1 = 1, 22363b94509STom Lendacky CCP_SHA_TYPE_224, 22463b94509STom Lendacky CCP_SHA_TYPE_256, 22563b94509STom Lendacky CCP_SHA_TYPE__LAST, 22663b94509STom Lendacky }; 22763b94509STom Lendacky 22863b94509STom Lendacky /** 22963b94509STom Lendacky * struct ccp_sha_engine - CCP SHA operation 23063b94509STom Lendacky * @type: Type of SHA operation 23163b94509STom Lendacky * @ctx: current hash value 23263b94509STom Lendacky * @ctx_len: length in bytes of hash value 23363b94509STom Lendacky * @src: data to be used for this operation 23463b94509STom Lendacky * @src_len: length in bytes of data used for this operation 235*c11baa02STom Lendacky * @opad: data to be used for final HMAC operation 236*c11baa02STom Lendacky * @opad_len: length in bytes of data used for final HMAC operation 237*c11baa02STom Lendacky * @first: indicates first SHA operation 23863b94509STom Lendacky * @final: indicates final SHA operation 23963b94509STom Lendacky * @msg_bits: total length of the message in bits used in final SHA operation 24063b94509STom Lendacky * 24163b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd(): 24263b94509STom Lendacky * - type, ctx, ctx_len, src, src_len, final 24363b94509STom Lendacky * - msg_bits if final is non-zero 24463b94509STom Lendacky * 24563b94509STom Lendacky * The ctx variable is used as both input and output. On completion of the 24663b94509STom Lendacky * SHA operation the new hash value overwrites the old hash value. 24763b94509STom Lendacky */ 24863b94509STom Lendacky struct ccp_sha_engine { 24963b94509STom Lendacky enum ccp_sha_type type; 25063b94509STom Lendacky 25163b94509STom Lendacky struct scatterlist *ctx; 25263b94509STom Lendacky u32 ctx_len; /* In bytes */ 25363b94509STom Lendacky 25463b94509STom Lendacky struct scatterlist *src; 25581a59f00STom Lendacky u64 src_len; /* In bytes */ 25663b94509STom Lendacky 257*c11baa02STom Lendacky struct scatterlist *opad; 258*c11baa02STom Lendacky u32 opad_len; /* In bytes */ 259*c11baa02STom Lendacky 260*c11baa02STom Lendacky u32 first; /* Indicates first sha cmd */ 26163b94509STom Lendacky u32 final; /* Indicates final sha cmd */ 26263b94509STom Lendacky u64 msg_bits; /* Message length in bits required for 26363b94509STom Lendacky * final sha cmd */ 26463b94509STom Lendacky }; 26563b94509STom Lendacky 26663b94509STom Lendacky /***** RSA engine *****/ 26763b94509STom Lendacky /** 26863b94509STom Lendacky * struct ccp_rsa_engine - CCP RSA operation 26963b94509STom Lendacky * @key_size: length in bits of RSA key 27063b94509STom Lendacky * @exp: RSA exponent 27163b94509STom Lendacky * @exp_len: length in bytes of exponent 27263b94509STom Lendacky * @mod: RSA modulus 27363b94509STom Lendacky * @mod_len: length in bytes of modulus 27463b94509STom Lendacky * @src: data to be used for this operation 27563b94509STom Lendacky * @dst: data produced by this operation 27663b94509STom Lendacky * @src_len: length in bytes of data used for this operation 27763b94509STom Lendacky * 27863b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd(): 27963b94509STom Lendacky * - key_size, exp, exp_len, mod, mod_len, src, dst, src_len 28063b94509STom Lendacky */ 28163b94509STom Lendacky struct ccp_rsa_engine { 28263b94509STom Lendacky u32 key_size; /* In bits */ 28363b94509STom Lendacky 28463b94509STom Lendacky struct scatterlist *exp; 28563b94509STom Lendacky u32 exp_len; /* In bytes */ 28663b94509STom Lendacky 28763b94509STom Lendacky struct scatterlist *mod; 28863b94509STom Lendacky u32 mod_len; /* In bytes */ 28963b94509STom Lendacky 29063b94509STom Lendacky struct scatterlist *src, *dst; 29163b94509STom Lendacky u32 src_len; /* In bytes */ 29263b94509STom Lendacky }; 29363b94509STom Lendacky 29463b94509STom Lendacky /***** Passthru engine *****/ 29563b94509STom Lendacky /** 29663b94509STom Lendacky * ccp_passthru_bitwise - type of bitwise passthru operation 29763b94509STom Lendacky * 29863b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_NOOP: no bitwise operation performed 29963b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_AND: perform bitwise AND of src with mask 30063b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_OR: perform bitwise OR of src with mask 30163b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_XOR: perform bitwise XOR of src with mask 30263b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_MASK: overwrite with mask 30363b94509STom Lendacky */ 30463b94509STom Lendacky enum ccp_passthru_bitwise { 30563b94509STom Lendacky CCP_PASSTHRU_BITWISE_NOOP = 0, 30663b94509STom Lendacky CCP_PASSTHRU_BITWISE_AND, 30763b94509STom Lendacky CCP_PASSTHRU_BITWISE_OR, 30863b94509STom Lendacky CCP_PASSTHRU_BITWISE_XOR, 30963b94509STom Lendacky CCP_PASSTHRU_BITWISE_MASK, 31063b94509STom Lendacky CCP_PASSTHRU_BITWISE__LAST, 31163b94509STom Lendacky }; 31263b94509STom Lendacky 31363b94509STom Lendacky /** 31463b94509STom Lendacky * ccp_passthru_byteswap - type of byteswap passthru operation 31563b94509STom Lendacky * 31663b94509STom Lendacky * @CCP_PASSTHRU_BYTESWAP_NOOP: no byte swapping performed 31763b94509STom Lendacky * @CCP_PASSTHRU_BYTESWAP_32BIT: swap bytes within 32-bit words 31863b94509STom Lendacky * @CCP_PASSTHRU_BYTESWAP_256BIT: swap bytes within 256-bit words 31963b94509STom Lendacky */ 32063b94509STom Lendacky enum ccp_passthru_byteswap { 32163b94509STom Lendacky CCP_PASSTHRU_BYTESWAP_NOOP = 0, 32263b94509STom Lendacky CCP_PASSTHRU_BYTESWAP_32BIT, 32363b94509STom Lendacky CCP_PASSTHRU_BYTESWAP_256BIT, 32463b94509STom Lendacky CCP_PASSTHRU_BYTESWAP__LAST, 32563b94509STom Lendacky }; 32663b94509STom Lendacky 32763b94509STom Lendacky /** 32863b94509STom Lendacky * struct ccp_passthru_engine - CCP pass-through operation 32963b94509STom Lendacky * @bit_mod: bitwise operation to perform 33063b94509STom Lendacky * @byte_swap: byteswap operation to perform 33163b94509STom Lendacky * @mask: mask to be applied to data 33263b94509STom Lendacky * @mask_len: length in bytes of mask 33363b94509STom Lendacky * @src: data to be used for this operation 33463b94509STom Lendacky * @dst: data produced by this operation 33563b94509STom Lendacky * @src_len: length in bytes of data used for this operation 33663b94509STom Lendacky * @final: indicate final pass-through operation 33763b94509STom Lendacky * 33863b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd(): 33963b94509STom Lendacky * - bit_mod, byte_swap, src, dst, src_len 34063b94509STom Lendacky * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP 34163b94509STom Lendacky */ 34263b94509STom Lendacky struct ccp_passthru_engine { 34363b94509STom Lendacky enum ccp_passthru_bitwise bit_mod; 34463b94509STom Lendacky enum ccp_passthru_byteswap byte_swap; 34563b94509STom Lendacky 34663b94509STom Lendacky struct scatterlist *mask; 34763b94509STom Lendacky u32 mask_len; /* In bytes */ 34863b94509STom Lendacky 34963b94509STom Lendacky struct scatterlist *src, *dst; 35081a59f00STom Lendacky u64 src_len; /* In bytes */ 35163b94509STom Lendacky 35263b94509STom Lendacky u32 final; 35363b94509STom Lendacky }; 35463b94509STom Lendacky 35563b94509STom Lendacky /***** ECC engine *****/ 35663b94509STom Lendacky #define CCP_ECC_MODULUS_BYTES 48 /* 384-bits */ 35763b94509STom Lendacky #define CCP_ECC_MAX_OPERANDS 6 35863b94509STom Lendacky #define CCP_ECC_MAX_OUTPUTS 3 35963b94509STom Lendacky 36063b94509STom Lendacky /** 36163b94509STom Lendacky * ccp_ecc_function - type of ECC function 36263b94509STom Lendacky * 36363b94509STom Lendacky * @CCP_ECC_FUNCTION_MMUL_384BIT: 384-bit modular multiplication 36463b94509STom Lendacky * @CCP_ECC_FUNCTION_MADD_384BIT: 384-bit modular addition 36563b94509STom Lendacky * @CCP_ECC_FUNCTION_MINV_384BIT: 384-bit multiplicative inverse 36663b94509STom Lendacky * @CCP_ECC_FUNCTION_PADD_384BIT: 384-bit point addition 36763b94509STom Lendacky * @CCP_ECC_FUNCTION_PMUL_384BIT: 384-bit point multiplication 36863b94509STom Lendacky * @CCP_ECC_FUNCTION_PDBL_384BIT: 384-bit point doubling 36963b94509STom Lendacky */ 37063b94509STom Lendacky enum ccp_ecc_function { 37163b94509STom Lendacky CCP_ECC_FUNCTION_MMUL_384BIT = 0, 37263b94509STom Lendacky CCP_ECC_FUNCTION_MADD_384BIT, 37363b94509STom Lendacky CCP_ECC_FUNCTION_MINV_384BIT, 37463b94509STom Lendacky CCP_ECC_FUNCTION_PADD_384BIT, 37563b94509STom Lendacky CCP_ECC_FUNCTION_PMUL_384BIT, 37663b94509STom Lendacky CCP_ECC_FUNCTION_PDBL_384BIT, 37763b94509STom Lendacky }; 37863b94509STom Lendacky 37963b94509STom Lendacky /** 38063b94509STom Lendacky * struct ccp_ecc_modular_math - CCP ECC modular math parameters 38163b94509STom Lendacky * @operand_1: first operand for the modular math operation 38263b94509STom Lendacky * @operand_1_len: length of the first operand 38363b94509STom Lendacky * @operand_2: second operand for the modular math operation 38463b94509STom Lendacky * (not used for CCP_ECC_FUNCTION_MINV_384BIT) 38563b94509STom Lendacky * @operand_2_len: length of the second operand 38663b94509STom Lendacky * (not used for CCP_ECC_FUNCTION_MINV_384BIT) 38763b94509STom Lendacky * @result: result of the modular math operation 38863b94509STom Lendacky * @result_len: length of the supplied result buffer 38963b94509STom Lendacky */ 39063b94509STom Lendacky struct ccp_ecc_modular_math { 39163b94509STom Lendacky struct scatterlist *operand_1; 39263b94509STom Lendacky unsigned int operand_1_len; /* In bytes */ 39363b94509STom Lendacky 39463b94509STom Lendacky struct scatterlist *operand_2; 39563b94509STom Lendacky unsigned int operand_2_len; /* In bytes */ 39663b94509STom Lendacky 39763b94509STom Lendacky struct scatterlist *result; 39863b94509STom Lendacky unsigned int result_len; /* In bytes */ 39963b94509STom Lendacky }; 40063b94509STom Lendacky 40163b94509STom Lendacky /** 40263b94509STom Lendacky * struct ccp_ecc_point - CCP ECC point definition 40363b94509STom Lendacky * @x: the x coordinate of the ECC point 40463b94509STom Lendacky * @x_len: the length of the x coordinate 40563b94509STom Lendacky * @y: the y coordinate of the ECC point 40663b94509STom Lendacky * @y_len: the length of the y coordinate 40763b94509STom Lendacky */ 40863b94509STom Lendacky struct ccp_ecc_point { 40963b94509STom Lendacky struct scatterlist *x; 41063b94509STom Lendacky unsigned int x_len; /* In bytes */ 41163b94509STom Lendacky 41263b94509STom Lendacky struct scatterlist *y; 41363b94509STom Lendacky unsigned int y_len; /* In bytes */ 41463b94509STom Lendacky }; 41563b94509STom Lendacky 41663b94509STom Lendacky /** 41763b94509STom Lendacky * struct ccp_ecc_point_math - CCP ECC point math parameters 41863b94509STom Lendacky * @point_1: the first point of the ECC point math operation 41963b94509STom Lendacky * @point_2: the second point of the ECC point math operation 42063b94509STom Lendacky * (only used for CCP_ECC_FUNCTION_PADD_384BIT) 42163b94509STom Lendacky * @domain_a: the a parameter of the ECC curve 42263b94509STom Lendacky * @domain_a_len: the length of the a parameter 42363b94509STom Lendacky * @scalar: the scalar parameter for the point match operation 42463b94509STom Lendacky * (only used for CCP_ECC_FUNCTION_PMUL_384BIT) 42563b94509STom Lendacky * @scalar_len: the length of the scalar parameter 42663b94509STom Lendacky * (only used for CCP_ECC_FUNCTION_PMUL_384BIT) 42763b94509STom Lendacky * @result: the point resulting from the point math operation 42863b94509STom Lendacky */ 42963b94509STom Lendacky struct ccp_ecc_point_math { 43063b94509STom Lendacky struct ccp_ecc_point point_1; 43163b94509STom Lendacky struct ccp_ecc_point point_2; 43263b94509STom Lendacky 43363b94509STom Lendacky struct scatterlist *domain_a; 43463b94509STom Lendacky unsigned int domain_a_len; /* In bytes */ 43563b94509STom Lendacky 43663b94509STom Lendacky struct scatterlist *scalar; 43763b94509STom Lendacky unsigned int scalar_len; /* In bytes */ 43863b94509STom Lendacky 43963b94509STom Lendacky struct ccp_ecc_point result; 44063b94509STom Lendacky }; 44163b94509STom Lendacky 44263b94509STom Lendacky /** 44363b94509STom Lendacky * struct ccp_ecc_engine - CCP ECC operation 44463b94509STom Lendacky * @function: ECC function to perform 44563b94509STom Lendacky * @mod: ECC modulus 44663b94509STom Lendacky * @mod_len: length in bytes of modulus 44763b94509STom Lendacky * @mm: module math parameters 44863b94509STom Lendacky * @pm: point math parameters 44963b94509STom Lendacky * @ecc_result: result of the ECC operation 45063b94509STom Lendacky * 45163b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd(): 45263b94509STom Lendacky * - function, mod, mod_len 45363b94509STom Lendacky * - operand, operand_len, operand_count, output, output_len, output_count 45463b94509STom Lendacky * - ecc_result 45563b94509STom Lendacky */ 45663b94509STom Lendacky struct ccp_ecc_engine { 45763b94509STom Lendacky enum ccp_ecc_function function; 45863b94509STom Lendacky 45963b94509STom Lendacky struct scatterlist *mod; 46063b94509STom Lendacky u32 mod_len; /* In bytes */ 46163b94509STom Lendacky 46263b94509STom Lendacky union { 46363b94509STom Lendacky struct ccp_ecc_modular_math mm; 46463b94509STom Lendacky struct ccp_ecc_point_math pm; 46563b94509STom Lendacky } u; 46663b94509STom Lendacky 46763b94509STom Lendacky u16 ecc_result; 46863b94509STom Lendacky }; 46963b94509STom Lendacky 47063b94509STom Lendacky 47163b94509STom Lendacky /** 47263b94509STom Lendacky * ccp_engine - CCP operation identifiers 47363b94509STom Lendacky * 47463b94509STom Lendacky * @CCP_ENGINE_AES: AES operation 47563b94509STom Lendacky * @CCP_ENGINE_XTS_AES: 128-bit XTS AES operation 47663b94509STom Lendacky * @CCP_ENGINE_RSVD1: unused 47763b94509STom Lendacky * @CCP_ENGINE_SHA: SHA operation 47863b94509STom Lendacky * @CCP_ENGINE_RSA: RSA operation 47963b94509STom Lendacky * @CCP_ENGINE_PASSTHRU: pass-through operation 48063b94509STom Lendacky * @CCP_ENGINE_ZLIB_DECOMPRESS: unused 48163b94509STom Lendacky * @CCP_ENGINE_ECC: ECC operation 48263b94509STom Lendacky */ 48363b94509STom Lendacky enum ccp_engine { 48463b94509STom Lendacky CCP_ENGINE_AES = 0, 48563b94509STom Lendacky CCP_ENGINE_XTS_AES_128, 48663b94509STom Lendacky CCP_ENGINE_RSVD1, 48763b94509STom Lendacky CCP_ENGINE_SHA, 48863b94509STom Lendacky CCP_ENGINE_RSA, 48963b94509STom Lendacky CCP_ENGINE_PASSTHRU, 49063b94509STom Lendacky CCP_ENGINE_ZLIB_DECOMPRESS, 49163b94509STom Lendacky CCP_ENGINE_ECC, 49263b94509STom Lendacky CCP_ENGINE__LAST, 49363b94509STom Lendacky }; 49463b94509STom Lendacky 49563b94509STom Lendacky /* Flag values for flags member of ccp_cmd */ 49663b94509STom Lendacky #define CCP_CMD_MAY_BACKLOG 0x00000001 49763b94509STom Lendacky 49863b94509STom Lendacky /** 49963b94509STom Lendacky * struct ccp_cmd - CPP operation request 50063b94509STom Lendacky * @entry: list element (ccp driver use only) 50163b94509STom Lendacky * @work: work element used for callbacks (ccp driver use only) 50263b94509STom Lendacky * @ccp: CCP device to be run on (ccp driver use only) 50363b94509STom Lendacky * @ret: operation return code (ccp driver use only) 50463b94509STom Lendacky * @flags: cmd processing flags 50563b94509STom Lendacky * @engine: CCP operation to perform 50663b94509STom Lendacky * @engine_error: CCP engine return code 50763b94509STom Lendacky * @u: engine specific structures, refer to specific engine struct below 50863b94509STom Lendacky * @callback: operation completion callback function 50963b94509STom Lendacky * @data: parameter value to be supplied to the callback function 51063b94509STom Lendacky * 51163b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd(): 51263b94509STom Lendacky * - engine, callback 51363b94509STom Lendacky * - See the operation structures below for what is required for each 51463b94509STom Lendacky * operation. 51563b94509STom Lendacky */ 51663b94509STom Lendacky struct ccp_cmd { 51763b94509STom Lendacky /* The list_head, work_struct, ccp and ret variables are for use 51863b94509STom Lendacky * by the CCP driver only. 51963b94509STom Lendacky */ 52063b94509STom Lendacky struct list_head entry; 52163b94509STom Lendacky struct work_struct work; 52263b94509STom Lendacky struct ccp_device *ccp; 52363b94509STom Lendacky int ret; 52463b94509STom Lendacky 52563b94509STom Lendacky u32 flags; 52663b94509STom Lendacky 52763b94509STom Lendacky enum ccp_engine engine; 52863b94509STom Lendacky u32 engine_error; 52963b94509STom Lendacky 53063b94509STom Lendacky union { 53163b94509STom Lendacky struct ccp_aes_engine aes; 53263b94509STom Lendacky struct ccp_xts_aes_engine xts; 53363b94509STom Lendacky struct ccp_sha_engine sha; 53463b94509STom Lendacky struct ccp_rsa_engine rsa; 53563b94509STom Lendacky struct ccp_passthru_engine passthru; 53663b94509STom Lendacky struct ccp_ecc_engine ecc; 53763b94509STom Lendacky } u; 53863b94509STom Lendacky 53963b94509STom Lendacky /* Completion callback support */ 54063b94509STom Lendacky void (*callback)(void *data, int err); 54163b94509STom Lendacky void *data; 54263b94509STom Lendacky }; 54363b94509STom Lendacky 54463b94509STom Lendacky #endif 545