]> git.proxmox.com Git - mirror_qemu.git/blob - include/sysemu/cryptodev.h
cryptodev: introduce cryptodev backend interface
[mirror_qemu.git] / include / sysemu / cryptodev.h
1 /*
2 * QEMU Crypto Device Implementation
3 *
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5 *
6 * Authors:
7 * Gonglei <arei.gonglei@huawei.com>
8 *
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.
13 *
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.
18 *
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/>.
21 *
22 */
23 #ifndef CRYPTODEV_H
24 #define CRYPTODEV_H
25
26 #include "qom/object.h"
27 #include "qemu-common.h"
28
29 /**
30 * CryptoDevBackend:
31 *
32 * The CryptoDevBackend object is an interface
33 * for different cryptodev backends, which provides crypto
34 * operation wrapper.
35 *
36 */
37
38 #define TYPE_CRYPTODEV_BACKEND "cryptodev-backend"
39
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)
49
50
51 #define MAX_CRYPTO_QUEUE_NUM 64
52
53 typedef struct CryptoDevBackendConf CryptoDevBackendConf;
54 typedef struct CryptoDevBackendPeers CryptoDevBackendPeers;
55 typedef struct CryptoDevBackendClient
56 CryptoDevBackendClient;
57 typedef struct CryptoDevBackend CryptoDevBackend;
58
59
60 typedef struct CryptoDevBackendClass {
61 ObjectClass parent_class;
62
63 void (*init)(CryptoDevBackend *backend, Error **errp);
64 void (*cleanup)(CryptoDevBackend *backend, Error **errp);
65 } CryptoDevBackendClass;
66
67
68 struct CryptoDevBackendClient {
69 char *model;
70 char *name;
71 char *info_str;
72 unsigned int queue_index;
73 QTAILQ_ENTRY(CryptoDevBackendClient) next;
74 };
75
76 struct CryptoDevBackendPeers {
77 CryptoDevBackendClient *ccs[MAX_CRYPTO_QUEUE_NUM];
78 uint32_t queues;
79 };
80
81 struct CryptoDevBackendConf {
82 CryptoDevBackendPeers peers;
83
84 /* Supported service mask */
85 uint32_t crypto_services;
86
87 /* Detailed algorithms mask */
88 uint32_t cipher_algo_l;
89 uint32_t cipher_algo_h;
90 uint32_t hash_algo;
91 uint32_t mac_algo_l;
92 uint32_t mac_algo_h;
93 uint32_t aead_algo;
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 */
99 uint64_t max_size;
100 };
101
102 struct CryptoDevBackend {
103 Object parent_obj;
104
105 bool ready;
106 CryptoDevBackendConf conf;
107 };
108
109 /**
110 * cryptodev_backend_new_client:
111 * @model: the cryptodev backend model
112 * @name: the cryptodev backend name, can be NULL
113 *
114 * Creates a new cryptodev backend client object
115 * with the @name in the model @model.
116 *
117 * The returned object must be released with
118 * cryptodev_backend_free_client() when no
119 * longer required
120 *
121 * Returns: a new cryptodev backend client object
122 */
123 CryptoDevBackendClient *
124 cryptodev_backend_new_client(const char *model,
125 const char *name);
126 /**
127 * cryptodev_backend_free_client:
128 * @cc: the cryptodev backend client object
129 *
130 * Release the memory associated with @cc that
131 * was previously allocated by cryptodev_backend_new_client()
132 */
133 void cryptodev_backend_free_client(
134 CryptoDevBackendClient *cc);
135
136 /**
137 * cryptodev_backend_cleanup:
138 * @backend: the cryptodev backend object
139 * @errp: pointer to a NULL-initialized error object
140 *
141 * Clean the resouce associated with @backend that realizaed
142 * by the specific backend's init() callback
143 */
144 void cryptodev_backend_cleanup(
145 CryptoDevBackend *backend,
146 Error **errp);
147
148 #endif /* CRYPTODEV_H */