public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephan Mueller <smueller@chronox.de>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org
Subject: [PATCH 5/8] DRBG: use kmalloc instead of kzalloc for V and C
Date: Sun, 17 Aug 2014 17:39:31 +0200	[thread overview]
Message-ID: <1908749.s83x5fJMRR@myon.chronox.de> (raw)
In-Reply-To: <7044529.FG2KhbPc9P@myon.chronox.de>

When allocating V, C, the zeroization is only needed when
allocating a new instance of the DRBG, i.e. when performing an
initial seeding. For all other allocations, the memcpy implemented in
drbg_copy_drbg ensures that the memory is filled with the correct
information.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
---
 crypto/drbg.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/crypto/drbg.c b/crypto/drbg.c
index d13f588..997c510 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -1142,6 +1142,11 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers,
 		pr_devel("DRBG: using personalization string\n");
 	}
 
+	if (!reseed) {
+		memset(drbg->V, 0, drbg_statelen(drbg));
+		memset(drbg->C, 0, drbg_statelen(drbg));
+	}
+
 	ret = drbg->d_ops->update(drbg, &seedlist, reseed);
 	if (ret)
 		goto out;
@@ -1186,14 +1191,14 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)
 	if (!drbg)
 		return -EINVAL;
 
-	drbg->V = kzalloc(drbg_statelen(drbg), GFP_KERNEL);
+	drbg->V = kmalloc(drbg_statelen(drbg), GFP_KERNEL);
 	if (!drbg->V)
 		goto err;
-	drbg->C = kzalloc(drbg_statelen(drbg), GFP_KERNEL);
+	drbg->C = kmalloc(drbg_statelen(drbg), GFP_KERNEL);
 	if (!drbg->C)
 		goto err;
 #ifdef CONFIG_CRYPTO_FIPS
-	drbg->prev = kzalloc(drbg_blocklen(drbg), GFP_KERNEL);
+	drbg->prev = kmalloc(drbg_blocklen(drbg), GFP_KERNEL);
 	if (!drbg->prev)
 		goto err;
 	drbg->fips_primed = false;
-- 
1.9.3



  parent reply	other threads:[~2014-08-17 15:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-17 15:37 [PATCH 0/8] DRBG: efficiency patches Stephan Mueller
2014-08-17 15:37 ` [PATCH 1/8] DRBG: replace int2byte with cpu_to_be Stephan Mueller
2014-08-17 15:37 ` [PATCH 2/8] DRBG: kzfree does not need a check for NULL pointer Stephan Mueller
2014-08-17 15:38 ` [PATCH 3/8] DRBG: remove superflowous checks Stephan Mueller
2014-08-17 15:38 ` [PATCH 4/8] DRBG: remove superflowous memset(0) Stephan Mueller
2014-08-17 15:39 ` Stephan Mueller [this message]
2014-08-17 15:40 ` [PATCH 6/8] DRBG: remove unnecessary sanity checks Stephan Mueller
2014-08-17 15:41 ` [PATCH 7/8] DRBG: remove configuration of fixed values Stephan Mueller
2014-08-17 15:41 ` [PATCH 8/8] DRBG: remove unnecessary sanity check for shadow state Stephan Mueller
2014-08-25 12:42 ` [PATCH 0/8] DRBG: efficiency patches 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=1908749.s83x5fJMRR@myon.chronox.de \
    --to=smueller@chronox.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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