[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for 8.0 7/8] cryptodev-builtin: Detect akcipher capability
From: |
zhenwei pi |
Subject: |
[PATCH for 8.0 7/8] cryptodev-builtin: Detect akcipher capability |
Date: |
Fri, 11 Nov 2022 14:45:52 +0800 |
Rather than exposing akcipher service/RSA algorithm to virtio crypto
device unconditionally, detect akcipher capability from akcipher
crypto framework. This avoids unsuccessful requests.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
backends/cryptodev-builtin.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c
index a548c66e39..9e94d2bfcc 100644
--- a/backends/cryptodev-builtin.c
+++ b/backends/cryptodev-builtin.c
@@ -59,6 +59,25 @@ struct CryptoDevBackendBuiltin {
CryptoDevBackendBuiltinSession *sessions[MAX_NUM_SESSIONS];
};
+static void cryptodev_builtin_init_akcipher(CryptoDevBackend *backend)
+{
+ QCryptoAkCipherOptions opts;
+ bool supported = false;
+
+ opts.alg = QCRYPTO_AKCIPHER_ALG_RSA;
+ opts.u.rsa.padding_alg = QCRYPTO_RSA_PADDING_ALG_RAW;
+ if (qcrypto_akcipher_supports(&opts)) {
+ backend->conf.crypto_services |=
+ (1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER);
+ backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA;
+ supported = true;
+ }
+
+ if (supported) {
+ backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1);
+ }
+}
+
static void cryptodev_builtin_init(
CryptoDevBackend *backend, Error **errp)
{
@@ -81,11 +100,9 @@ static void cryptodev_builtin_init(
backend->conf.crypto_services =
1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER |
1u << QCRYPTODEV_BACKEND_SERVICE_HASH |
- 1u << QCRYPTODEV_BACKEND_SERVICE_MAC |
- 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER;
+ 1u << QCRYPTODEV_BACKEND_SERVICE_MAC;
backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC;
backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1;
- backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA;
/*
* Set the Maximum length of crypto request.
* Why this value? Just avoid to overflow when
@@ -96,7 +113,7 @@ static void cryptodev_builtin_init(
backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN;
backend->sym_stat = g_new0(QCryptodevBackendSymStat, 1);
- backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1);
+ cryptodev_builtin_init_akcipher(backend);
cryptodev_backend_set_ready(backend, true);
}
--
2.20.1
- [PATCH for 8.0 0/8] Refactor cryptodev, zhenwei pi, 2022/11/11
- [PATCH for 8.0 2/8] cryptodev: Remove 'name' & 'model' fields, zhenwei pi, 2022/11/11
- [PATCH for 8.0 4/8] cryptodev: Introduce server type in QAPI, zhenwei pi, 2022/11/11
- [PATCH for 8.0 1/8] cryptodev: Introduce cryptodev.json, zhenwei pi, 2022/11/11
- [PATCH for 8.0 3/8] cryptodev: Introduce cryptodev alg type in QAPI, zhenwei pi, 2022/11/11
- [PATCH for 8.0 6/8] cryptodev: Support statistics, zhenwei pi, 2022/11/11
- [PATCH for 8.0 7/8] cryptodev-builtin: Detect akcipher capability,
zhenwei pi <=
- [PATCH for 8.0 8/8] hmp: add cryptodev info command, zhenwei pi, 2022/11/11
- [PATCH for 8.0 5/8] cryptodev: Introduce 'query-cryptodev' QMP command, zhenwei pi, 2022/11/11
- PING: [PATCH for 8.0 0/8] Refactor cryptodev, zhenwei pi, 2022/11/15