From: "Longpeng(Mike)" <longpeng2@huawei.com>
To: arei.gonglei@huawei.com, pasic@linux.vnet.ibm.com
Cc: weidong.huang@huawei.com, wangxinxin.wang@huawei.com,
jianjay.zhou@huawei.com, qemu-devel@nongnu.org,
"Longpeng(Mike)" <longpeng2@huawei.com>
Subject: [Qemu-devel] [RFC 08/10] cryptodev: extract one util function
Date: Mon, 6 Nov 2017 14:57:00 +0800 [thread overview]
Message-ID: <1509951422-20060-9-git-send-email-longpeng2@huawei.com> (raw)
In-Reply-To: <1509951422-20060-1-git-send-email-longpeng2@huawei.com>
From: Gonglei <arei.gonglei@huawei.com>
So that the new function can be used by both seesion creation
and the following stateless crypto operation.
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com>
---
backends/cryptodev-builtin.c | 100 +++++++++++++++++++++++++------------------
1 file changed, 58 insertions(+), 42 deletions(-)
diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c
index 6df23b9..ba6d15c 100644
--- a/backends/cryptodev-builtin.c
+++ b/backends/cryptodev-builtin.c
@@ -152,73 +152,56 @@ err:
return -1;
}
-static int cryptodev_builtin_create_cipher_session(
- CryptoDevBackendBuiltin *builtin,
+static int
+cryptodev_builtin_get_cipher_alg_mode(
CryptoDevBackendSymSessionInfo *sess_info,
+ int *algo, int *mode,
Error **errp)
{
- int algo;
- int mode;
- QCryptoCipher *cipher;
- int index;
- CryptoDevBackendBuiltinSession *sess;
-
- if (sess_info->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) {
- error_setg(errp, "Unsupported optype :%u", sess_info->op_type);
- return -1;
- }
-
- index = cryptodev_builtin_get_unused_session_index(builtin);
- if (index < 0) {
- error_setg(errp, "Total number of sessions created exceeds %u",
- MAX_NUM_SESSIONS);
- return -1;
- }
-
switch (sess_info->cipher_alg) {
case VIRTIO_CRYPTO_CIPHER_AES_ECB:
- mode = QCRYPTO_CIPHER_MODE_ECB;
- algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
- mode, errp);
- if (algo < 0) {
+ *mode = QCRYPTO_CIPHER_MODE_ECB;
+ *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
+ *mode, errp);
+ if (*algo < 0) {
return -1;
}
break;
case VIRTIO_CRYPTO_CIPHER_AES_CBC:
- mode = QCRYPTO_CIPHER_MODE_CBC;
- algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
- mode, errp);
- if (algo < 0) {
+ *mode = QCRYPTO_CIPHER_MODE_CBC;
+ *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
+ *mode, errp);
+ if (*algo < 0) {
return -1;
}
break;
case VIRTIO_CRYPTO_CIPHER_AES_CTR:
- mode = QCRYPTO_CIPHER_MODE_CTR;
- algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
- mode, errp);
- if (algo < 0) {
+ *mode = QCRYPTO_CIPHER_MODE_CTR;
+ *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
+ *mode, errp);
+ if (*algo < 0) {
return -1;
}
break;
case VIRTIO_CRYPTO_CIPHER_AES_XTS:
- mode = QCRYPTO_CIPHER_MODE_XTS;
- algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
- mode, errp);
- if (algo < 0) {
+ *mode = QCRYPTO_CIPHER_MODE_XTS;
+ *algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,
+ *mode, errp);
+ if (*algo < 0) {
return -1;
}
break;
case VIRTIO_CRYPTO_CIPHER_3DES_ECB:
- mode = QCRYPTO_CIPHER_MODE_ECB;
- algo = QCRYPTO_CIPHER_ALG_3DES;
+ *mode = QCRYPTO_CIPHER_MODE_ECB;
+ *algo = QCRYPTO_CIPHER_ALG_3DES;
break;
case VIRTIO_CRYPTO_CIPHER_3DES_CBC:
- mode = QCRYPTO_CIPHER_MODE_CBC;
- algo = QCRYPTO_CIPHER_ALG_3DES;
+ *mode = QCRYPTO_CIPHER_MODE_CBC;
+ *algo = QCRYPTO_CIPHER_ALG_3DES;
break;
case VIRTIO_CRYPTO_CIPHER_3DES_CTR:
- mode = QCRYPTO_CIPHER_MODE_CTR;
- algo = QCRYPTO_CIPHER_ALG_3DES;
+ *mode = QCRYPTO_CIPHER_MODE_CTR;
+ *algo = QCRYPTO_CIPHER_ALG_3DES;
break;
default:
error_setg(errp, "Unsupported cipher alg :%u",
@@ -226,6 +209,39 @@ static int cryptodev_builtin_create_cipher_session(
return -1;
}
+ return 0;
+}
+
+static int cryptodev_builtin_create_cipher_session(
+ CryptoDevBackendBuiltin *builtin,
+ CryptoDevBackendSymSessionInfo *sess_info,
+ Error **errp)
+{
+ int algo;
+ int mode;
+ QCryptoCipher *cipher;
+ int index;
+ CryptoDevBackendBuiltinSession *sess;
+ int ret;
+
+ if (sess_info->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) {
+ error_setg(errp, "Unsupported optype :%u", sess_info->op_type);
+ return -1;
+ }
+
+ index = cryptodev_builtin_get_unused_session_index(builtin);
+ if (index < 0) {
+ error_setg(errp, "Total number of sessions created exceeds %u",
+ MAX_NUM_SESSIONS);
+ return -1;
+ }
+
+ ret = cryptodev_builtin_get_cipher_alg_mode(sess_info,
+ &algo, &mode, errp);
+ if (ret < 0) {
+ return -1;
+ }
+
cipher = qcrypto_cipher_new(algo, mode,
sess_info->cipher_key,
sess_info->key_len,
--
1.8.3.1
next prev parent reply other threads:[~2017-11-06 6:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-06 6:56 [Qemu-devel] [RFC 00/10] virtio-crypto: add multiplexing mode support Longpeng(Mike)
2017-11-06 6:56 ` [Qemu-devel] [RFC 01/10] virtio-crypto: remove virtio_crypto_op_ctrl_req structure Longpeng(Mike)
2017-11-06 6:56 ` [Qemu-devel] [RFC 02/10] virtio-crypto: add session creation logic for mux mode Longpeng(Mike)
2017-11-06 6:56 ` [Qemu-devel] [RFC 03/10] virtio-crypto: remove queue_id field in ctrl header Longpeng(Mike)
2017-11-06 6:56 ` [Qemu-devel] [RFC 04/10] virtio-crypto: remove virtio_crypto_op_data_req structure Longpeng(Mike)
2017-11-06 6:56 ` [Qemu-devel] [RFC 05/10] virtio-crypto: add dataq operation logic for mux mode Longpeng(Mike)
2017-11-06 6:56 ` [Qemu-devel] [RFC 06/10] cryptodev: add stateless mode cipher support Longpeng(Mike)
2017-11-06 6:56 ` [Qemu-devel] [RFC 07/10] virtio-crypto: add stateless crypto request handler Longpeng(Mike)
2017-11-06 6:57 ` Longpeng(Mike) [this message]
2017-11-06 6:57 ` [Qemu-devel] [RFC 09/10] cryptodev-builtin: add stateless cipher support Longpeng(Mike)
2017-11-06 6:57 ` [Qemu-devel] [RFC 10/10] virtio-crypto: add host feature bits support Longpeng(Mike)
2017-11-06 7:57 ` [Qemu-devel] [RFC 00/10] virtio-crypto: add multiplexing mode support no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1509951422-20060-9-git-send-email-longpeng2@huawei.com \
--to=longpeng2@huawei.com \
--cc=arei.gonglei@huawei.com \
--cc=jianjay.zhou@huawei.com \
--cc=pasic@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=wangxinxin.wang@huawei.com \
--cc=weidong.huang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).