From: "Longpeng(Mike)" <longpeng2@huawei.com> To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org Cc: luonengjun@huawei.com, mst@redhat.com, cohuck@redhat.com, stefanha@redhat.com, denglingli@chinamobile.com, Jani.Kokkonen@huawei.com, Ola.Liljedahl@arm.com, Varun.Sethi@freescale.com, xin.zeng@intel.com, brian.a.keating@intel.com, liang.j.ma@intel.com, john.griffin@intel.com, weidong.huang@huawei.com, mike.caraman@nxp.com, agraf@suse.de, jasowang@redhat.com, vincent.jardin@6wind.com, arei.gonglei@hotmail.com, pasic@linux.vnet.ibm.com, wangxinxin.wang@huawei.com, arei.gonglei@huawei.com, "Longpeng(Mike)" <longpeng2@huawei.com> Subject: [Qemu-devel] [RFC 6/8] cryptodev: extract one util function Date: Mon, 11 Sep 2017 09:10:38 +0800 [thread overview] Message-ID: <1505092240-10864-7-git-send-email-longpeng2@huawei.com> (raw) In-Reply-To: <1505092240-10864-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 6e10feb..ab3d88d 100755 --- 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
WARNING: multiple messages have this Message-ID (diff)
From: "Longpeng(Mike)" <longpeng2@huawei.com> To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org Cc: luonengjun@huawei.com, mst@redhat.com, cohuck@redhat.com, stefanha@redhat.com, denglingli@chinamobile.com, Jani.Kokkonen@huawei.com, Ola.Liljedahl@arm.com, Varun.Sethi@freescale.com, xin.zeng@intel.com, brian.a.keating@intel.com, liang.j.ma@intel.com, john.griffin@intel.com, weidong.huang@huawei.com, mike.caraman@nxp.com, agraf@suse.de, jasowang@redhat.com, vincent.jardin@6wind.com, arei.gonglei@hotmail.com, pasic@linux.vnet.ibm.com, wangxinxin.wang@huawei.com, arei.gonglei@huawei.com, "Longpeng(Mike)" <longpeng2@huawei.com> Subject: [virtio-dev] [RFC 6/8] cryptodev: extract one util function Date: Mon, 11 Sep 2017 09:10:38 +0800 [thread overview] Message-ID: <1505092240-10864-7-git-send-email-longpeng2@huawei.com> (raw) In-Reply-To: <1505092240-10864-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 6e10feb..ab3d88d 100755 --- 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 --------------------------------------------------------------------- To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org
next prev parent reply other threads:[~2017-09-11 1:11 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-09-11 1:10 [Qemu-devel] [RFC 0/8] virtio-crypto: add multiplexing mode support Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:10 ` [Qemu-devel] [RFC 1/8] virtio-crypto: add new definations for multiplexing mode Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:10 ` [Qemu-devel] [RFC 2/8] virtio-crypto: add session creation logic for mux mode Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:10 ` [Qemu-devel] [RFC 3/8] virtio-crypto: add dataq operation " Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:10 ` [Qemu-devel] [RFC 4/8] cryptodev: add stateless mode cipher support Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:10 ` [Qemu-devel] [RFC 5/8] virtio-crypto: add stateless crypto request handler Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:10 ` Longpeng(Mike) [this message] 2017-09-11 1:10 ` [virtio-dev] [RFC 6/8] cryptodev: extract one util function Longpeng(Mike) 2017-09-11 1:10 ` [Qemu-devel] [RFC 7/8] cryptodev-builtin: add stateless cipher support Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:10 ` [Qemu-devel] [RFC 8/8] virtio-crypto: add host feature bits support Longpeng(Mike) 2017-09-11 1:10 ` [virtio-dev] " Longpeng(Mike) 2017-09-11 1:26 ` [Qemu-devel] [RFC 0/8] virtio-crypto: add multiplexing mode support no-reply 2017-09-11 1:26 ` no-reply 2017-09-13 18:14 ` Halil Pasic 2017-09-13 18:14 ` [virtio-dev] " Halil Pasic 2017-09-14 0:58 ` [Qemu-devel] [virtio-dev] " Longpeng (Mike) 2017-09-14 0:58 ` [virtio-dev] Re: [Qemu-devel] " Longpeng (Mike) 2017-09-15 17:33 ` [Qemu-devel] [virtio-dev] " Halil Pasic 2017-09-15 17:33 ` [virtio-dev] " Halil Pasic 2017-09-18 1:17 ` [Qemu-devel] [virtio-dev] " Longpeng (Mike) 2017-09-18 1:17 ` [virtio-dev] Re: [Qemu-devel] " Longpeng (Mike) 2017-10-06 14:24 ` [Qemu-devel] [virtio-dev] " Halil Pasic 2017-10-06 14:24 ` [virtio-dev] " Halil Pasic 2017-10-09 9:22 ` Gonglei (Arei) 2017-10-09 9:22 ` [virtio-dev] " Gonglei (Arei) 2017-10-09 11:04 ` Halil Pasic 2017-10-09 11:04 ` [virtio-dev] " Halil Pasic 2017-10-09 11:17 ` Gonglei (Arei) 2017-10-09 11:17 ` [virtio-dev] " Gonglei (Arei) 2017-10-10 8:35 ` Longpeng (Mike) 2017-10-10 8:35 ` [virtio-dev] " Longpeng (Mike)
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=1505092240-10864-7-git-send-email-longpeng2@huawei.com \ --to=longpeng2@huawei.com \ --cc=Jani.Kokkonen@huawei.com \ --cc=Ola.Liljedahl@arm.com \ --cc=Varun.Sethi@freescale.com \ --cc=agraf@suse.de \ --cc=arei.gonglei@hotmail.com \ --cc=arei.gonglei@huawei.com \ --cc=brian.a.keating@intel.com \ --cc=cohuck@redhat.com \ --cc=denglingli@chinamobile.com \ --cc=jasowang@redhat.com \ --cc=john.griffin@intel.com \ --cc=liang.j.ma@intel.com \ --cc=luonengjun@huawei.com \ --cc=mike.caraman@nxp.com \ --cc=mst@redhat.com \ --cc=pasic@linux.vnet.ibm.com \ --cc=qemu-devel@nongnu.org \ --cc=stefanha@redhat.com \ --cc=vincent.jardin@6wind.com \ --cc=virtio-dev@lists.oasis-open.org \ --cc=wangxinxin.wang@huawei.com \ --cc=weidong.huang@huawei.com \ --cc=xin.zeng@intel.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.