[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v6 6/9] crypto: Implement RSA algorithm by gcrypt
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH v6 6/9] crypto: Implement RSA algorithm by gcrypt |
Date: |
Mon, 23 May 2022 10:40:19 +0100 |
User-agent: |
Mutt/2.2.1 (2022-02-19) |
On Sat, May 14, 2022 at 08:55:01AM +0800, zhenwei pi wrote:
> From: Lei He <helei.sig11@bytedance.com>
>
> Added gcryt implementation of RSA algorithm, RSA algorithm
> implemented by gcrypt has a higher priority than nettle because
> it supports raw padding.
>
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> Signed-off-by: lei he <helei.sig11@bytedance.com>
> ---
> crypto/akcipher-gcrypt.c.inc | 597 +++++++++++++++++++++++++++++++++++
> crypto/akcipher.c | 4 +-
> 2 files changed, 600 insertions(+), 1 deletion(-)
> create mode 100644 crypto/akcipher-gcrypt.c.inc
>
> diff --git a/crypto/akcipher-gcrypt.c.inc b/crypto/akcipher-gcrypt.c.inc
> new file mode 100644
> index 0000000000..6c5daa301e
> --- /dev/null
> +++ b/crypto/akcipher-gcrypt.c.inc
> @@ -0,0 +1,597 @@
> +/*
> + * QEMU Crypto akcipher algorithms
> + *
> + * Copyright (c) 2022 Bytedance
> + * Author: lei he <helei.sig11@bytedance.com>
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see
> <http://www.gnu.org/licenses/>.
> + *
> + */
> +
> +#include <gcrypt.h>
> +static QCryptoGcryptRSA *qcrypto_gcrypt_rsa_new(
> + const QCryptoAkCipherOptionsRSA *opt,
> + QCryptoAkCipherKeyType type,
> + const uint8_t *key, size_t keylen,
> + Error **errp)
> +{
> + QCryptoGcryptRSA *rsa = g_new0(QCryptoGcryptRSA, 1);
> + rsa->padding_alg = opt->padding_alg;
> + rsa->hash_alg = opt->hash_alg;
> + rsa->akcipher.driver = &gcrypt_rsa;
> +
> + switch (type) {
> + case QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE:
> + if (qcrypto_gcrypt_parse_rsa_private_key(rsa, key, keylen, errp) !=
> 0) {
> + error_setg(errp, "Failed to parse rsa private key");
Not need now, since qcrypto_gcrypt_parse_rsa_private_key reports the
real error message.
> + goto error;
> + }
> + break;
> +
> + case QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC:
> + if (qcrypto_gcrypt_parse_rsa_public_key(rsa, key, keylen, errp) !=
> 0) {
> + error_setg(errp, "Failed to parse rsa public rsa key");
Likewise not needed.
> + goto error;
> + }
> + break;
> +
> + default:
> + error_setg(errp, "Unknown akcipher key type %d", type);
> + goto error;
> + }
> +
> + return rsa;
> +
> +error:
> + qcrypto_gcrypt_rsa_free((QCryptoAkCipher *)rsa);
> + return NULL;
> +}
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- [PATCH v6 0/9] Introduce akcipher service for virtio-crypto, zhenwei pi, 2022/05/13
- [PATCH v6 3/9] crypto: Introduce akcipher crypto class, zhenwei pi, 2022/05/13
- [PATCH v6 1/9] virtio-crypto: header update, zhenwei pi, 2022/05/13
- [PATCH v6 2/9] qapi: crypto-akcipher: Introduce akcipher types to qapi, zhenwei pi, 2022/05/13
- [PATCH v6 4/9] crypto: add ASN.1 DER decoder, zhenwei pi, 2022/05/13
- [PATCH v6 5/9] crypto: Implement RSA algorithm by hogweed, zhenwei pi, 2022/05/13
- [PATCH v6 6/9] crypto: Implement RSA algorithm by gcrypt, zhenwei pi, 2022/05/13
- Re: [PATCH v6 6/9] crypto: Implement RSA algorithm by gcrypt,
Daniel P . Berrangé <=
- [PATCH v6 7/9] test/crypto: Add test suite for crypto akcipher, zhenwei pi, 2022/05/13
- [PATCH v6 8/9] tests/crypto: Add test suite for RSA keys, zhenwei pi, 2022/05/13
- [PATCH v6 9/9] crypto: Introduce RSA algorithm, zhenwei pi, 2022/05/13