From patchwork Wed Dec 1 00:48:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 519426 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74245C433FE for ; Wed, 1 Dec 2021 00:50:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345926AbhLAAxj (ORCPT ); Tue, 30 Nov 2021 19:53:39 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:58186 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345922AbhLAAwx (ORCPT ); Tue, 30 Nov 2021 19:52:53 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 806D01FD60; Wed, 1 Dec 2021 00:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1638319772; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uqN+KoCZ+C9BhFwzmXjcu2xieMALlbPBAiHPvURkpJQ=; b=Lat5lAbPE+RphGYj547/LoMG1vr5BLvUWu9DyIOWOQovk63wglyF900QgrUtvQgrWTvl2s 5Y37jDEVtI+jF6TUxrtmVOYzUkCh9BpdYs60upO24XaYWLSBu3Io7ixIkXBOeN6sar4rNo QmFTvQeY44aAiBFzQFeMWBBdPTjLBtU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1638319772; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uqN+KoCZ+C9BhFwzmXjcu2xieMALlbPBAiHPvURkpJQ=; b=8xQKxaiST0fQTnrcbYeSTXwq38uf5e/uCWQiX625NSo89MpHeGv7xTO8Gj4oZ/gOmWgi38 IoS6jf6F/OhUIfDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6D28C13C10; Wed, 1 Dec 2021 00:49:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2AR+GZzGpmH8KAAAMHmgww (envelope-from ); Wed, 01 Dec 2021 00:49:32 +0000 From: Nicolai Stange To: Herbert Xu , "David S. Miller" Cc: =?utf-8?q?Stephan_M=C3=BCller?= , Hannes Reinecke , Torsten Duwe , Zaibo Xu , Giovanni Cabiddu , David Howells , Jarkko Sakkinen , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, qat-linux@intel.com, keyrings@vger.kernel.org, Nicolai Stange Subject: [PATCH 12/18] crypto: dh - introduce support for ephemeral key generation to qat driver Date: Wed, 1 Dec 2021 01:48:52 +0100 Message-Id: <20211201004858.19831-13-nstange@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211201004858.19831-1-nstange@suse.de> References: <20211201004858.19831-1-nstange@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org A previous patch made the dh-generic implementation's ->set_secret() to generate an ephemeral key in case the input ->key_size is zero, just in analogy with ecdh. Make the qat crypto driver's DH implementation to behave consistently by doing the same. Signed-off-by: Nicolai Stange Reviewed-by: Hannes Reinecke --- drivers/crypto/qat/qat_common/qat_asym_algs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto/qat/qat_common/qat_asym_algs.c index b0b78445418b..e0d3a70fa6b1 100644 --- a/drivers/crypto/qat/qat_common/qat_asym_algs.c +++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c @@ -441,11 +441,20 @@ static int qat_dh_set_secret(struct crypto_kpp *tfm, const void *buf, struct qat_dh_ctx *ctx = kpp_tfm_ctx(tfm); struct device *dev = &GET_DEV(ctx->inst->accel_dev); struct dh params; + char key[CRYPTO_DH_MAX_PRIVKEY_SIZE]; int ret; if (crypto_dh_decode_key(buf, len, ¶ms) < 0) return -EINVAL; + if (!params.key_size) { + ret = crypto_dh_gen_privkey(params.group_id, key, + ¶ms.key_size); + if (ret) + return ret; + params.key = key; + } + /* Free old secret if any */ qat_dh_clear_ctx(dev, ctx);