xref: /openbmc/qemu/include/sysemu/cryptodev.h (revision d0ee7a135fe499dd900bdca4d70efc2beaa6ef9c)
1*d0ee7a13SGonglei /*
2*d0ee7a13SGonglei  * QEMU Crypto Device Implementation
3*d0ee7a13SGonglei  *
4*d0ee7a13SGonglei  * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
5*d0ee7a13SGonglei  *
6*d0ee7a13SGonglei  * Authors:
7*d0ee7a13SGonglei  *    Gonglei <arei.gonglei@huawei.com>
8*d0ee7a13SGonglei  *
9*d0ee7a13SGonglei  * This library is free software; you can redistribute it and/or
10*d0ee7a13SGonglei  * modify it under the terms of the GNU Lesser General Public
11*d0ee7a13SGonglei  * License as published by the Free Software Foundation; either
12*d0ee7a13SGonglei  * version 2 of the License, or (at your option) any later version.
13*d0ee7a13SGonglei  *
14*d0ee7a13SGonglei  * This library is distributed in the hope that it will be useful,
15*d0ee7a13SGonglei  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*d0ee7a13SGonglei  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17*d0ee7a13SGonglei  * Lesser General Public License for more details.
18*d0ee7a13SGonglei  *
19*d0ee7a13SGonglei  * You should have received a copy of the GNU Lesser General Public
20*d0ee7a13SGonglei  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21*d0ee7a13SGonglei  *
22*d0ee7a13SGonglei  */
23*d0ee7a13SGonglei #ifndef CRYPTODEV_H
24*d0ee7a13SGonglei #define CRYPTODEV_H
25*d0ee7a13SGonglei 
26*d0ee7a13SGonglei #include "qom/object.h"
27*d0ee7a13SGonglei #include "qemu-common.h"
28*d0ee7a13SGonglei 
29*d0ee7a13SGonglei /**
30*d0ee7a13SGonglei  * CryptoDevBackend:
31*d0ee7a13SGonglei  *
32*d0ee7a13SGonglei  * The CryptoDevBackend object is an interface
33*d0ee7a13SGonglei  * for different cryptodev backends, which provides crypto
34*d0ee7a13SGonglei  * operation wrapper.
35*d0ee7a13SGonglei  *
36*d0ee7a13SGonglei  */
37*d0ee7a13SGonglei 
38*d0ee7a13SGonglei #define TYPE_CRYPTODEV_BACKEND "cryptodev-backend"
39*d0ee7a13SGonglei 
40*d0ee7a13SGonglei #define CRYPTODEV_BACKEND(obj) \
41*d0ee7a13SGonglei     OBJECT_CHECK(CryptoDevBackend, \
42*d0ee7a13SGonglei                  (obj), TYPE_CRYPTODEV_BACKEND)
43*d0ee7a13SGonglei #define CRYPTODEV_BACKEND_GET_CLASS(obj) \
44*d0ee7a13SGonglei     OBJECT_GET_CLASS(CryptoDevBackendClass, \
45*d0ee7a13SGonglei                  (obj), TYPE_CRYPTODEV_BACKEND)
46*d0ee7a13SGonglei #define CRYPTODEV_BACKEND_CLASS(klass) \
47*d0ee7a13SGonglei     OBJECT_CLASS_CHECK(CryptoDevBackendClass, \
48*d0ee7a13SGonglei                 (klass), TYPE_CRYPTODEV_BACKEND)
49*d0ee7a13SGonglei 
50*d0ee7a13SGonglei 
51*d0ee7a13SGonglei #define MAX_CRYPTO_QUEUE_NUM  64
52*d0ee7a13SGonglei 
53*d0ee7a13SGonglei typedef struct CryptoDevBackendConf CryptoDevBackendConf;
54*d0ee7a13SGonglei typedef struct CryptoDevBackendPeers CryptoDevBackendPeers;
55*d0ee7a13SGonglei typedef struct CryptoDevBackendClient
56*d0ee7a13SGonglei                      CryptoDevBackendClient;
57*d0ee7a13SGonglei typedef struct CryptoDevBackend CryptoDevBackend;
58*d0ee7a13SGonglei 
59*d0ee7a13SGonglei 
60*d0ee7a13SGonglei typedef struct CryptoDevBackendClass {
61*d0ee7a13SGonglei     ObjectClass parent_class;
62*d0ee7a13SGonglei 
63*d0ee7a13SGonglei     void (*init)(CryptoDevBackend *backend, Error **errp);
64*d0ee7a13SGonglei     void (*cleanup)(CryptoDevBackend *backend, Error **errp);
65*d0ee7a13SGonglei } CryptoDevBackendClass;
66*d0ee7a13SGonglei 
67*d0ee7a13SGonglei 
68*d0ee7a13SGonglei struct CryptoDevBackendClient {
69*d0ee7a13SGonglei     char *model;
70*d0ee7a13SGonglei     char *name;
71*d0ee7a13SGonglei     char *info_str;
72*d0ee7a13SGonglei     unsigned int queue_index;
73*d0ee7a13SGonglei     QTAILQ_ENTRY(CryptoDevBackendClient) next;
74*d0ee7a13SGonglei };
75*d0ee7a13SGonglei 
76*d0ee7a13SGonglei struct CryptoDevBackendPeers {
77*d0ee7a13SGonglei     CryptoDevBackendClient *ccs[MAX_CRYPTO_QUEUE_NUM];
78*d0ee7a13SGonglei     uint32_t queues;
79*d0ee7a13SGonglei };
80*d0ee7a13SGonglei 
81*d0ee7a13SGonglei struct CryptoDevBackendConf {
82*d0ee7a13SGonglei     CryptoDevBackendPeers peers;
83*d0ee7a13SGonglei 
84*d0ee7a13SGonglei     /* Supported service mask */
85*d0ee7a13SGonglei     uint32_t crypto_services;
86*d0ee7a13SGonglei 
87*d0ee7a13SGonglei     /* Detailed algorithms mask */
88*d0ee7a13SGonglei     uint32_t cipher_algo_l;
89*d0ee7a13SGonglei     uint32_t cipher_algo_h;
90*d0ee7a13SGonglei     uint32_t hash_algo;
91*d0ee7a13SGonglei     uint32_t mac_algo_l;
92*d0ee7a13SGonglei     uint32_t mac_algo_h;
93*d0ee7a13SGonglei     uint32_t aead_algo;
94*d0ee7a13SGonglei     /* Maximum length of cipher key */
95*d0ee7a13SGonglei     uint32_t max_cipher_key_len;
96*d0ee7a13SGonglei     /* Maximum length of authenticated key */
97*d0ee7a13SGonglei     uint32_t max_auth_key_len;
98*d0ee7a13SGonglei     /* Maximum size of each crypto request's content */
99*d0ee7a13SGonglei     uint64_t max_size;
100*d0ee7a13SGonglei };
101*d0ee7a13SGonglei 
102*d0ee7a13SGonglei struct CryptoDevBackend {
103*d0ee7a13SGonglei     Object parent_obj;
104*d0ee7a13SGonglei 
105*d0ee7a13SGonglei     bool ready;
106*d0ee7a13SGonglei     CryptoDevBackendConf conf;
107*d0ee7a13SGonglei };
108*d0ee7a13SGonglei 
109*d0ee7a13SGonglei /**
110*d0ee7a13SGonglei  * cryptodev_backend_new_client:
111*d0ee7a13SGonglei  * @model: the cryptodev backend model
112*d0ee7a13SGonglei  * @name: the cryptodev backend name, can be NULL
113*d0ee7a13SGonglei  *
114*d0ee7a13SGonglei  * Creates a new cryptodev backend client object
115*d0ee7a13SGonglei  * with the @name in the model @model.
116*d0ee7a13SGonglei  *
117*d0ee7a13SGonglei  * The returned object must be released with
118*d0ee7a13SGonglei  * cryptodev_backend_free_client() when no
119*d0ee7a13SGonglei  * longer required
120*d0ee7a13SGonglei  *
121*d0ee7a13SGonglei  * Returns: a new cryptodev backend client object
122*d0ee7a13SGonglei  */
123*d0ee7a13SGonglei CryptoDevBackendClient *
124*d0ee7a13SGonglei cryptodev_backend_new_client(const char *model,
125*d0ee7a13SGonglei                                     const char *name);
126*d0ee7a13SGonglei /**
127*d0ee7a13SGonglei  * cryptodev_backend_free_client:
128*d0ee7a13SGonglei  * @cc: the cryptodev backend client object
129*d0ee7a13SGonglei  *
130*d0ee7a13SGonglei  * Release the memory associated with @cc that
131*d0ee7a13SGonglei  * was previously allocated by cryptodev_backend_new_client()
132*d0ee7a13SGonglei  */
133*d0ee7a13SGonglei void cryptodev_backend_free_client(
134*d0ee7a13SGonglei                   CryptoDevBackendClient *cc);
135*d0ee7a13SGonglei 
136*d0ee7a13SGonglei /**
137*d0ee7a13SGonglei  * cryptodev_backend_cleanup:
138*d0ee7a13SGonglei  * @backend: the cryptodev backend object
139*d0ee7a13SGonglei  * @errp: pointer to a NULL-initialized error object
140*d0ee7a13SGonglei  *
141*d0ee7a13SGonglei  * Clean the resouce associated with @backend that realizaed
142*d0ee7a13SGonglei  * by the specific backend's init() callback
143*d0ee7a13SGonglei  */
144*d0ee7a13SGonglei void cryptodev_backend_cleanup(
145*d0ee7a13SGonglei            CryptoDevBackend *backend,
146*d0ee7a13SGonglei            Error **errp);
147*d0ee7a13SGonglei 
148*d0ee7a13SGonglei #endif /* CRYPTODEV_H */
149