Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp3170364imc; Sat, 23 Feb 2019 22:11:02 -0800 (PST) X-Google-Smtp-Source: AHgI3IbPX2YaT61RM3V9qmkn03a/Q6mgBcFFAcOctb6vqk0okbp+/dpDIucUOJ/nndpPIGmAbbis X-Received: by 2002:a62:4586:: with SMTP id n6mr12642147pfi.43.1550988662833; Sat, 23 Feb 2019 22:11:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550988662; cv=none; d=google.com; s=arc-20160816; b=O5QiaNaKy6Qhp9cQ1vfT5oSYgqhW6UxUUgwwwpJXS+e4SjdMhDVnLPh5jXu8PTbArC 7XzuOO9oN8ES3jqmW7REesoSz78KwGBewLStGaW0a2oAXb9kyrLB51HzlBhhg66c1BcD GMLxPu/ZubsAk2KjN2+VRz2CFnxJB+Dy5fm44A067d3kLleGaA7CCE5GeqUP3clq/oKU J8a5jt+RvM1QEWZ6m6ViFkuuWXavSXa7BoHYg1k5I3HzxqVxWvZOMrQGQsSwAcw3d7fM dggECogAOcSoXdo+wlUti6BDV5eK/qkSvxPPadBOd1p9Z8Z9yDs59INphcifBCPop0Sf GOxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=GQQZ+AqLhAG+7DLjbcXvj3akQw7AE+FsDfk/HypYz7A=; b=ptIJG99kUI7pNrUMw9UCaz1psb9BN3nUdU/b0T/MdC5ZpqfsNEoRqsaSRnH8s7Pryw dfHS64kfcglID7GeLNcOrrC+lLfb4WV4hPAg8w1L+vTDejTKxcRsxLXA0GFkidHmq9tO 0maQIE132BEUfNQu31Mb9qUHHVqYmg6Xt3c3Uc9wf8sPaWP+MqqNUbE0Txk3WnO4Zsbl GELbWnamXxOgpKh1r6nis54esBqIdePnCLZ0zkKrFCGQvNrFKPWyCoNBVge1OtfuPbdE xJ3utEql08cYq6Agqn2XoOtRrXfrWTdxGz3HhjUTh6/Rellyuk597l39C1OO6POBHQdc ly+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l186si5102231pgd.67.2019.02.23.22.10.47; Sat, 23 Feb 2019 22:11:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727991AbfBXGI6 (ORCPT + 99 others); Sun, 24 Feb 2019 01:08:58 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:43672 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbfBXGI5 (ORCPT ); Sun, 24 Feb 2019 01:08:57 -0500 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id F0E8772CCAF; Sun, 24 Feb 2019 09:08:54 +0300 (MSK) Received: from beacon.altlinux.org (unknown [185.6.174.98]) by imap.altlinux.org (Postfix) with ESMTPSA id B83D94A4AE7; Sun, 24 Feb 2019 09:08:54 +0300 (MSK) From: Vitaly Chikunov To: Herbert Xu , David Howells , Mimi Zohar , linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 02/10] crypto: akcipher - check the presence of callback before the call Date: Sun, 24 Feb 2019 09:08:20 +0300 Message-Id: <20190224060828.2527-3-vt@altlinux.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190224060828.2527-1-vt@altlinux.org> References: <20190224060828.2527-1-vt@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because with introduction of EC-RDSA and change in workings of RSA in regard to sign/verify, akcipher could have not all callbacks defined, check the presence of callbacks before calling them to increase robustness. Signed-off-by: Vitaly Chikunov --- include/crypto/akcipher.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h index 2d690494568c..f537fad1989f 100644 --- a/include/crypto/akcipher.h +++ b/include/crypto/akcipher.h @@ -268,7 +268,10 @@ static inline unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm) { struct akcipher_alg *alg = crypto_akcipher_alg(tfm); - return alg->max_size(tfm); + if (alg->max_size) + return alg->max_size(tfm); + else + return 0; } /** @@ -287,10 +290,11 @@ static inline int crypto_akcipher_encrypt(struct akcipher_request *req) struct akcipher_alg *alg = crypto_akcipher_alg(tfm); struct crypto_alg *calg = tfm->base.__crt_alg; unsigned int src_len = req->src_len; - int ret; + int ret = -ENOSYS; crypto_stats_get(calg); - ret = alg->encrypt(req); + if (alg->encrypt) + ret = alg->encrypt(req); crypto_stats_akcipher_encrypt(src_len, ret, calg); return ret; } @@ -311,10 +315,11 @@ static inline int crypto_akcipher_decrypt(struct akcipher_request *req) struct akcipher_alg *alg = crypto_akcipher_alg(tfm); struct crypto_alg *calg = tfm->base.__crt_alg; unsigned int src_len = req->src_len; - int ret; + int ret = -ENOSYS; crypto_stats_get(calg); - ret = alg->decrypt(req); + if (alg->decrypt) + ret = alg->decrypt(req); crypto_stats_akcipher_decrypt(src_len, ret, calg); return ret; } @@ -334,10 +339,11 @@ static inline int crypto_akcipher_sign(struct akcipher_request *req) struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct akcipher_alg *alg = crypto_akcipher_alg(tfm); struct crypto_alg *calg = tfm->base.__crt_alg; - int ret; + int ret = -ENOSYS; crypto_stats_get(calg); - ret = alg->sign(req); + if (alg->sign) + ret = alg->sign(req); crypto_stats_akcipher_sign(ret, calg); return ret; } @@ -357,10 +363,11 @@ static inline int crypto_akcipher_verify(struct akcipher_request *req) struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct akcipher_alg *alg = crypto_akcipher_alg(tfm); struct crypto_alg *calg = tfm->base.__crt_alg; - int ret; + int ret = -ENOSYS; crypto_stats_get(calg); - ret = alg->verify(req); + if (alg->verify) + ret = alg->verify(req); crypto_stats_akcipher_verify(ret, calg); return ret; } -- 2.11.0