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" 27d0ee7a13SGonglei #include "qom/object.h" 2814c9fd16Szhenwei pi #include "qapi/qapi-types-cryptodev.h" 29d0ee7a13SGonglei 30d0ee7a13SGonglei /** 31d0ee7a13SGonglei * CryptoDevBackend: 32d0ee7a13SGonglei * 33d0ee7a13SGonglei * The CryptoDevBackend object is an interface 34d0ee7a13SGonglei * for different cryptodev backends, which provides crypto 35d0ee7a13SGonglei * operation wrapper. 36d0ee7a13SGonglei * 37d0ee7a13SGonglei */ 38d0ee7a13SGonglei 39d0ee7a13SGonglei #define TYPE_CRYPTODEV_BACKEND "cryptodev-backend" 40d0ee7a13SGonglei 41c821774aSEduardo Habkost OBJECT_DECLARE_TYPE(CryptoDevBackend, CryptoDevBackendClass, 4230b5707cSEduardo Habkost CRYPTODEV_BACKEND) 43d0ee7a13SGonglei 44d0ee7a13SGonglei 45d0ee7a13SGonglei #define MAX_CRYPTO_QUEUE_NUM 64 46d0ee7a13SGonglei 47d0ee7a13SGonglei typedef struct CryptoDevBackendConf CryptoDevBackendConf; 48d0ee7a13SGonglei typedef struct CryptoDevBackendPeers CryptoDevBackendPeers; 49d0ee7a13SGonglei typedef struct CryptoDevBackendClient 50d0ee7a13SGonglei CryptoDevBackendClient; 51d0ee7a13SGonglei 529e4f86a8SGonglei /** 539e4f86a8SGonglei * CryptoDevBackendSymSessionInfo: 549e4f86a8SGonglei * 559e4f86a8SGonglei * @cipher_alg: algorithm type of CIPHER 569e4f86a8SGonglei * @key_len: byte length of cipher key 579e4f86a8SGonglei * @hash_alg: algorithm type of HASH/MAC 589e4f86a8SGonglei * @hash_result_len: byte length of HASH operation result 599e4f86a8SGonglei * @auth_key_len: byte length of authenticated key 609e4f86a8SGonglei * @add_len: byte length of additional authenticated data 619e4f86a8SGonglei * @op_type: operation type (refer to virtio_crypto.h) 629e4f86a8SGonglei * @direction: encryption or direction for CIPHER 639e4f86a8SGonglei * @hash_mode: HASH mode for HASH operation (refer to virtio_crypto.h) 649e4f86a8SGonglei * @alg_chain_order: order of algorithm chaining (CIPHER then HASH, 659e4f86a8SGonglei * or HASH then CIPHER) 669e4f86a8SGonglei * @cipher_key: point to a key of CIPHER 679e4f86a8SGonglei * @auth_key: point to an authenticated key of MAC 689e4f86a8SGonglei * 699e4f86a8SGonglei */ 709e4f86a8SGonglei typedef struct CryptoDevBackendSymSessionInfo { 719e4f86a8SGonglei /* corresponding with virtio crypto spec */ 729e4f86a8SGonglei uint32_t cipher_alg; 739e4f86a8SGonglei uint32_t key_len; 749e4f86a8SGonglei uint32_t hash_alg; 759e4f86a8SGonglei uint32_t hash_result_len; 769e4f86a8SGonglei uint32_t auth_key_len; 779e4f86a8SGonglei uint32_t add_len; 789e4f86a8SGonglei uint8_t op_type; 799e4f86a8SGonglei uint8_t direction; 809e4f86a8SGonglei uint8_t hash_mode; 819e4f86a8SGonglei uint8_t alg_chain_order; 829e4f86a8SGonglei uint8_t *cipher_key; 839e4f86a8SGonglei uint8_t *auth_key; 849e4f86a8SGonglei } CryptoDevBackendSymSessionInfo; 859e4f86a8SGonglei 869e4f86a8SGonglei /** 870e660a6fSzhenwei pi * CryptoDevBackendAsymSessionInfo: 880e660a6fSzhenwei pi */ 890e660a6fSzhenwei pi typedef struct CryptoDevBackendRsaPara { 900e660a6fSzhenwei pi uint32_t padding_algo; 910e660a6fSzhenwei pi uint32_t hash_algo; 920e660a6fSzhenwei pi } CryptoDevBackendRsaPara; 930e660a6fSzhenwei pi 940e660a6fSzhenwei pi typedef struct CryptoDevBackendAsymSessionInfo { 950e660a6fSzhenwei pi /* corresponding with virtio crypto spec */ 960e660a6fSzhenwei pi uint32_t algo; 970e660a6fSzhenwei pi uint32_t keytype; 980e660a6fSzhenwei pi uint32_t keylen; 990e660a6fSzhenwei pi uint8_t *key; 1000e660a6fSzhenwei pi union { 1010e660a6fSzhenwei pi CryptoDevBackendRsaPara rsa; 1020e660a6fSzhenwei pi } u; 1030e660a6fSzhenwei pi } CryptoDevBackendAsymSessionInfo; 1040e660a6fSzhenwei pi 1050e660a6fSzhenwei pi typedef struct CryptoDevBackendSessionInfo { 1060e660a6fSzhenwei pi uint32_t op_code; 1070e660a6fSzhenwei pi union { 1080e660a6fSzhenwei pi CryptoDevBackendSymSessionInfo sym_sess_info; 1090e660a6fSzhenwei pi CryptoDevBackendAsymSessionInfo asym_sess_info; 1100e660a6fSzhenwei pi } u; 1112fda101dSLei He uint64_t session_id; 1120e660a6fSzhenwei pi } CryptoDevBackendSessionInfo; 1130e660a6fSzhenwei pi 1140e660a6fSzhenwei pi /** 1159e4f86a8SGonglei * CryptoDevBackendSymOpInfo: 1169e4f86a8SGonglei * 1179e4f86a8SGonglei * @aad_len: byte length of additional authenticated data 1189e4f86a8SGonglei * @iv_len: byte length of initialization vector or counter 1199e4f86a8SGonglei * @src_len: byte length of source data 1209e4f86a8SGonglei * @dst_len: byte length of destination data 1219e4f86a8SGonglei * @digest_result_len: byte length of hash digest result 1229e4f86a8SGonglei * @hash_start_src_offset: Starting point for hash processing, specified 1239e4f86a8SGonglei * as number of bytes from start of packet in source data, only used for 1249e4f86a8SGonglei * algorithm chain 1259e4f86a8SGonglei * @cipher_start_src_offset: Starting point for cipher processing, specified 1269e4f86a8SGonglei * as number of bytes from start of packet in source data, only used for 1279e4f86a8SGonglei * algorithm chain 1289e4f86a8SGonglei * @len_to_hash: byte length of source data on which the hash 1299e4f86a8SGonglei * operation will be computed, only used for algorithm chain 1309e4f86a8SGonglei * @len_to_cipher: byte length of source data on which the cipher 1319e4f86a8SGonglei * operation will be computed, only used for algorithm chain 1329e4f86a8SGonglei * @op_type: operation type (refer to virtio_crypto.h) 1339e4f86a8SGonglei * @iv: point to the initialization vector or counter 1349e4f86a8SGonglei * @src: point to the source data 1359e4f86a8SGonglei * @dst: point to the destination data 1369e4f86a8SGonglei * @aad_data: point to the additional authenticated data 1379e4f86a8SGonglei * @digest_result: point to the digest result data 1389e4f86a8SGonglei * @data[0]: point to the extensional memory by one memory allocation 1399e4f86a8SGonglei * 1409e4f86a8SGonglei */ 1419e4f86a8SGonglei typedef struct CryptoDevBackendSymOpInfo { 1429e4f86a8SGonglei uint32_t aad_len; 1439e4f86a8SGonglei uint32_t iv_len; 1449e4f86a8SGonglei uint32_t src_len; 1459e4f86a8SGonglei uint32_t dst_len; 1469e4f86a8SGonglei uint32_t digest_result_len; 1479e4f86a8SGonglei uint32_t hash_start_src_offset; 1489e4f86a8SGonglei uint32_t cipher_start_src_offset; 1499e4f86a8SGonglei uint32_t len_to_hash; 1509e4f86a8SGonglei uint32_t len_to_cipher; 1519e4f86a8SGonglei uint8_t op_type; 1529e4f86a8SGonglei uint8_t *iv; 1539e4f86a8SGonglei uint8_t *src; 1549e4f86a8SGonglei uint8_t *dst; 1559e4f86a8SGonglei uint8_t *aad_data; 1569e4f86a8SGonglei uint8_t *digest_result; 157f7795e40SPhilippe Mathieu-Daudé uint8_t data[]; 1589e4f86a8SGonglei } CryptoDevBackendSymOpInfo; 159d0ee7a13SGonglei 1600e660a6fSzhenwei pi 1610e660a6fSzhenwei pi /** 1620e660a6fSzhenwei pi * CryptoDevBackendAsymOpInfo: 1630e660a6fSzhenwei pi * 1640e660a6fSzhenwei pi * @src_len: byte length of source data 1650e660a6fSzhenwei pi * @dst_len: byte length of destination data 1660e660a6fSzhenwei pi * @src: point to the source data 1670e660a6fSzhenwei pi * @dst: point to the destination data 1680e660a6fSzhenwei pi * 1690e660a6fSzhenwei pi */ 1700e660a6fSzhenwei pi typedef struct CryptoDevBackendAsymOpInfo { 1710e660a6fSzhenwei pi uint32_t src_len; 1720e660a6fSzhenwei pi uint32_t dst_len; 1730e660a6fSzhenwei pi uint8_t *src; 1740e660a6fSzhenwei pi uint8_t *dst; 1750e660a6fSzhenwei pi } CryptoDevBackendAsymOpInfo; 1760e660a6fSzhenwei pi 1772cb06927Szhenwei pi typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); 1782cb06927Szhenwei pi 1790e660a6fSzhenwei pi typedef struct CryptoDevBackendOpInfo { 180999c789fSzhenwei pi QCryptodevBackendAlgType algtype; 1810e660a6fSzhenwei pi uint32_t op_code; 1822cb06927Szhenwei pi uint32_t queue_index; 1832cb06927Szhenwei pi CryptoDevCompletionFunc cb; 1842cb06927Szhenwei pi void *opaque; /* argument for cb */ 1850e660a6fSzhenwei pi uint64_t session_id; 1860e660a6fSzhenwei pi union { 1870e660a6fSzhenwei pi CryptoDevBackendSymOpInfo *sym_op_info; 1880e660a6fSzhenwei pi CryptoDevBackendAsymOpInfo *asym_op_info; 1890e660a6fSzhenwei pi } u; 1900e660a6fSzhenwei pi } CryptoDevBackendOpInfo; 1910e660a6fSzhenwei pi 192db1015e9SEduardo Habkost struct CryptoDevBackendClass { 193d0ee7a13SGonglei ObjectClass parent_class; 194d0ee7a13SGonglei 195d0ee7a13SGonglei void (*init)(CryptoDevBackend *backend, Error **errp); 196d0ee7a13SGonglei void (*cleanup)(CryptoDevBackend *backend, Error **errp); 1979e4f86a8SGonglei 1982fda101dSLei He int (*create_session)(CryptoDevBackend *backend, 1990e660a6fSzhenwei pi CryptoDevBackendSessionInfo *sess_info, 2002fda101dSLei He uint32_t queue_index, 2012fda101dSLei He CryptoDevCompletionFunc cb, 2022fda101dSLei He void *opaque); 2032fda101dSLei He 2049e4f86a8SGonglei int (*close_session)(CryptoDevBackend *backend, 2059e4f86a8SGonglei uint64_t session_id, 2062fda101dSLei He uint32_t queue_index, 2072fda101dSLei He CryptoDevCompletionFunc cb, 2082fda101dSLei He void *opaque); 2092fda101dSLei He 2100e660a6fSzhenwei pi int (*do_op)(CryptoDevBackend *backend, 2112cb06927Szhenwei pi CryptoDevBackendOpInfo *op_info); 212db1015e9SEduardo Habkost }; 213d0ee7a13SGonglei 214d0ee7a13SGonglei struct CryptoDevBackendClient { 21514c9fd16Szhenwei pi QCryptodevBackendType type; 216d0ee7a13SGonglei char *info_str; 217d0ee7a13SGonglei unsigned int queue_index; 2185da73dabSGonglei int vring_enable; 219d0ee7a13SGonglei QTAILQ_ENTRY(CryptoDevBackendClient) next; 220d0ee7a13SGonglei }; 221d0ee7a13SGonglei 222d0ee7a13SGonglei struct CryptoDevBackendPeers { 223d0ee7a13SGonglei CryptoDevBackendClient *ccs[MAX_CRYPTO_QUEUE_NUM]; 224d0ee7a13SGonglei uint32_t queues; 225d0ee7a13SGonglei }; 226d0ee7a13SGonglei 227d0ee7a13SGonglei struct CryptoDevBackendConf { 228d0ee7a13SGonglei CryptoDevBackendPeers peers; 229d0ee7a13SGonglei 230d0ee7a13SGonglei /* Supported service mask */ 231d0ee7a13SGonglei uint32_t crypto_services; 232d0ee7a13SGonglei 233d0ee7a13SGonglei /* Detailed algorithms mask */ 234d0ee7a13SGonglei uint32_t cipher_algo_l; 235d0ee7a13SGonglei uint32_t cipher_algo_h; 236d0ee7a13SGonglei uint32_t hash_algo; 237d0ee7a13SGonglei uint32_t mac_algo_l; 238d0ee7a13SGonglei uint32_t mac_algo_h; 239d0ee7a13SGonglei uint32_t aead_algo; 2400e660a6fSzhenwei pi uint32_t akcipher_algo; 241d0ee7a13SGonglei /* Maximum length of cipher key */ 242d0ee7a13SGonglei uint32_t max_cipher_key_len; 243d0ee7a13SGonglei /* Maximum length of authenticated key */ 244d0ee7a13SGonglei uint32_t max_auth_key_len; 245d0ee7a13SGonglei /* Maximum size of each crypto request's content */ 246d0ee7a13SGonglei uint64_t max_size; 247d0ee7a13SGonglei }; 248d0ee7a13SGonglei 249*e7a775fdSzhenwei pi typedef struct CryptodevBackendSymStat { 250*e7a775fdSzhenwei pi int64_t encrypt_ops; 251*e7a775fdSzhenwei pi int64_t decrypt_ops; 252*e7a775fdSzhenwei pi int64_t encrypt_bytes; 253*e7a775fdSzhenwei pi int64_t decrypt_bytes; 254*e7a775fdSzhenwei pi } CryptodevBackendSymStat; 255*e7a775fdSzhenwei pi 256*e7a775fdSzhenwei pi typedef struct CryptodevBackendAsymStat { 257*e7a775fdSzhenwei pi int64_t encrypt_ops; 258*e7a775fdSzhenwei pi int64_t decrypt_ops; 259*e7a775fdSzhenwei pi int64_t sign_ops; 260*e7a775fdSzhenwei pi int64_t verify_ops; 261*e7a775fdSzhenwei pi int64_t encrypt_bytes; 262*e7a775fdSzhenwei pi int64_t decrypt_bytes; 263*e7a775fdSzhenwei pi int64_t sign_bytes; 264*e7a775fdSzhenwei pi int64_t verify_bytes; 265*e7a775fdSzhenwei pi } CryptodevBackendAsymStat; 266*e7a775fdSzhenwei pi 267d0ee7a13SGonglei struct CryptoDevBackend { 268d0ee7a13SGonglei Object parent_obj; 269d0ee7a13SGonglei 270d0ee7a13SGonglei bool ready; 27146fd1705SGonglei /* Tag the cryptodev backend is used by virtio-crypto or not */ 27246fd1705SGonglei bool is_used; 273d0ee7a13SGonglei CryptoDevBackendConf conf; 274*e7a775fdSzhenwei pi CryptodevBackendSymStat *sym_stat; 275*e7a775fdSzhenwei pi CryptodevBackendAsymStat *asym_stat; 276d0ee7a13SGonglei }; 277d0ee7a13SGonglei 278*e7a775fdSzhenwei pi #define CryptodevSymStatInc(be, op, bytes) do { \ 279*e7a775fdSzhenwei pi be->sym_stat->op##_bytes += (bytes); \ 280*e7a775fdSzhenwei pi be->sym_stat->op##_ops += 1; \ 281*e7a775fdSzhenwei pi } while (/*CONSTCOND*/0) 282*e7a775fdSzhenwei pi 283*e7a775fdSzhenwei pi #define CryptodevSymStatIncEncrypt(be, bytes) \ 284*e7a775fdSzhenwei pi CryptodevSymStatInc(be, encrypt, bytes) 285*e7a775fdSzhenwei pi 286*e7a775fdSzhenwei pi #define CryptodevSymStatIncDecrypt(be, bytes) \ 287*e7a775fdSzhenwei pi CryptodevSymStatInc(be, decrypt, bytes) 288*e7a775fdSzhenwei pi 289*e7a775fdSzhenwei pi #define CryptodevAsymStatInc(be, op, bytes) do { \ 290*e7a775fdSzhenwei pi be->asym_stat->op##_bytes += (bytes); \ 291*e7a775fdSzhenwei pi be->asym_stat->op##_ops += 1; \ 292*e7a775fdSzhenwei pi } while (/*CONSTCOND*/0) 293*e7a775fdSzhenwei pi 294*e7a775fdSzhenwei pi #define CryptodevAsymStatIncEncrypt(be, bytes) \ 295*e7a775fdSzhenwei pi CryptodevAsymStatInc(be, encrypt, bytes) 296*e7a775fdSzhenwei pi 297*e7a775fdSzhenwei pi #define CryptodevAsymStatIncDecrypt(be, bytes) \ 298*e7a775fdSzhenwei pi CryptodevAsymStatInc(be, decrypt, bytes) 299*e7a775fdSzhenwei pi 300*e7a775fdSzhenwei pi #define CryptodevAsymStatIncSign(be, bytes) \ 301*e7a775fdSzhenwei pi CryptodevAsymStatInc(be, sign, bytes) 302*e7a775fdSzhenwei pi 303*e7a775fdSzhenwei pi #define CryptodevAsymStatIncVerify(be, bytes) \ 304*e7a775fdSzhenwei pi CryptodevAsymStatInc(be, verify, bytes) 305*e7a775fdSzhenwei pi 306*e7a775fdSzhenwei pi 307d0ee7a13SGonglei /** 308d0ee7a13SGonglei * cryptodev_backend_new_client: 309d0ee7a13SGonglei * 3103f478371Szhenwei pi * Creates a new cryptodev backend client object. 311d0ee7a13SGonglei * 312d0ee7a13SGonglei * The returned object must be released with 313d0ee7a13SGonglei * cryptodev_backend_free_client() when no 314d0ee7a13SGonglei * longer required 315d0ee7a13SGonglei * 316d0ee7a13SGonglei * Returns: a new cryptodev backend client object 317d0ee7a13SGonglei */ 3183f478371Szhenwei pi CryptoDevBackendClient *cryptodev_backend_new_client(void); 3193f478371Szhenwei pi 320d0ee7a13SGonglei /** 321d0ee7a13SGonglei * cryptodev_backend_free_client: 322d0ee7a13SGonglei * @cc: the cryptodev backend client object 323d0ee7a13SGonglei * 324d0ee7a13SGonglei * Release the memory associated with @cc that 325d0ee7a13SGonglei * was previously allocated by cryptodev_backend_new_client() 326d0ee7a13SGonglei */ 327d0ee7a13SGonglei void cryptodev_backend_free_client( 328d0ee7a13SGonglei CryptoDevBackendClient *cc); 329d0ee7a13SGonglei 330d0ee7a13SGonglei /** 331d0ee7a13SGonglei * cryptodev_backend_cleanup: 332d0ee7a13SGonglei * @backend: the cryptodev backend object 333d0ee7a13SGonglei * @errp: pointer to a NULL-initialized error object 334d0ee7a13SGonglei * 335d0ee7a13SGonglei * Clean the resouce associated with @backend that realizaed 336d0ee7a13SGonglei * by the specific backend's init() callback 337d0ee7a13SGonglei */ 338d0ee7a13SGonglei void cryptodev_backend_cleanup( 339d0ee7a13SGonglei CryptoDevBackend *backend, 340d0ee7a13SGonglei Error **errp); 341d0ee7a13SGonglei 3429e4f86a8SGonglei /** 3430e660a6fSzhenwei pi * cryptodev_backend_create_session: 3449e4f86a8SGonglei * @backend: the cryptodev backend object 3459e4f86a8SGonglei * @sess_info: parameters needed by session creating 3469e4f86a8SGonglei * @queue_index: queue index of cryptodev backend client 3479e4f86a8SGonglei * @errp: pointer to a NULL-initialized error object 3482fda101dSLei He * @cb: callback when session create is compeleted 3492fda101dSLei He * @opaque: parameter passed to callback 3509e4f86a8SGonglei * 3512fda101dSLei He * Create a session for symmetric/asymmetric algorithms 3529e4f86a8SGonglei * 3532fda101dSLei He * Returns: 0 for success and cb will be called when creation is completed, 3542fda101dSLei He * negative value for error, and cb will not be called. 3559e4f86a8SGonglei */ 3562fda101dSLei He int cryptodev_backend_create_session( 3579e4f86a8SGonglei CryptoDevBackend *backend, 3580e660a6fSzhenwei pi CryptoDevBackendSessionInfo *sess_info, 3592fda101dSLei He uint32_t queue_index, 3602fda101dSLei He CryptoDevCompletionFunc cb, 3612fda101dSLei He void *opaque); 3629e4f86a8SGonglei 3639e4f86a8SGonglei /** 3640e660a6fSzhenwei pi * cryptodev_backend_close_session: 3659e4f86a8SGonglei * @backend: the cryptodev backend object 3669e4f86a8SGonglei * @session_id: the session id 3679e4f86a8SGonglei * @queue_index: queue index of cryptodev backend client 3689e4f86a8SGonglei * @errp: pointer to a NULL-initialized error object 3692fda101dSLei He * @cb: callback when session create is compeleted 3702fda101dSLei He * @opaque: parameter passed to callback 3719e4f86a8SGonglei * 3720e660a6fSzhenwei pi * Close a session for which was previously 3730e660a6fSzhenwei pi * created by cryptodev_backend_create_session() 3749e4f86a8SGonglei * 3752fda101dSLei He * Returns: 0 for success and cb will be called when creation is completed, 3762fda101dSLei He * negative value for error, and cb will not be called. 3779e4f86a8SGonglei */ 3780e660a6fSzhenwei pi int cryptodev_backend_close_session( 3799e4f86a8SGonglei CryptoDevBackend *backend, 3809e4f86a8SGonglei uint64_t session_id, 3812fda101dSLei He uint32_t queue_index, 3822fda101dSLei He CryptoDevCompletionFunc cb, 3832fda101dSLei He void *opaque); 3849e4f86a8SGonglei 3859e4f86a8SGonglei /** 386d6634ac0SGonglei * cryptodev_backend_crypto_operation: 3879e4f86a8SGonglei * @backend: the cryptodev backend object 3882cb06927Szhenwei pi * @op_info: pointer to a CryptoDevBackendOpInfo object 3899e4f86a8SGonglei * 3902cb06927Szhenwei pi * Do crypto operation, such as encryption, decryption, signature and 3912cb06927Szhenwei pi * verification 3929e4f86a8SGonglei * 3932fda101dSLei He * Returns: 0 for success and cb will be called when creation is completed, 3942fda101dSLei He * negative value for error, and cb will not be called. 3959e4f86a8SGonglei */ 396d6634ac0SGonglei int cryptodev_backend_crypto_operation( 3979e4f86a8SGonglei CryptoDevBackend *backend, 3982cb06927Szhenwei pi CryptoDevBackendOpInfo *op_info); 3999e4f86a8SGonglei 40046fd1705SGonglei /** 40146fd1705SGonglei * cryptodev_backend_set_used: 40246fd1705SGonglei * @backend: the cryptodev backend object 40346fd1705SGonglei * @used: ture or false 40446fd1705SGonglei * 40546fd1705SGonglei * Set the cryptodev backend is used by virtio-crypto or not 40646fd1705SGonglei */ 40746fd1705SGonglei void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used); 40846fd1705SGonglei 40946fd1705SGonglei /** 41046fd1705SGonglei * cryptodev_backend_is_used: 41146fd1705SGonglei * @backend: the cryptodev backend object 41246fd1705SGonglei * 41346fd1705SGonglei * Return the status that the cryptodev backend is used 41446fd1705SGonglei * by virtio-crypto or not 41546fd1705SGonglei * 41646fd1705SGonglei * Returns: true on used, or false on not used 41746fd1705SGonglei */ 41846fd1705SGonglei bool cryptodev_backend_is_used(CryptoDevBackend *backend); 41946fd1705SGonglei 4206138dbdaSGonglei /** 4216138dbdaSGonglei * cryptodev_backend_set_ready: 4226138dbdaSGonglei * @backend: the cryptodev backend object 4236138dbdaSGonglei * @ready: ture or false 4246138dbdaSGonglei * 4256138dbdaSGonglei * Set the cryptodev backend is ready or not, which is called 4266138dbdaSGonglei * by the children of the cryptodev banckend interface. 4276138dbdaSGonglei */ 4286138dbdaSGonglei void cryptodev_backend_set_ready(CryptoDevBackend *backend, bool ready); 4296138dbdaSGonglei 4306138dbdaSGonglei /** 4316138dbdaSGonglei * cryptodev_backend_is_ready: 4326138dbdaSGonglei * @backend: the cryptodev backend object 4336138dbdaSGonglei * 4346138dbdaSGonglei * Return the status that the cryptodev backend is ready or not 4356138dbdaSGonglei * 4366138dbdaSGonglei * Returns: true on ready, or false on not ready 4376138dbdaSGonglei */ 4386138dbdaSGonglei bool cryptodev_backend_is_ready(CryptoDevBackend *backend); 43946fd1705SGonglei 440d0ee7a13SGonglei #endif /* CRYPTODEV_H */ 441