* [Qemu-devel] [PATCH for-2.9 0/2] cryptodev: support xts(aes) algorithm @ 2016-12-05 7:44 Longpeng(Mike) 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm Longpeng(Mike) 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 2/2] cryptodev: add xts(aes) support Longpeng(Mike) 0 siblings, 2 replies; 6+ messages in thread From: Longpeng(Mike) @ 2016-12-05 7:44 UTC (permalink / raw) To: arei.gonglei; +Cc: longpeng2, qemu-devel, wu.wubin, jianjay.zhou This patchset firstly fix a bug in cryptodev_builtin_get_aes_algo, and then add xts(aes) algorithm support. Longpeng(Mike) (2): cryptodev: fix the check of aes algorithm cryptodev: add xts(aes) support backends/cryptodev-builtin.c | 55 +++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 14 deletions(-) -- 1.8.3.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm 2016-12-05 7:44 [Qemu-devel] [PATCH for-2.9 0/2] cryptodev: support xts(aes) algorithm Longpeng(Mike) @ 2016-12-05 7:44 ` Longpeng(Mike) 2016-12-05 9:34 ` Gonglei (Arei) 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 2/2] cryptodev: add xts(aes) support Longpeng(Mike) 1 sibling, 1 reply; 6+ messages in thread From: Longpeng(Mike) @ 2016-12-05 7:44 UTC (permalink / raw) To: arei.gonglei; +Cc: longpeng2, qemu-devel, wu.wubin, jianjay.zhou As the key length of xts(aes) is different with other mode of aes, so we should check specially in cryptodev_builtin_get_aes_algo, if it is xts mode. Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com> --- backends/cryptodev-builtin.c | 47 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index eda954b..9dec6b8 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -111,23 +111,42 @@ cryptodev_builtin_get_unused_session_index( return -1; } +#define AES_KEYSIZE_128 16 +#define AES_KEYSIZE_128_XTS 32 +#define AES_KEYSIZE_192 24 +#define AES_KEYSIZE_256 32 +#define AES_KEYSIZE_256_XTS 64 + static int -cryptodev_builtin_get_aes_algo(uint32_t key_len, Error **errp) +cryptodev_builtin_get_aes_algo(uint32_t key_len, int mode, Error **errp) { int algo; - if (key_len == 128 / 8) { + if (key_len == AES_KEYSIZE_128) { algo = QCRYPTO_CIPHER_ALG_AES_128; - } else if (key_len == 192 / 8) { + } else if (key_len == AES_KEYSIZE_192) { algo = QCRYPTO_CIPHER_ALG_AES_192; - } else if (key_len == 256 / 8) { - algo = QCRYPTO_CIPHER_ALG_AES_256; + } else if (key_len == AES_KEYSIZE_256) { /* equals AES_KEYSIZE_128_XTS */ + if (mode == QCRYPTO_CIPHER_MODE_XTS) { + algo = QCRYPTO_CIPHER_ALG_AES_128; + } else { + algo = QCRYPTO_CIPHER_ALG_AES_256; + } + } else if (key_len == AES_KEYSIZE_256_XTS) { + if (mode == QCRYPTO_CIPHER_MODE_XTS) { + algo = QCRYPTO_CIPHER_ALG_AES_256; + } else { + goto err; + } } else { - error_setg(errp, "Unsupported key length :%u", key_len); - return -1; + goto err; } return algo; + +err: + error_setg(errp, "Unsupported key length :%u", key_len); + return -1; } static int cryptodev_builtin_create_cipher_session( @@ -155,32 +174,32 @@ static int cryptodev_builtin_create_cipher_session( 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, - errp); + mode, errp); if (algo < 0) { return -1; } - mode = QCRYPTO_CIPHER_MODE_ECB; break; case VIRTIO_CRYPTO_CIPHER_AES_CBC: + mode = QCRYPTO_CIPHER_MODE_CBC; algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - errp); + mode, errp); if (algo < 0) { return -1; } - mode = QCRYPTO_CIPHER_MODE_CBC; break; case VIRTIO_CRYPTO_CIPHER_AES_CTR: + mode = QCRYPTO_CIPHER_MODE_CTR; algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, - errp); + mode, errp); if (algo < 0) { return -1; } - mode = QCRYPTO_CIPHER_MODE_CTR; break; case VIRTIO_CRYPTO_CIPHER_DES_ECB: - algo = QCRYPTO_CIPHER_ALG_DES_RFB; mode = QCRYPTO_CIPHER_MODE_ECB; + algo = QCRYPTO_CIPHER_ALG_DES_RFB; break; default: error_setg(errp, "Unsupported cipher alg :%u", -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm Longpeng(Mike) @ 2016-12-05 9:34 ` Gonglei (Arei) 2016-12-05 9:51 ` Longpeng (Mike) 0 siblings, 1 reply; 6+ messages in thread From: Gonglei (Arei) @ 2016-12-05 9:34 UTC (permalink / raw) To: longpeng; +Cc: qemu-devel@nongnu.org, Wubin (H), Zhoujian (jay, Euler) > -----Original Message----- > From: longpeng > Sent: Monday, December 05, 2016 3:44 PM > To: Gonglei (Arei) > Cc: longpeng; qemu-devel@nongnu.org; Wubin (H); Zhoujian (jay, Euler) > Subject: [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm > > As the key length of xts(aes) is different with other mode of aes, > so we should check specially in cryptodev_builtin_get_aes_algo, if > it is xts mode. > > Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com> > --- > backends/cryptodev-builtin.c | 47 > +++++++++++++++++++++++++++++++------------- > 1 file changed, 33 insertions(+), 14 deletions(-) > > diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c > index eda954b..9dec6b8 100644 > --- a/backends/cryptodev-builtin.c > +++ b/backends/cryptodev-builtin.c > @@ -111,23 +111,42 @@ cryptodev_builtin_get_unused_session_index( > return -1; > } > > +#define AES_KEYSIZE_128 16 > +#define AES_KEYSIZE_128_XTS 32 > +#define AES_KEYSIZE_192 24 > +#define AES_KEYSIZE_256 32 > +#define AES_KEYSIZE_256_XTS 64 > + > static int > -cryptodev_builtin_get_aes_algo(uint32_t key_len, Error **errp) > +cryptodev_builtin_get_aes_algo(uint32_t key_len, int mode, Error **errp) > { > int algo; > > - if (key_len == 128 / 8) { > + if (key_len == AES_KEYSIZE_128) { > algo = QCRYPTO_CIPHER_ALG_AES_128; > - } else if (key_len == 192 / 8) { > + } else if (key_len == AES_KEYSIZE_192) { > algo = QCRYPTO_CIPHER_ALG_AES_192; > - } else if (key_len == 256 / 8) { > - algo = QCRYPTO_CIPHER_ALG_AES_256; > + } else if (key_len == AES_KEYSIZE_256) { /* equals AES_KEYSIZE_128_XTS > */ So I think you can: #define AES_KEYSIZE_128_XTS AES_KEYSIZE_256 Regards, -Gonglei > + if (mode == QCRYPTO_CIPHER_MODE_XTS) { > + algo = QCRYPTO_CIPHER_ALG_AES_128; > + } else { > + algo = QCRYPTO_CIPHER_ALG_AES_256; > + } > + } else if (key_len == AES_KEYSIZE_256_XTS) { > + if (mode == QCRYPTO_CIPHER_MODE_XTS) { > + algo = QCRYPTO_CIPHER_ALG_AES_256; > + } else { > + goto err; > + } > } else { > - error_setg(errp, "Unsupported key length :%u", key_len); > - return -1; > + goto err; > } > > return algo; > + > +err: > + error_setg(errp, "Unsupported key length :%u", key_len); > + return -1; > } > > static int cryptodev_builtin_create_cipher_session( > @@ -155,32 +174,32 @@ static int cryptodev_builtin_create_cipher_session( > > 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, > - errp); > + mode, errp); > if (algo < 0) { > return -1; > } > - mode = QCRYPTO_CIPHER_MODE_ECB; > break; > case VIRTIO_CRYPTO_CIPHER_AES_CBC: > + mode = QCRYPTO_CIPHER_MODE_CBC; > algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, > - errp); > + mode, errp); > if (algo < 0) { > return -1; > } > - mode = QCRYPTO_CIPHER_MODE_CBC; > break; > case VIRTIO_CRYPTO_CIPHER_AES_CTR: > + mode = QCRYPTO_CIPHER_MODE_CTR; > algo = cryptodev_builtin_get_aes_algo(sess_info->key_len, > - errp); > + mode, errp); > if (algo < 0) { > return -1; > } > - mode = QCRYPTO_CIPHER_MODE_CTR; > break; > case VIRTIO_CRYPTO_CIPHER_DES_ECB: > - algo = QCRYPTO_CIPHER_ALG_DES_RFB; > mode = QCRYPTO_CIPHER_MODE_ECB; > + algo = QCRYPTO_CIPHER_ALG_DES_RFB; > break; > default: > error_setg(errp, "Unsupported cipher alg :%u", > -- > 1.8.3.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm 2016-12-05 9:34 ` Gonglei (Arei) @ 2016-12-05 9:51 ` Longpeng (Mike) 0 siblings, 0 replies; 6+ messages in thread From: Longpeng (Mike) @ 2016-12-05 9:51 UTC (permalink / raw) To: Gonglei (Arei); +Cc: qemu-devel@nongnu.org, Wubin (H), Zhoujian (jay, Euler) Hi Gonglei, On 2016/12/5 17:34, Gonglei (Arei) wrote: > ...... >> >> +#define AES_KEYSIZE_128 16 >> +#define AES_KEYSIZE_128_XTS 32 >> +#define AES_KEYSIZE_192 24 >> +#define AES_KEYSIZE_256 32 >> +#define AES_KEYSIZE_256_XTS 64 >> + >> static int >> -cryptodev_builtin_get_aes_algo(uint32_t key_len, Error **errp) >> +cryptodev_builtin_get_aes_algo(uint32_t key_len, int mode, Error **errp) >> { >> int algo; >> >> - if (key_len == 128 / 8) { >> + if (key_len == AES_KEYSIZE_128) { >> algo = QCRYPTO_CIPHER_ALG_AES_128; >> - } else if (key_len == 192 / 8) { >> + } else if (key_len == AES_KEYSIZE_192) { >> algo = QCRYPTO_CIPHER_ALG_AES_192; >> - } else if (key_len == 256 / 8) { >> - algo = QCRYPTO_CIPHER_ALG_AES_256; >> + } else if (key_len == AES_KEYSIZE_256) { /* equals AES_KEYSIZE_128_XTS >> */ > > So I think you can: > #define AES_KEYSIZE_128_XTS AES_KEYSIZE_256 All right, I send a V2 later. :) > > > Regards, > -Gonglei > ...... > -- Regards, Longpeng(Mike) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH for-2.9 2/2] cryptodev: add xts(aes) support 2016-12-05 7:44 [Qemu-devel] [PATCH for-2.9 0/2] cryptodev: support xts(aes) algorithm Longpeng(Mike) 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm Longpeng(Mike) @ 2016-12-05 7:44 ` Longpeng(Mike) 2016-12-05 9:35 ` Gonglei (Arei) 1 sibling, 1 reply; 6+ messages in thread From: Longpeng(Mike) @ 2016-12-05 7:44 UTC (permalink / raw) To: arei.gonglei; +Cc: longpeng2, qemu-devel, wu.wubin, jianjay.zhou This patch add xts(aes) support. Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com> --- backends/cryptodev-builtin.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 9dec6b8..ecad565 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -197,6 +197,14 @@ static int cryptodev_builtin_create_cipher_session( 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) { + return -1; + } + break; case VIRTIO_CRYPTO_CIPHER_DES_ECB: mode = QCRYPTO_CIPHER_MODE_ECB; algo = QCRYPTO_CIPHER_ALG_DES_RFB; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9 2/2] cryptodev: add xts(aes) support 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 2/2] cryptodev: add xts(aes) support Longpeng(Mike) @ 2016-12-05 9:35 ` Gonglei (Arei) 0 siblings, 0 replies; 6+ messages in thread From: Gonglei (Arei) @ 2016-12-05 9:35 UTC (permalink / raw) To: longpeng; +Cc: qemu-devel@nongnu.org, Wubin (H), Zhoujian (jay, Euler) > -----Original Message----- > From: longpeng > Sent: Monday, December 05, 2016 3:44 PM > To: Gonglei (Arei) > Cc: longpeng; qemu-devel@nongnu.org; Wubin (H); Zhoujian (jay, Euler) > Subject: [PATCH for-2.9 2/2] cryptodev: add xts(aes) support > > This patch add xts(aes) support. > > Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com> > --- > backends/cryptodev-builtin.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > Reviewed-by: Gonglei <arei.gonglei@huawei.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-12-05 9:52 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-12-05 7:44 [Qemu-devel] [PATCH for-2.9 0/2] cryptodev: support xts(aes) algorithm Longpeng(Mike) 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 1/2] cryptodev: fix the check of aes algorithm Longpeng(Mike) 2016-12-05 9:34 ` Gonglei (Arei) 2016-12-05 9:51 ` Longpeng (Mike) 2016-12-05 7:44 ` [Qemu-devel] [PATCH for-2.9 2/2] cryptodev: add xts(aes) support Longpeng(Mike) 2016-12-05 9:35 ` Gonglei (Arei)
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).