From: Tudor Ambarus <tudor.ambarus@microchip.com>
To: <herbert@gondor.apana.org.au>
Cc: <linux-crypto@vger.kernel.org>, <smueller@chronox.de>,
<marcel@holtmann.org>, <Nicolas.Ferre@microchip.com>,
Tudor Ambarus <tudor.ambarus@microchip.com>
Subject: [RFC PATCH 3/4] crypto: dh - allow user to provide NULL privkey
Date: Wed, 17 May 2017 13:38:35 +0300 [thread overview]
Message-ID: <1495017516-10048-4-git-send-email-tudor.ambarus@microchip.com> (raw)
In-Reply-To: <1495017516-10048-1-git-send-email-tudor.ambarus@microchip.com>
If the user provides a NULL private key, the kernel will
generate it and further use it for dh.
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
crypto/dh.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/crypto/dh.c b/crypto/dh.c
index 87e3542..33df165 100644
--- a/crypto/dh.c
+++ b/crypto/dh.c
@@ -83,7 +83,9 @@ static int dh_set_secret(struct crypto_kpp *tfm, const void *buf,
unsigned int len)
{
struct dh_ctx *ctx = dh_get_ctx(tfm);
+ u8 *rndbuf = NULL;
struct dh params;
+ int maxsize;
if (crypto_dh_decode_key(buf, len, ¶ms) < 0)
return -EINVAL;
@@ -91,12 +93,28 @@ static int dh_set_secret(struct crypto_kpp *tfm, const void *buf,
if (dh_set_params(ctx, ¶ms) < 0)
return -EINVAL;
+ if (!params.key || !params.key_size) {
+ maxsize = crypto_kpp_maxsize(tfm);
+ if (maxsize < 0)
+ return maxsize;
+
+ rndbuf = kmalloc(maxsize, GFP_KERNEL);
+ if (!rndbuf)
+ return -ENOMEM;
+
+ get_random_bytes(rndbuf, maxsize);
+ params.key = rndbuf;
+ params.key_size = maxsize;
+ }
+
ctx->xa = mpi_read_raw_data(params.key, params.key_size);
if (!ctx->xa) {
dh_clear_params(ctx);
+ kzfree(rndbuf);
return -EINVAL;
}
+ kzfree(rndbuf);
return 0;
}
--
2.7.4
next prev parent reply other threads:[~2017-05-17 10:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-17 10:38 [RFC PATCH 0/4] crypto: (ec)dh - add privkey generation support Tudor Ambarus
2017-05-17 10:38 ` [RFC PATCH 1/4] crypto: ecc " Tudor Ambarus
2017-05-17 10:38 ` [RFC PATCH 2/4] crypto: ecdh - allow user to provide NULL privkey Tudor Ambarus
2017-05-17 10:38 ` Tudor Ambarus [this message]
2017-05-17 10:38 ` [RFC PATCH 4/4] crypto: testmgr - add genkey kpp test Tudor Ambarus
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=1495017516-10048-4-git-send-email-tudor.ambarus@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=Nicolas.Ferre@microchip.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=smueller@chronox.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.