From: Stephan Mueller <smueller@chronox.de>
To: George Spelvin <linux@horizon.com>
Cc: herbert@gondor.apana.org.au, nhorman@tuxdriver.com,
linux-crypto@vger.kernel.org
Subject: Re: [PATCH 02/17] crypto: ansi_cprng - Eliminate ctx->last_rand_data
Date: Tue, 02 Dec 2014 09:57:17 +0100 [thread overview]
Message-ID: <1969422.t6jbN6M3rE@tauon> (raw)
In-Reply-To: <20141202083550.17918.qmail@ns.horizon.com>
Am Dienstag, 2. Dezember 2014, 03:35:50 schrieb George Spelvin:
Hi George,
>It's simply not necessary.
Can you please be a bit more verbose on why you think this is not
necessary?
Have you tested that change with reference test vectors -- what do
testmgr test vectors say?
>
>Signed-off-by: George Spelvin <linux@horizon.com>
>---
> crypto/ansi_cprng.c | 28 +++++++++++-----------------
> 1 file changed, 11 insertions(+), 17 deletions(-)
>
>diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
>index c9e1684b..c0a27288 100644
>--- a/crypto/ansi_cprng.c
>+++ b/crypto/ansi_cprng.c
>@@ -46,7 +46,6 @@
> struct prng_context {
> spinlock_t prng_lock;
> unsigned char rand_data[DEFAULT_BLK_SZ];
>- unsigned char last_rand_data[DEFAULT_BLK_SZ];
> unsigned char DT[DEFAULT_BLK_SZ];
> unsigned char I[DEFAULT_BLK_SZ];
> unsigned char V[DEFAULT_BLK_SZ];
>@@ -89,8 +88,6 @@ static int _get_more_prng_bytes(struct prng_context
>*ctx, int cont_test) {
> int i;
> unsigned char tmp[DEFAULT_BLK_SZ];
>- unsigned char *output = NULL;
>-
>
> dbgprint(KERN_CRIT "Calling _get_more_prng_bytes for context
%p\n",
> ctx);
>@@ -103,6 +100,7 @@ static int _get_more_prng_bytes(struct prng_context
>*ctx, int cont_test) * This algorithm is a 3 stage state machine
> */
> for (i = 0; i < 3; i++) {
>+ unsigned char *output;
>
> switch (i) {
> case 0:
>@@ -115,23 +113,23 @@ static int _get_more_prng_bytes(struct
>prng_context *ctx, int cont_test) hexdump("tmp stage 0: ", tmp,
>DEFAULT_BLK_SZ);
> break;
> case 1:
>-
> /*
>- * Next xor I with our secret vector V
>- * encrypt that result to obtain our
>- * pseudo random data which we output
>+ * Next xor I with our secret vector V.
>+ * Encrypt that result to obtain our pseudo
random
>+ * data which we output. It is kept temporarily
>+ * in (no longer used) V until we have done the
>+ * anti-repetition compare.
> */
> xor_vectors(ctx->I, ctx->V, tmp,
DEFAULT_BLK_SZ);
> hexdump("tmp stage 1: ", tmp, DEFAULT_BLK_SZ);
>- output = ctx->rand_data;
>+ output = ctx->V;
> break;
> case 2:
> /*
> * First check that we didn't produce the same
>- * random data that we did last time around
through this
>+ * random data that we did last time around.
> */
>- if (!memcmp(ctx->rand_data, ctx->last_rand_data,
>- DEFAULT_BLK_SZ)) {
>+ if (!memcmp(ctx->V, ctx->rand_data,
DEFAULT_BLK_SZ)) {
> if (cont_test) {
> panic("cprng %p Failed
repetition check!\n",
> ctx);
>@@ -144,15 +142,13 @@ static int _get_more_prng_bytes(struct
>prng_context *ctx, int cont_test) ctx->flags |= PRNG_NEED_RESET;
> return -EINVAL;
> }
>- memcpy(ctx->last_rand_data, ctx->rand_data,
>- DEFAULT_BLK_SZ);
>+ memcpy(ctx->rand_data, ctx->V, DEFAULT_BLK_SZ);
>
> /*
> * Lastly xor the random data with I
> * and encrypt that to obtain a new secret
vector V
> */
>- xor_vectors(ctx->rand_data, ctx->I, tmp,
>- DEFAULT_BLK_SZ);
>+ xor_vectors(ctx->I, ctx->V, tmp,
DEFAULT_BLK_SZ);
> output = ctx->V;
> hexdump("tmp stage 2: ", tmp, DEFAULT_BLK_SZ);
> break;
>@@ -161,7 +157,6 @@ static int _get_more_prng_bytes(struct prng_context
>*ctx, int cont_test)
>
> /* do the encryption */
> crypto_cipher_encrypt_one(ctx->tfm, output, tmp);
>-
> }
>
> /*
>@@ -299,7 +294,6 @@ static int reset_prng_context(struct prng_context
>*ctx, memset(ctx->DT, 0, DEFAULT_BLK_SZ);
>
> memset(ctx->rand_data, 0, DEFAULT_BLK_SZ);
>- memset(ctx->last_rand_data, 0, DEFAULT_BLK_SZ);
>
> ctx->rand_read_pos = DEFAULT_BLK_SZ; /* Force immediate
refill */
Ciao
Stephan
next prev parent reply other threads:[~2014-12-02 8:57 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-29 2:43 Is ansi_cprng.c supposed to implement X9.17/X9.31's RNG? George Spelvin
2014-11-29 17:26 ` George Spelvin
2014-11-29 17:59 ` Neil Horman
2014-12-02 8:33 ` [PATCH 00/17] Multiple changes to crypto/ansi_cprng.c George Spelvin
2014-12-02 8:34 ` [PATCH 01/17] crypto: ansi_cprng - Rename rand_data_valid more sensibly George Spelvin
2014-12-02 8:41 ` Stephan Mueller
2014-12-02 17:12 ` George Spelvin
2014-12-02 8:35 ` [PATCH 02/17] crypto: ansi_cprng - Eliminate ctx->last_rand_data George Spelvin
2014-12-02 8:57 ` Stephan Mueller [this message]
2014-12-02 9:08 ` George Spelvin
2014-12-02 14:46 ` Neil Horman
2014-12-02 19:45 ` George Spelvin
2014-12-02 8:37 ` [PATCH 03/17] crypto: ansi_cprng - Eliminate ctx->I George Spelvin
2014-12-02 14:52 ` Neil Horman
2014-12-02 20:03 ` George Spelvin
2014-12-03 11:08 ` Neil Horman
2014-12-02 8:37 ` PATCH 04/17] crypto: ansi_cprng - simplify xor_vectors() to xor_block() George Spelvin
2014-12-02 8:39 ` [PATCH 05/17] crypto: ansi_cprng - Add const annotations to hexdump() George Spelvin
2014-12-02 8:40 ` [PATCH 06/17] crypto: ansi_cprng - Eliminate unused PRNG_FIXED_SIZE flag George Spelvin
2014-12-02 8:43 ` [PATCH 07/17] crypto: ansi_cprng - Shrink rand_read_pos & flags George Spelvin
2014-12-02 14:59 ` Neil Horman
2014-12-02 20:28 ` George Spelvin
2014-12-03 11:11 ` Neil Horman
2014-12-02 8:46 ` [PATCH 08/17] crypto: ansi_cprng - Require non-null key & V in reset_prng_context George Spelvin
2014-12-02 8:50 ` [PATCH 09/17] crypto: ansi_cprng - Clean up some variable types George Spelvin
2014-12-02 8:52 ` [PATCH 10/17] crypto: ansi_cprng - simplify get_prng_bytes George Spelvin
2014-12-02 8:54 ` [PATCH 11/17] crypto: ansi_cprng - unroll _get_more_prng_bytes George Spelvin
2014-12-02 21:54 ` George Spelvin
2014-12-02 8:56 ` [PATCH 12/17] crypto: ansi_cprng - Create a "block buffer" data type George Spelvin
2014-12-02 8:57 ` [PATCH 13/17] crypto: ansi_cprng - If DT is not provided, use a fresh timestamp George Spelvin
2014-12-02 9:11 ` George Spelvin
2014-12-02 8:58 ` [PATCH 14/17] crypto: ansi_cprng - If DT is omitted, don't buffer old output George Spelvin
2014-12-02 8:59 ` [PATCH 15/17] crypto: testmgr - Teach test_cprng to handle non-default seed sizes George Spelvin
2014-12-02 9:01 ` [PATCH 16/17] crypto: testmgr - Merge seed arrays in struct cprng_testvec George Spelvin
2014-12-02 9:02 ` [PATCH 17/17] crypto: ansi_cprng - Shrink default seed size George Spelvin
2014-12-03 11:13 ` [PATCH 00/17] Multiple changes to crypto/ansi_cprng.c Neil Horman
2014-12-03 20:27 ` George Spelvin
2014-12-04 18:07 ` Stephan Mueller
2014-12-05 11:28 ` Neil Horman
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=1969422.t6jbN6M3rE@tauon \
--to=smueller@chronox.de \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux@horizon.com \
--cc=nhorman@tuxdriver.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