linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tudor Ambarus <tudor.ambarus@microchip.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
	<horia.geanta@nxp.com>, <dan.douglass@nxp.com>,
	<giovanni.cabiddu@intel.com>, <salvatore.benedetto@intel.com>
Cc: <linux-crypto@vger.kernel.org>,
	Tudor Ambarus <tudor.ambarus@microchip.com>
Subject: [PATCH v4 06/14] crypto: kpp: maxsize() - assume key is already set
Date: Thu, 25 May 2017 10:18:08 +0300	[thread overview]
Message-ID: <1495696696-22580-7-git-send-email-tudor.ambarus@microchip.com> (raw)
In-Reply-To: <1495696696-22580-1-git-send-email-tudor.ambarus@microchip.com>

As of now, crypto_kpp_maxsize() can not be reached without successfully
setting the key for the transformation. kpp algorithm implementations
check if the key was set and then return the output buffer size
required for the given key.

Change the return type to unsigned int and always assume that this
function is called after a successful setkey of the transformation.
kpp algorithm implementations will remove the check if key is not NULL
and directly return the max size.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
 include/crypto/kpp.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/crypto/kpp.h b/include/crypto/kpp.h
index c190825..2133d17 100644
--- a/include/crypto/kpp.h
+++ b/include/crypto/kpp.h
@@ -79,7 +79,7 @@ struct kpp_alg {
 	int (*generate_public_key)(struct kpp_request *req);
 	int (*compute_shared_secret)(struct kpp_request *req);
 
-	int (*max_size)(struct crypto_kpp *tfm);
+	unsigned int (*max_size)(struct crypto_kpp *tfm);
 
 	int (*init)(struct crypto_kpp *tfm);
 	void (*exit)(struct crypto_kpp *tfm);
@@ -323,13 +323,14 @@ static inline int crypto_kpp_compute_shared_secret(struct kpp_request *req)
 /**
  * crypto_kpp_maxsize() - Get len for output buffer
  *
- * Function returns the output buffer size required
+ * Function returns the output buffer size required for a given key.
+ * Function assumes that the key is already set in the transformation. If this
+ * function is called without a setkey or with a failed setkey, you will end up
+ * in a NULL dereference.
  *
  * @tfm:	KPP tfm handle allocated with crypto_alloc_kpp()
- *
- * Return: minimum len for output buffer or error code if key hasn't been set
  */
-static inline int crypto_kpp_maxsize(struct crypto_kpp *tfm)
+static inline unsigned int crypto_kpp_maxsize(struct crypto_kpp *tfm)
 {
 	struct kpp_alg *alg = crypto_kpp_alg(tfm);
 
-- 
2.7.4

  parent reply	other threads:[~2017-05-25  7:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-25  7:18 [PATCH v4 00/14] fixes for kpp and akcipher Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 01/14] crypto: kpp, (ec)dh - fix typos Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 02/14] crypto: ecc - remove unused function arguments Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 03/14] crypto: ecc - remove unnecessary casts Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 04/14] crypto: ecc - don't be selfish on pubkeys Tudor Ambarus
2017-05-28 17:22   ` Horia Geantă
2017-05-29 14:11     ` Tudor Ambarus
2017-05-30 12:37       ` [PATCH v5 04/14] crypto: ecc - rename ecdh_make_pub_key() Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 05/14] crypto: dh - fix memleak in setkey Tudor Ambarus
2017-05-25  7:18 ` Tudor Ambarus [this message]
2017-05-25  7:18 ` [PATCH v4 07/14] crypto: dh - comply with crypto_kpp_maxsize() Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 08/14] crypto: ecdh " Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 09/14] crypto: qat " Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 10/14] crypto: akcipher: maxsize() - assume key is already set Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 11/14] crypto: rsa - comply with crypto_akcipher_maxsize() Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 12/14] crypto: caampkc " Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 13/14] crypto: qat " Tudor Ambarus
2017-05-25  7:18 ` [PATCH v4 14/14] crypto: pkcs1pad " Tudor Ambarus
2017-06-10  4:17 ` [PATCH v4 00/14] fixes for kpp and akcipher Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1495696696-22580-7-git-send-email-tudor.ambarus@microchip.com \
    --to=tudor.ambarus@microchip.com \
    --cc=dan.douglass@nxp.com \
    --cc=davem@davemloft.net \
    --cc=giovanni.cabiddu@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=salvatore.benedetto@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).