cryptodev: Introduce cryptodev alg type in QAPI

Introduce cryptodev alg type in cryptodev.json, then apply this to
related codes, and drop 'enum CryptoDevBackendAlgType'.

There are two options:
1, { 'enum': 'QCryptodevBackendAlgType',
  'prefix': 'CRYPTODEV_BACKEND_ALG',
  'data': ['sym', 'asym']}
Then we can keep 'CRYPTODEV_BACKEND_ALG_SYM' and avoid lots of
changes.
2, changes in this patch(with prefix 'QCRYPTODEV_BACKEND_ALG').

To avoid breaking the rule of QAPI, use 2 here.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Message-Id: <20230301105847.253084-4-pizhenwei@bytedance.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
master
zhenwei pi 2023-03-01 18:58:38 +08:00 committed by Michael S. Tsirkin
parent 3f478371fd
commit 999c789f00
6 changed files with 30 additions and 22 deletions

View File

@ -537,7 +537,7 @@ static int cryptodev_builtin_operation(
CryptoDevBackendBuiltinSession *sess; CryptoDevBackendBuiltinSession *sess;
CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendSymOpInfo *sym_op_info;
CryptoDevBackendAsymOpInfo *asym_op_info; CryptoDevBackendAsymOpInfo *asym_op_info;
enum CryptoDevBackendAlgType algtype = op_info->algtype; QCryptodevBackendAlgType algtype = op_info->algtype;
int status = -VIRTIO_CRYPTO_ERR; int status = -VIRTIO_CRYPTO_ERR;
Error *local_error = NULL; Error *local_error = NULL;
@ -549,11 +549,11 @@ static int cryptodev_builtin_operation(
} }
sess = builtin->sessions[op_info->session_id]; sess = builtin->sessions[op_info->session_id];
if (algtype == CRYPTODEV_BACKEND_ALG_SYM) { if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) {
sym_op_info = op_info->u.sym_op_info; sym_op_info = op_info->u.sym_op_info;
status = cryptodev_builtin_sym_operation(sess, sym_op_info, status = cryptodev_builtin_sym_operation(sess, sym_op_info,
&local_error); &local_error);
} else if (algtype == CRYPTODEV_BACKEND_ALG_ASYM) { } else if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) {
asym_op_info = op_info->u.asym_op_info; asym_op_info = op_info->u.asym_op_info;
status = cryptodev_builtin_asym_operation(sess, op_info->op_code, status = cryptodev_builtin_asym_operation(sess, op_info->op_code,
asym_op_info, &local_error); asym_op_info, &local_error);

View File

@ -477,7 +477,7 @@ static int cryptodev_lkcf_operation(
CryptoDevBackendLKCF *lkcf = CryptoDevBackendLKCF *lkcf =
CRYPTODEV_BACKEND_LKCF(backend); CRYPTODEV_BACKEND_LKCF(backend);
CryptoDevBackendLKCFSession *sess; CryptoDevBackendLKCFSession *sess;
enum CryptoDevBackendAlgType algtype = op_info->algtype; QCryptodevBackendAlgType algtype = op_info->algtype;
CryptoDevLKCFTask *task; CryptoDevLKCFTask *task;
if (op_info->session_id >= MAX_SESSIONS || if (op_info->session_id >= MAX_SESSIONS ||
@ -488,7 +488,7 @@ static int cryptodev_lkcf_operation(
} }
sess = lkcf->sess[op_info->session_id]; sess = lkcf->sess[op_info->session_id];
if (algtype != CRYPTODEV_BACKEND_ALG_ASYM) { if (algtype != QCRYPTODEV_BACKEND_ALG_ASYM) {
error_report("algtype not supported: %u", algtype); error_report("algtype not supported: %u", algtype);
return -VIRTIO_CRYPTO_NOTSUPP; return -VIRTIO_CRYPTO_NOTSUPP;
} }

View File

@ -120,10 +120,10 @@ int cryptodev_backend_crypto_operation(
{ {
VirtIOCryptoReq *req = opaque1; VirtIOCryptoReq *req = opaque1;
CryptoDevBackendOpInfo *op_info = &req->op_info; CryptoDevBackendOpInfo *op_info = &req->op_info;
enum CryptoDevBackendAlgType algtype = req->flags; QCryptodevBackendAlgType algtype = req->flags;
if ((algtype != CRYPTODEV_BACKEND_ALG_SYM) if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM)
&& (algtype != CRYPTODEV_BACKEND_ALG_ASYM)) { && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) {
error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype);
return -VIRTIO_CRYPTO_NOTSUPP; return -VIRTIO_CRYPTO_NOTSUPP;
} }

View File

@ -462,7 +462,7 @@ static void virtio_crypto_init_request(VirtIOCrypto *vcrypto, VirtQueue *vq,
req->in_iov = NULL; req->in_iov = NULL;
req->in_num = 0; req->in_num = 0;
req->in_len = 0; req->in_len = 0;
req->flags = CRYPTODEV_BACKEND_ALG__MAX; req->flags = QCRYPTODEV_BACKEND_ALG__MAX;
memset(&req->op_info, 0x00, sizeof(req->op_info)); memset(&req->op_info, 0x00, sizeof(req->op_info));
} }
@ -472,7 +472,7 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req)
return; return;
} }
if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { if (req->flags == QCRYPTODEV_BACKEND_ALG_SYM) {
size_t max_len; size_t max_len;
CryptoDevBackendSymOpInfo *op_info = req->op_info.u.sym_op_info; CryptoDevBackendSymOpInfo *op_info = req->op_info.u.sym_op_info;
@ -485,7 +485,7 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req)
/* Zeroize and free request data structure */ /* Zeroize and free request data structure */
memset(op_info, 0, sizeof(*op_info) + max_len); memset(op_info, 0, sizeof(*op_info) + max_len);
g_free(op_info); g_free(op_info);
} else if (req->flags == CRYPTODEV_BACKEND_ALG_ASYM) { } else if (req->flags == QCRYPTODEV_BACKEND_ALG_ASYM) {
CryptoDevBackendAsymOpInfo *op_info = req->op_info.u.asym_op_info; CryptoDevBackendAsymOpInfo *op_info = req->op_info.u.asym_op_info;
if (op_info) { if (op_info) {
g_free(op_info->src); g_free(op_info->src);
@ -570,10 +570,10 @@ static void virtio_crypto_req_complete(void *opaque, int ret)
VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto);
uint8_t status = -ret; uint8_t status = -ret;
if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { if (req->flags == QCRYPTODEV_BACKEND_ALG_SYM) {
virtio_crypto_sym_input_data_helper(vdev, req, status, virtio_crypto_sym_input_data_helper(vdev, req, status,
req->op_info.u.sym_op_info); req->op_info.u.sym_op_info);
} else if (req->flags == CRYPTODEV_BACKEND_ALG_ASYM) { } else if (req->flags == QCRYPTODEV_BACKEND_ALG_ASYM) {
virtio_crypto_akcipher_input_data_helper(vdev, req, status, virtio_crypto_akcipher_input_data_helper(vdev, req, status,
req->op_info.u.asym_op_info); req->op_info.u.asym_op_info);
} }
@ -875,7 +875,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request)
switch (opcode) { switch (opcode) {
case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_ENCRYPT:
case VIRTIO_CRYPTO_CIPHER_DECRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT:
op_info->algtype = request->flags = CRYPTODEV_BACKEND_ALG_SYM; op_info->algtype = request->flags = QCRYPTODEV_BACKEND_ALG_SYM;
ret = virtio_crypto_handle_sym_req(vcrypto, ret = virtio_crypto_handle_sym_req(vcrypto,
&req.u.sym_req, op_info, &req.u.sym_req, op_info,
out_iov, out_num); out_iov, out_num);
@ -885,7 +885,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request)
case VIRTIO_CRYPTO_AKCIPHER_DECRYPT: case VIRTIO_CRYPTO_AKCIPHER_DECRYPT:
case VIRTIO_CRYPTO_AKCIPHER_SIGN: case VIRTIO_CRYPTO_AKCIPHER_SIGN:
case VIRTIO_CRYPTO_AKCIPHER_VERIFY: case VIRTIO_CRYPTO_AKCIPHER_VERIFY:
op_info->algtype = request->flags = CRYPTODEV_BACKEND_ALG_ASYM; op_info->algtype = request->flags = QCRYPTODEV_BACKEND_ALG_ASYM;
ret = virtio_crypto_handle_asym_req(vcrypto, ret = virtio_crypto_handle_asym_req(vcrypto,
&req.u.akcipher_req, op_info, &req.u.akcipher_req, op_info,
out_iov, out_num); out_iov, out_num);

View File

@ -49,12 +49,6 @@ typedef struct CryptoDevBackendPeers CryptoDevBackendPeers;
typedef struct CryptoDevBackendClient typedef struct CryptoDevBackendClient
CryptoDevBackendClient; CryptoDevBackendClient;
enum CryptoDevBackendAlgType {
CRYPTODEV_BACKEND_ALG_SYM,
CRYPTODEV_BACKEND_ALG_ASYM,
CRYPTODEV_BACKEND_ALG__MAX,
};
/** /**
* CryptoDevBackendSymSessionInfo: * CryptoDevBackendSymSessionInfo:
* *
@ -181,7 +175,7 @@ typedef struct CryptoDevBackendAsymOpInfo {
} CryptoDevBackendAsymOpInfo; } CryptoDevBackendAsymOpInfo;
typedef struct CryptoDevBackendOpInfo { typedef struct CryptoDevBackendOpInfo {
enum CryptoDevBackendAlgType algtype; QCryptodevBackendAlgType algtype;
uint32_t op_code; uint32_t op_code;
uint64_t session_id; uint64_t session_id;
union { union {

View File

@ -4,6 +4,20 @@
# This work is licensed under the terms of the GNU GPL, version 2 or later. # This work is licensed under the terms of the GNU GPL, version 2 or later.
# See the COPYING file in the top-level directory. # See the COPYING file in the top-level directory.
##
# @QCryptodevBackendAlgType:
#
# The supported algorithm types of a crypto device.
#
# @sym: symmetric encryption
# @asym: asymmetric Encryption
#
# Since: 8.0
##
{ 'enum': 'QCryptodevBackendAlgType',
'prefix': 'QCRYPTODEV_BACKEND_ALG',
'data': ['sym', 'asym']}
## ##
# @QCryptodevBackendType: # @QCryptodevBackendType:
# #