From patchwork Thu Jan 19 07:14:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13107524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 231BEC38142 for ; Thu, 19 Jan 2023 07:16:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8M-000677-Cy; Thu, 19 Jan 2023 02:14:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIP8K-00066F-NU for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:48 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8I-0002GV-Um for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:48 -0500 Received: by mail-pj1-x1030.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so1023448pjl.0 for ; Wed, 18 Jan 2023 23:14:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=3D7MIjXLiLtJi1lFTm9scaUgzt7Dh8edppItpSH87bvmhEK8MpjiUDeCzwYWQsGQZf EGMr/kZgDRrb6X/K694JqfylDcUfW5qYU8roScGooz3x44iDxOY6+4HksEBExkFUdJXa fUS2/VQZ6vowHFj1p8MMfmhlR46UYaAKYwM/0ujDcfR5jssV1TV2XMsvYa1Wm1ZlYd9L jQRepKrNtWVk2EHooudBrnC4WjDdXxw/Sl2uj3glo2DaczT0BnWsyuHvVzpG6HcexIHl URNc4J5tPsOZsl589a8vCpP3s0BSqYXY+Cy4ErZ93MPk20nTQlRUQxKGs2CJtvCyCOL1 v/Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=MLdyIy2BYvNNoYX3YDuR68WUJg8K3fZlecOE1UJCkmsQKy+/UpnwvuS3YhVBOOCW6a X3INF+PgdlebqNP6HLxwY0VkyK1+rdS5q1+n3/wGRfR6TkBiwHUMEmaf+CabZHc+ZuQ2 UbDF+9YIsPlRKGR1KFc47hyEEMSTMZyW6gF7trPYXuly5lvCHEQ9A67xWM1JWgfI6WkV s0C0Sa7pLJt77r+lxFsKxuDB7hn56zCWANzwjf6qO/CJmcXMCQmKX2Ph9HKPkKc2SQS5 e36wwcxz0plH9/8Hf9zniPUs9dLBmK6GAvW+2B5u21g7/rMDL/qYoBpzTEKyWGtLy2dn upZA== X-Gm-Message-State: AFqh2krtBm+TxXRuvcmkaV1+eb9xoXpZIeaKR1iMX73+jYw57EgRuwF6 c6WEDuH79BPvi01+P6FlCIhyDw== X-Google-Smtp-Source: AMrXdXtU0or2wiYw3dLPnOQWEOoNs70ts2qrBISfjnF1tNIcRLDd9PQsGiES/7aXQAN4bKBv6xMXsQ== X-Received: by 2002:a17:902:c10d:b0:194:9cb0:12e2 with SMTP id 13-20020a170902c10d00b001949cb012e2mr10144470pli.36.1674112485437; Wed, 18 Jan 2023 23:14:45 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:45 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 06/12] cryptodev-builtin: Detect akcipher capability Date: Thu, 19 Jan 2023 15:14:13 +0800 Message-Id: <20230119071419.3585771-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Rather than exposing akcipher service/RSA algorithm to virtio crypto device unconditionally, detect akcipher capability from akcipher crypto framework. This avoids unsuccessful requests. Reviewed-by: Daniel P. Berrangé Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index c0fbb650d7..c45b5906c5 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -59,6 +59,19 @@ struct CryptoDevBackendBuiltin { CryptoDevBackendBuiltinSession *sessions[MAX_NUM_SESSIONS]; }; +static void cryptodev_builtin_init_akcipher(CryptoDevBackend *backend) +{ + QCryptoAkCipherOptions opts; + + 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; + } +} + static void cryptodev_builtin_init( CryptoDevBackend *backend, Error **errp) { @@ -81,11 +94,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 @@ -94,6 +105,7 @@ static void cryptodev_builtin_init( backend->conf.max_size = LONG_MAX - sizeof(CryptoDevBackendOpInfo); backend->conf.max_cipher_key_len = CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_LEN; backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; + cryptodev_builtin_init_akcipher(backend); cryptodev_backend_set_ready(backend, true); }