2 * QEMU Crypto Device Implementation
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
7 * Gonglei <arei.gonglei@huawei.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include "qom/object.h"
27 #include "qemu-common.h"
32 * The CryptoDevBackend object is an interface
33 * for different cryptodev backends, which provides crypto
38 #define TYPE_CRYPTODEV_BACKEND "cryptodev-backend"
40 #define CRYPTODEV_BACKEND(obj) \
41 OBJECT_CHECK(CryptoDevBackend, \
42 (obj), TYPE_CRYPTODEV_BACKEND)
43 #define CRYPTODEV_BACKEND_GET_CLASS(obj) \
44 OBJECT_GET_CLASS(CryptoDevBackendClass, \
45 (obj), TYPE_CRYPTODEV_BACKEND)
46 #define CRYPTODEV_BACKEND_CLASS(klass) \
47 OBJECT_CLASS_CHECK(CryptoDevBackendClass, \
48 (klass), TYPE_CRYPTODEV_BACKEND)
51 #define MAX_CRYPTO_QUEUE_NUM 64
53 typedef struct CryptoDevBackendConf CryptoDevBackendConf
;
54 typedef struct CryptoDevBackendPeers CryptoDevBackendPeers
;
55 typedef struct CryptoDevBackendClient
56 CryptoDevBackendClient
;
57 typedef struct CryptoDevBackend CryptoDevBackend
;
60 typedef struct CryptoDevBackendClass
{
61 ObjectClass parent_class
;
63 void (*init
)(CryptoDevBackend
*backend
, Error
**errp
);
64 void (*cleanup
)(CryptoDevBackend
*backend
, Error
**errp
);
65 } CryptoDevBackendClass
;
68 struct CryptoDevBackendClient
{
72 unsigned int queue_index
;
73 QTAILQ_ENTRY(CryptoDevBackendClient
) next
;
76 struct CryptoDevBackendPeers
{
77 CryptoDevBackendClient
*ccs
[MAX_CRYPTO_QUEUE_NUM
];
81 struct CryptoDevBackendConf
{
82 CryptoDevBackendPeers peers
;
84 /* Supported service mask */
85 uint32_t crypto_services
;
87 /* Detailed algorithms mask */
88 uint32_t cipher_algo_l
;
89 uint32_t cipher_algo_h
;
94 /* Maximum length of cipher key */
95 uint32_t max_cipher_key_len
;
96 /* Maximum length of authenticated key */
97 uint32_t max_auth_key_len
;
98 /* Maximum size of each crypto request's content */
102 struct CryptoDevBackend
{
106 CryptoDevBackendConf conf
;
110 * cryptodev_backend_new_client:
111 * @model: the cryptodev backend model
112 * @name: the cryptodev backend name, can be NULL
114 * Creates a new cryptodev backend client object
115 * with the @name in the model @model.
117 * The returned object must be released with
118 * cryptodev_backend_free_client() when no
121 * Returns: a new cryptodev backend client object
123 CryptoDevBackendClient
*
124 cryptodev_backend_new_client(const char *model
,
127 * cryptodev_backend_free_client:
128 * @cc: the cryptodev backend client object
130 * Release the memory associated with @cc that
131 * was previously allocated by cryptodev_backend_new_client()
133 void cryptodev_backend_free_client(
134 CryptoDevBackendClient
*cc
);
137 * cryptodev_backend_cleanup:
138 * @backend: the cryptodev backend object
139 * @errp: pointer to a NULL-initialized error object
141 * Clean the resouce associated with @backend that realizaed
142 * by the specific backend's init() callback
144 void cryptodev_backend_cleanup(
145 CryptoDevBackend
*backend
,
148 #endif /* CRYPTODEV_H */