From patchwork Tue Apr 18 23:06:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Mueller X-Patchwork-Id: 9686619 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F77E6037E for ; Tue, 18 Apr 2017 23:10:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5180627D4D for ; Tue, 18 Apr 2017 23:10:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46594283A6; Tue, 18 Apr 2017 23:10:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6AF72839C for ; Tue, 18 Apr 2017 23:10:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932709AbdDRXK2 (ORCPT ); Tue, 18 Apr 2017 19:10:28 -0400 Received: from mail.eperm.de ([89.247.134.16]:58998 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758187AbdDRXKJ (ORCPT ); Tue, 18 Apr 2017 19:10:09 -0400 Received: from positron.chronox.de (mail.eperm.de [89.247.134.16]) by mail.eperm.de (Postfix) with ESMTPA id 1A1731817979; Wed, 19 Apr 2017 01:09:43 +0200 (CEST) From: Stephan =?ISO-8859-1?Q?M=FCller?= To: linux-crypto@vger.kernel.org Cc: keyrings@vger.kernel.org Subject: [PATCH 5/8] crypto: DH - allow params and key to be set independently Date: Wed, 19 Apr 2017 01:06:23 +0200 Message-ID: <2575387.ZKC7OI4y0P@positron.chronox.de> In-Reply-To: <2715753.J0rCo2lbig@positron.chronox.de> References: <2715753.J0rCo2lbig@positron.chronox.de> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Parameters are handled independently from the secret key. Therefore, this patch allows setting of the parameter independently from the secret key. Before invoking the actual crypto operation, the code must now check that the secret key and the parameters are all present. Signed-off-by: Stephan Mueller --- crypto/dh.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crypto/dh.c b/crypto/dh.c index 87e3542..f7be48e 100644 --- a/crypto/dh.c +++ b/crypto/dh.c @@ -60,6 +60,10 @@ static int dh_check_params_length(unsigned int p_len) static int dh_set_params(struct dh_ctx *ctx, struct dh *params) { + /* If DH parameters are not given, do not check them. */ + if (!params->p_size && !params->g_size) + return 0; + if (unlikely(!params->p || !params->g)) return -EINVAL; @@ -111,7 +115,7 @@ static int dh_compute_value(struct kpp_request *req) if (!val) return -ENOMEM; - if (unlikely(!ctx->xa)) { + if (unlikely(!ctx->xa || !ctx->p || !ctx->g)) { ret = -EINVAL; goto err_free_val; }