1d0ee7a13SGonglei /* 2d0ee7a13SGonglei * QEMU Crypto Device Implementation 3d0ee7a13SGonglei * 4d0ee7a13SGonglei * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. 5d0ee7a13SGonglei * 6d0ee7a13SGonglei * Authors: 7d0ee7a13SGonglei * Gonglei <arei.gonglei@huawei.com> 8d0ee7a13SGonglei * 9d0ee7a13SGonglei * This library is free software; you can redistribute it and/or 10d0ee7a13SGonglei * modify it under the terms of the GNU Lesser General Public 11d0ee7a13SGonglei * License as published by the Free Software Foundation; either 120dda001bSChetan Pant * version 2.1 of the License, or (at your option) any later version. 13d0ee7a13SGonglei * 14d0ee7a13SGonglei * This library is distributed in the hope that it will be useful, 15d0ee7a13SGonglei * but WITHOUT ANY WARRANTY; without even the implied warranty of 16d0ee7a13SGonglei * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17d0ee7a13SGonglei * Lesser General Public License for more details. 18d0ee7a13SGonglei * 19d0ee7a13SGonglei * You should have received a copy of the GNU Lesser General Public 20d0ee7a13SGonglei * License along with this library; if not, see <http://www.gnu.org/licenses/>. 21d0ee7a13SGonglei * 22d0ee7a13SGonglei */ 23d0ee7a13SGonglei #ifndef CRYPTODEV_H 24d0ee7a13SGonglei #define CRYPTODEV_H 25d0ee7a13SGonglei 26dc5e9ac7SMarkus Armbruster #include "qemu/queue.h" 272580b452Szhenwei pi #include "qemu/throttle.h" 28d0ee7a13SGonglei #include "qom/object.h" 2914c9fd16Szhenwei pi #include "qapi/qapi-types-cryptodev.h" 30d0ee7a13SGonglei 31d0ee7a13SGonglei /** 32d0ee7a13SGonglei * CryptoDevBackend: 33d0ee7a13SGonglei * 34d0ee7a13SGonglei * The CryptoDevBackend object is an interface 35d0ee7a13SGonglei * for different cryptodev backends, which provides crypto 36d0ee7a13SGonglei * operation wrapper. 37d0ee7a13SGonglei * 38d0ee7a13SGonglei */ 39d0ee7a13SGonglei 40d0ee7a13SGonglei #define TYPE_CRYPTODEV_BACKEND "cryptodev-backend" 41d0ee7a13SGonglei 42c821774aSEduardo Habkost OBJECT_DECLARE_TYPE(CryptoDevBackend, CryptoDevBackendClass, 4330b5707cSEduardo Habkost CRYPTODEV_BACKEND) 44d0ee7a13SGonglei 45d0ee7a13SGonglei 46d0ee7a13SGonglei #define MAX_CRYPTO_QUEUE_NUM 64 47d0ee7a13SGonglei 48d0ee7a13SGonglei typedef struct CryptoDevBackendConf CryptoDevBackendConf; 49d0ee7a13SGonglei typedef struct CryptoDevBackendPeers CryptoDevBackendPeers; 50d0ee7a13SGonglei typedef struct CryptoDevBackendClient 51d0ee7a13SGonglei CryptoDevBackendClient; 52d0ee7a13SGonglei 539e4f86a8SGonglei /** 549e4f86a8SGonglei * CryptoDevBackendSymSessionInfo: 559e4f86a8SGonglei * 569e4f86a8SGonglei * @cipher_alg: algorithm type of CIPHER 579e4f86a8SGonglei * @key_len: byte length of cipher key 589e4f86a8SGonglei * @hash_alg: algorithm type of HASH/MAC 599e4f86a8SGonglei * @hash_result_len: byte length of HASH operation result 609e4f86a8SGonglei * @auth_key_len: byte length of authenticated key 619e4f86a8SGonglei * @add_len: byte length of additional authenticated data 629e4f86a8SGonglei * @op_type: operation type (refer to virtio_crypto.h) 639e4f86a8SGonglei * @direction: encryption or direction for CIPHER 649e4f86a8SGonglei * @hash_mode: HASH mode for HASH operation (refer to virtio_crypto.h) 659e4f86a8SGonglei * @alg_chain_order: order of algorithm chaining (CIPHER then HASH, 669e4f86a8SGonglei * or HASH then CIPHER) 679e4f86a8SGonglei * @cipher_key: point to a key of CIPHER 689e4f86a8SGonglei * @auth_key: point to an authenticated key of MAC 699e4f86a8SGonglei * 709e4f86a8SGonglei */ 719e4f86a8SGonglei typedef struct CryptoDevBackendSymSessionInfo { 729e4f86a8SGonglei /* corresponding with virtio crypto spec */ 739e4f86a8SGonglei uint32_t cipher_alg; 749e4f86a8SGonglei uint32_t key_len; 759e4f86a8SGonglei uint32_t hash_alg; 769e4f86a8SGonglei uint32_t hash_result_len; 779e4f86a8SGonglei uint32_t auth_key_len; 789e4f86a8SGonglei uint32_t add_len; 799e4f86a8SGonglei uint8_t op_type; 809e4f86a8SGonglei uint8_t direction; 819e4f86a8SGonglei uint8_t hash_mode; 829e4f86a8SGonglei uint8_t alg_chain_order; 839e4f86a8SGonglei uint8_t *cipher_key; 849e4f86a8SGonglei uint8_t *auth_key; 859e4f86a8SGonglei } CryptoDevBackendSymSessionInfo; 869e4f86a8SGonglei 879e4f86a8SGonglei /** 880e660a6fSzhenwei pi * CryptoDevBackendAsymSessionInfo: 890e660a6fSzhenwei pi */ 900e660a6fSzhenwei pi typedef struct CryptoDevBackendRsaPara { 910e660a6fSzhenwei pi uint32_t padding_algo; 920e660a6fSzhenwei pi uint32_t hash_algo; 930e660a6fSzhenwei pi } CryptoDevBackendRsaPara; 940e660a6fSzhenwei pi 950e660a6fSzhenwei pi typedef struct CryptoDevBackendAsymSessionInfo { 960e660a6fSzhenwei pi /* corresponding with virtio crypto spec */ 970e660a6fSzhenwei pi uint32_t algo; 980e660a6fSzhenwei pi uint32_t keytype; 990e660a6fSzhenwei pi uint32_t keylen; 1000e660a6fSzhenwei pi uint8_t *key; 1010e660a6fSzhenwei pi union { 1020e660a6fSzhenwei pi CryptoDevBackendRsaPara rsa; 1030e660a6fSzhenwei pi } u; 1040e660a6fSzhenwei pi } CryptoDevBackendAsymSessionInfo; 1050e660a6fSzhenwei pi 1060e660a6fSzhenwei pi typedef struct CryptoDevBackendSessionInfo { 1070e660a6fSzhenwei pi uint32_t op_code; 1080e660a6fSzhenwei pi union { 1090e660a6fSzhenwei pi CryptoDevBackendSymSessionInfo sym_sess_info; 1100e660a6fSzhenwei pi CryptoDevBackendAsymSessionInfo asym_sess_info; 1110e660a6fSzhenwei pi } u; 1122fda101dSLei He uint64_t session_id; 1130e660a6fSzhenwei pi } CryptoDevBackendSessionInfo; 1140e660a6fSzhenwei pi 1150e660a6fSzhenwei pi /** 1169e4f86a8SGonglei * CryptoDevBackendSymOpInfo: 1179e4f86a8SGonglei * 1189e4f86a8SGonglei * @aad_len: byte length of additional authenticated data 1199e4f86a8SGonglei * @iv_len: byte length of initialization vector or counter 1209e4f86a8SGonglei * @src_len: byte length of source data 1219e4f86a8SGonglei * @dst_len: byte length of destination data 1229e4f86a8SGonglei * @digest_result_len: byte length of hash digest result 1239e4f86a8SGonglei * @hash_start_src_offset: Starting point for hash processing, specified 1249e4f86a8SGonglei * as number of bytes from start of packet in source data, only used for 1259e4f86a8SGonglei * algorithm chain 1269e4f86a8SGonglei * @cipher_start_src_offset: Starting point for cipher processing, specified 1279e4f86a8SGonglei * as number of bytes from start of packet in source data, only used for 1289e4f86a8SGonglei * algorithm chain 1299e4f86a8SGonglei * @len_to_hash: byte length of source data on which the hash 1309e4f86a8SGonglei * operation will be computed, only used for algorithm chain 1319e4f86a8SGonglei * @len_to_cipher: byte length of source data on which the cipher 1329e4f86a8SGonglei * operation will be computed, only used for algorithm chain 1339e4f86a8SGonglei * @op_type: operation type (refer to virtio_crypto.h) 1349e4f86a8SGonglei * @iv: point to the initialization vector or counter 1359e4f86a8SGonglei * @src: point to the source data 1369e4f86a8SGonglei * @dst: point to the destination data 1379e4f86a8SGonglei * @aad_data: point to the additional authenticated data 1389e4f86a8SGonglei * @digest_result: point to the digest result data 1399e4f86a8SGonglei * @data[0]: point to the extensional memory by one memory allocation 1409e4f86a8SGonglei * 1419e4f86a8SGonglei */ 1429e4f86a8SGonglei typedef struct CryptoDevBackendSymOpInfo { 1439e4f86a8SGonglei uint32_t aad_len; 1449e4f86a8SGonglei uint32_t iv_len; 1459e4f86a8SGonglei uint32_t src_len; 1469e4f86a8SGonglei uint32_t dst_len; 1479e4f86a8SGonglei uint32_t digest_result_len; 1489e4f86a8SGonglei uint32_t hash_start_src_offset; 1499e4f86a8SGonglei uint32_t cipher_start_src_offset; 1509e4f86a8SGonglei uint32_t len_to_hash; 1519e4f86a8SGonglei uint32_t len_to_cipher; 1529e4f86a8SGonglei uint8_t op_type; 1539e4f86a8SGonglei uint8_t *iv; 1549e4f86a8SGonglei uint8_t *src; 1559e4f86a8SGonglei uint8_t *dst; 1569e4f86a8SGonglei uint8_t *aad_data; 1579e4f86a8SGonglei uint8_t *digest_result; 158f7795e40SPhilippe Mathieu-Daudé uint8_t data[]; 1599e4f86a8SGonglei } CryptoDevBackendSymOpInfo; 160d0ee7a13SGonglei 1610e660a6fSzhenwei pi 1620e660a6fSzhenwei pi /** 1630e660a6fSzhenwei pi * CryptoDevBackendAsymOpInfo: 1640e660a6fSzhenwei pi * 1650e660a6fSzhenwei pi * @src_len: byte length of source data 1660e660a6fSzhenwei pi * @dst_len: byte length of destination data 1670e660a6fSzhenwei pi * @src: point to the source data 1680e660a6fSzhenwei pi * @dst: point to the destination data 1690e660a6fSzhenwei pi * 1700e660a6fSzhenwei pi */ 1710e660a6fSzhenwei pi typedef struct CryptoDevBackendAsymOpInfo { 1720e660a6fSzhenwei pi uint32_t src_len; 1730e660a6fSzhenwei pi uint32_t dst_len; 1740e660a6fSzhenwei pi uint8_t *src; 1750e660a6fSzhenwei pi uint8_t *dst; 1760e660a6fSzhenwei pi } CryptoDevBackendAsymOpInfo; 1770e660a6fSzhenwei pi 1782cb06927Szhenwei pi typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); 1792cb06927Szhenwei pi 1800e660a6fSzhenwei pi typedef struct CryptoDevBackendOpInfo { 181*b1019999SMarkus Armbruster QCryptodevBackendAlgoType algtype; 1820e660a6fSzhenwei pi uint32_t op_code; 1832cb06927Szhenwei pi uint32_t queue_index; 1842cb06927Szhenwei pi CryptoDevCompletionFunc cb; 1852cb06927Szhenwei pi void *opaque; /* argument for cb */ 1860e660a6fSzhenwei pi uint64_t session_id; 1870e660a6fSzhenwei pi union { 1880e660a6fSzhenwei pi CryptoDevBackendSymOpInfo *sym_op_info; 1890e660a6fSzhenwei pi CryptoDevBackendAsymOpInfo *asym_op_info; 1900e660a6fSzhenwei pi } u; 1912580b452Szhenwei pi QTAILQ_ENTRY(CryptoDevBackendOpInfo) next; 1920e660a6fSzhenwei pi } CryptoDevBackendOpInfo; 1930e660a6fSzhenwei pi 194db1015e9SEduardo Habkost struct CryptoDevBackendClass { 195d0ee7a13SGonglei ObjectClass parent_class; 196d0ee7a13SGonglei 197d0ee7a13SGonglei void (*init)(CryptoDevBackend *backend, Error **errp); 198d0ee7a13SGonglei void (*cleanup)(CryptoDevBackend *backend, Error **errp); 1999e4f86a8SGonglei 2002fda101dSLei He int (*create_session)(CryptoDevBackend *backend, 2010e660a6fSzhenwei pi CryptoDevBackendSessionInfo *sess_info, 2022fda101dSLei He uint32_t queue_index, 2032fda101dSLei He CryptoDevCompletionFunc cb, 2042fda101dSLei He void *opaque); 2052fda101dSLei He 2069e4f86a8SGonglei int (*close_session)(CryptoDevBackend *backend, 2079e4f86a8SGonglei uint64_t session_id, 2082fda101dSLei He uint32_t queue_index, 2092fda101dSLei He CryptoDevCompletionFunc cb, 2102fda101dSLei He void *opaque); 2112fda101dSLei He 2120e660a6fSzhenwei pi int (*do_op)(CryptoDevBackend *backend, 2132cb06927Szhenwei pi CryptoDevBackendOpInfo *op_info); 214db1015e9SEduardo Habkost }; 215d0ee7a13SGonglei 216d0ee7a13SGonglei struct CryptoDevBackendClient { 21714c9fd16Szhenwei pi QCryptodevBackendType type; 218d0ee7a13SGonglei char *info_str; 219d0ee7a13SGonglei unsigned int queue_index; 2205da73dabSGonglei int vring_enable; 221d0ee7a13SGonglei QTAILQ_ENTRY(CryptoDevBackendClient) next; 222d0ee7a13SGonglei }; 223d0ee7a13SGonglei 224d0ee7a13SGonglei struct CryptoDevBackendPeers { 225d0ee7a13SGonglei CryptoDevBackendClient *ccs[MAX_CRYPTO_QUEUE_NUM]; 226d0ee7a13SGonglei uint32_t queues; 227d0ee7a13SGonglei }; 228d0ee7a13SGonglei 229d0ee7a13SGonglei struct CryptoDevBackendConf { 230d0ee7a13SGonglei CryptoDevBackendPeers peers; 231d0ee7a13SGonglei 232d0ee7a13SGonglei /* Supported service mask */ 233d0ee7a13SGonglei uint32_t crypto_services; 234d0ee7a13SGonglei 235d0ee7a13SGonglei /* Detailed algorithms mask */ 236d0ee7a13SGonglei uint32_t cipher_algo_l; 237d0ee7a13SGonglei uint32_t cipher_algo_h; 238d0ee7a13SGonglei uint32_t hash_algo; 239d0ee7a13SGonglei uint32_t mac_algo_l; 240d0ee7a13SGonglei uint32_t mac_algo_h; 241d0ee7a13SGonglei uint32_t aead_algo; 2420e660a6fSzhenwei pi uint32_t akcipher_algo; 243d0ee7a13SGonglei /* Maximum length of cipher key */ 244d0ee7a13SGonglei uint32_t max_cipher_key_len; 245d0ee7a13SGonglei /* Maximum length of authenticated key */ 246d0ee7a13SGonglei uint32_t max_auth_key_len; 247d0ee7a13SGonglei /* Maximum size of each crypto request's content */ 248d0ee7a13SGonglei uint64_t max_size; 249d0ee7a13SGonglei }; 250d0ee7a13SGonglei 251e7a775fdSzhenwei pi typedef struct CryptodevBackendSymStat { 252e7a775fdSzhenwei pi int64_t encrypt_ops; 253e7a775fdSzhenwei pi int64_t decrypt_ops; 254e7a775fdSzhenwei pi int64_t encrypt_bytes; 255e7a775fdSzhenwei pi int64_t decrypt_bytes; 256e7a775fdSzhenwei pi } CryptodevBackendSymStat; 257e7a775fdSzhenwei pi 258e7a775fdSzhenwei pi typedef struct CryptodevBackendAsymStat { 259e7a775fdSzhenwei pi int64_t encrypt_ops; 260e7a775fdSzhenwei pi int64_t decrypt_ops; 261e7a775fdSzhenwei pi int64_t sign_ops; 262e7a775fdSzhenwei pi int64_t verify_ops; 263e7a775fdSzhenwei pi int64_t encrypt_bytes; 264e7a775fdSzhenwei pi int64_t decrypt_bytes; 265e7a775fdSzhenwei pi int64_t sign_bytes; 266e7a775fdSzhenwei pi int64_t verify_bytes; 267e7a775fdSzhenwei pi } CryptodevBackendAsymStat; 268e7a775fdSzhenwei pi 269d0ee7a13SGonglei struct CryptoDevBackend { 270d0ee7a13SGonglei Object parent_obj; 271d0ee7a13SGonglei 272d0ee7a13SGonglei bool ready; 27346fd1705SGonglei /* Tag the cryptodev backend is used by virtio-crypto or not */ 27446fd1705SGonglei bool is_used; 275d0ee7a13SGonglei CryptoDevBackendConf conf; 276e7a775fdSzhenwei pi CryptodevBackendSymStat *sym_stat; 277e7a775fdSzhenwei pi CryptodevBackendAsymStat *asym_stat; 2782580b452Szhenwei pi 2792580b452Szhenwei pi ThrottleState ts; 2802580b452Szhenwei pi ThrottleTimers tt; 2812580b452Szhenwei pi ThrottleConfig tc; 2822580b452Szhenwei pi QTAILQ_HEAD(, CryptoDevBackendOpInfo) opinfos; 283d0ee7a13SGonglei }; 284d0ee7a13SGonglei 285e7a775fdSzhenwei pi #define CryptodevSymStatInc(be, op, bytes) do { \ 286e7a775fdSzhenwei pi be->sym_stat->op##_bytes += (bytes); \ 287e7a775fdSzhenwei pi be->sym_stat->op##_ops += 1; \ 288e7a775fdSzhenwei pi } while (/*CONSTCOND*/0) 289e7a775fdSzhenwei pi 290e7a775fdSzhenwei pi #define CryptodevSymStatIncEncrypt(be, bytes) \ 291e7a775fdSzhenwei pi CryptodevSymStatInc(be, encrypt, bytes) 292e7a775fdSzhenwei pi 293e7a775fdSzhenwei pi #define CryptodevSymStatIncDecrypt(be, bytes) \ 294e7a775fdSzhenwei pi CryptodevSymStatInc(be, decrypt, bytes) 295e7a775fdSzhenwei pi 296e7a775fdSzhenwei pi #define CryptodevAsymStatInc(be, op, bytes) do { \ 297e7a775fdSzhenwei pi be->asym_stat->op##_bytes += (bytes); \ 298e7a775fdSzhenwei pi be->asym_stat->op##_ops += 1; \ 299e7a775fdSzhenwei pi } while (/*CONSTCOND*/0) 300e7a775fdSzhenwei pi 301e7a775fdSzhenwei pi #define CryptodevAsymStatIncEncrypt(be, bytes) \ 302e7a775fdSzhenwei pi CryptodevAsymStatInc(be, encrypt, bytes) 303e7a775fdSzhenwei pi 304e7a775fdSzhenwei pi #define CryptodevAsymStatIncDecrypt(be, bytes) \ 305e7a775fdSzhenwei pi CryptodevAsymStatInc(be, decrypt, bytes) 306e7a775fdSzhenwei pi 307e7a775fdSzhenwei pi #define CryptodevAsymStatIncSign(be, bytes) \ 308e7a775fdSzhenwei pi CryptodevAsymStatInc(be, sign, bytes) 309e7a775fdSzhenwei pi 310e7a775fdSzhenwei pi #define CryptodevAsymStatIncVerify(be, bytes) \ 311e7a775fdSzhenwei pi CryptodevAsymStatInc(be, verify, bytes) 312e7a775fdSzhenwei pi 313e7a775fdSzhenwei pi 314d0ee7a13SGonglei /** 315d0ee7a13SGonglei * cryptodev_backend_new_client: 316d0ee7a13SGonglei * 3173f478371Szhenwei pi * Creates a new cryptodev backend client object. 318d0ee7a13SGonglei * 319d0ee7a13SGonglei * The returned object must be released with 320d0ee7a13SGonglei * cryptodev_backend_free_client() when no 321d0ee7a13SGonglei * longer required 322d0ee7a13SGonglei * 323d0ee7a13SGonglei * Returns: a new cryptodev backend client object 324d0ee7a13SGonglei */ 3253f478371Szhenwei pi CryptoDevBackendClient *cryptodev_backend_new_client(void); 3263f478371Szhenwei pi 327d0ee7a13SGonglei /** 328d0ee7a13SGonglei * cryptodev_backend_free_client: 329d0ee7a13SGonglei * @cc: the cryptodev backend client object 330d0ee7a13SGonglei * 331d0ee7a13SGonglei * Release the memory associated with @cc that 332d0ee7a13SGonglei * was previously allocated by cryptodev_backend_new_client() 333d0ee7a13SGonglei */ 334d0ee7a13SGonglei void cryptodev_backend_free_client( 335d0ee7a13SGonglei CryptoDevBackendClient *cc); 336d0ee7a13SGonglei 337d0ee7a13SGonglei /** 338d0ee7a13SGonglei * cryptodev_backend_cleanup: 339d0ee7a13SGonglei * @backend: the cryptodev backend object 340d0ee7a13SGonglei * @errp: pointer to a NULL-initialized error object 341d0ee7a13SGonglei * 342a1a62cedSMichael Tokarev * Clean the resource associated with @backend that realizaed 343d0ee7a13SGonglei * by the specific backend's init() callback 344d0ee7a13SGonglei */ 345d0ee7a13SGonglei void cryptodev_backend_cleanup( 346d0ee7a13SGonglei CryptoDevBackend *backend, 347d0ee7a13SGonglei Error **errp); 348d0ee7a13SGonglei 3499e4f86a8SGonglei /** 3500e660a6fSzhenwei pi * cryptodev_backend_create_session: 3519e4f86a8SGonglei * @backend: the cryptodev backend object 3529e4f86a8SGonglei * @sess_info: parameters needed by session creating 3539e4f86a8SGonglei * @queue_index: queue index of cryptodev backend client 3549e4f86a8SGonglei * @errp: pointer to a NULL-initialized error object 3552fda101dSLei He * @cb: callback when session create is compeleted 3562fda101dSLei He * @opaque: parameter passed to callback 3579e4f86a8SGonglei * 3582fda101dSLei He * Create a session for symmetric/asymmetric algorithms 3599e4f86a8SGonglei * 3602fda101dSLei He * Returns: 0 for success and cb will be called when creation is completed, 3612fda101dSLei He * negative value for error, and cb will not be called. 3629e4f86a8SGonglei */ 3632fda101dSLei He int cryptodev_backend_create_session( 3649e4f86a8SGonglei CryptoDevBackend *backend, 3650e660a6fSzhenwei pi CryptoDevBackendSessionInfo *sess_info, 3662fda101dSLei He uint32_t queue_index, 3672fda101dSLei He CryptoDevCompletionFunc cb, 3682fda101dSLei He void *opaque); 3699e4f86a8SGonglei 3709e4f86a8SGonglei /** 3710e660a6fSzhenwei pi * cryptodev_backend_close_session: 3729e4f86a8SGonglei * @backend: the cryptodev backend object 3739e4f86a8SGonglei * @session_id: the session id 3749e4f86a8SGonglei * @queue_index: queue index of cryptodev backend client 3759e4f86a8SGonglei * @errp: pointer to a NULL-initialized error object 3762fda101dSLei He * @cb: callback when session create is compeleted 3772fda101dSLei He * @opaque: parameter passed to callback 3789e4f86a8SGonglei * 3790e660a6fSzhenwei pi * Close a session for which was previously 3800e660a6fSzhenwei pi * created by cryptodev_backend_create_session() 3819e4f86a8SGonglei * 3822fda101dSLei He * Returns: 0 for success and cb will be called when creation is completed, 3832fda101dSLei He * negative value for error, and cb will not be called. 3849e4f86a8SGonglei */ 3850e660a6fSzhenwei pi int cryptodev_backend_close_session( 3869e4f86a8SGonglei CryptoDevBackend *backend, 3879e4f86a8SGonglei uint64_t session_id, 3882fda101dSLei He uint32_t queue_index, 3892fda101dSLei He CryptoDevCompletionFunc cb, 3902fda101dSLei He void *opaque); 3919e4f86a8SGonglei 3929e4f86a8SGonglei /** 393d6634ac0SGonglei * cryptodev_backend_crypto_operation: 3949e4f86a8SGonglei * @backend: the cryptodev backend object 3952cb06927Szhenwei pi * @op_info: pointer to a CryptoDevBackendOpInfo object 3969e4f86a8SGonglei * 3972cb06927Szhenwei pi * Do crypto operation, such as encryption, decryption, signature and 3982cb06927Szhenwei pi * verification 3999e4f86a8SGonglei * 4002fda101dSLei He * Returns: 0 for success and cb will be called when creation is completed, 4012fda101dSLei He * negative value for error, and cb will not be called. 4029e4f86a8SGonglei */ 403d6634ac0SGonglei int cryptodev_backend_crypto_operation( 4049e4f86a8SGonglei CryptoDevBackend *backend, 4052cb06927Szhenwei pi CryptoDevBackendOpInfo *op_info); 4069e4f86a8SGonglei 40746fd1705SGonglei /** 40846fd1705SGonglei * cryptodev_backend_set_used: 40946fd1705SGonglei * @backend: the cryptodev backend object 410a1a62cedSMichael Tokarev * @used: true or false 41146fd1705SGonglei * 41246fd1705SGonglei * Set the cryptodev backend is used by virtio-crypto or not 41346fd1705SGonglei */ 41446fd1705SGonglei void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used); 41546fd1705SGonglei 41646fd1705SGonglei /** 41746fd1705SGonglei * cryptodev_backend_is_used: 41846fd1705SGonglei * @backend: the cryptodev backend object 41946fd1705SGonglei * 42046fd1705SGonglei * Return the status that the cryptodev backend is used 42146fd1705SGonglei * by virtio-crypto or not 42246fd1705SGonglei * 42346fd1705SGonglei * Returns: true on used, or false on not used 42446fd1705SGonglei */ 42546fd1705SGonglei bool cryptodev_backend_is_used(CryptoDevBackend *backend); 42646fd1705SGonglei 4276138dbdaSGonglei /** 4286138dbdaSGonglei * cryptodev_backend_set_ready: 4296138dbdaSGonglei * @backend: the cryptodev backend object 430a1a62cedSMichael Tokarev * @ready: true or false 4316138dbdaSGonglei * 4326138dbdaSGonglei * Set the cryptodev backend is ready or not, which is called 4336138dbdaSGonglei * by the children of the cryptodev banckend interface. 4346138dbdaSGonglei */ 4356138dbdaSGonglei void cryptodev_backend_set_ready(CryptoDevBackend *backend, bool ready); 4366138dbdaSGonglei 4376138dbdaSGonglei /** 4386138dbdaSGonglei * cryptodev_backend_is_ready: 4396138dbdaSGonglei * @backend: the cryptodev backend object 4406138dbdaSGonglei * 4416138dbdaSGonglei * Return the status that the cryptodev backend is ready or not 4426138dbdaSGonglei * 4436138dbdaSGonglei * Returns: true on ready, or false on not ready 4446138dbdaSGonglei */ 4456138dbdaSGonglei bool cryptodev_backend_is_ready(CryptoDevBackend *backend); 44646fd1705SGonglei 447d0ee7a13SGonglei #endif /* CRYPTODEV_H */ 448