* [PATCH] crypto: ansi_cprng: fix inverted DT increment routine
@ 2008-11-13 16:36 Jarod Wilson
2008-11-13 18:44 ` Neil Horman
0 siblings, 1 reply; 3+ messages in thread
From: Jarod Wilson @ 2008-11-13 16:36 UTC (permalink / raw)
To: linux-crypto; +Cc: Neil Horman, herbert, davem, linux-kernel
The ANSI X9.31 PRNG docs aren't particularly clear on how to increment DT,
but empirical testing shows we're incrementing from the wrong end. A 10,000
iteration Monte Carlo RNG test currently winds up not getting the expected
result.
>From http://csrc.nist.gov/groups/STM/cavp/documents/rng/RNGVS.pdf :
# CAVS 4.3
# ANSI931 MCT
[X9.31]
[AES 128-Key]
COUNT = 0
Key = 9f5b51200bf334b5d82be8c37255c848
DT = 6376bbe52902ba3b67c925fa701f11ac
V = 572c8e76872647977e74fbddc49501d1
R = 48e9bd0d06ee18fbe45790d5c3fc9b73
Currently, we get 0dd08496c4f7178bfa70a2161a79459a after 10000 loops.
Inverting the DT increment routine results in us obtaining the expected result
of 48e9bd0d06ee18fbe45790d5c3fc9b73. Verified on both x86_64 and ppc64.
Signed-off-by: Jarod Wilson <jarod@redhat.com>
---
crypto/ansi_cprng.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index 486aa93..a7c703d 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -161,7 +161,7 @@ static int _get_more_prng_bytes(struct prng_context *ctx)
/*
* Now update our DT value
*/
- for (i = 0; i < DEFAULT_BLK_SZ; i++) {
+ for (i = DEFAULT_BLK_SZ - 1; i >= 0; i--) {
ctx->DT[i] += 1;
if (ctx->DT[i] != 0)
break;
--
Jarod Wilson
jarod@redhat.com
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ansi_cprng: fix inverted DT increment routine
2008-11-13 16:36 [PATCH] crypto: ansi_cprng: fix inverted DT increment routine Jarod Wilson
@ 2008-11-13 18:44 ` Neil Horman
2008-11-24 13:20 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Neil Horman @ 2008-11-13 18:44 UTC (permalink / raw)
To: Jarod Wilson; +Cc: linux-crypto, herbert, davem, linux-kernel
On Thu, Nov 13, 2008 at 11:36:11AM -0500, Jarod Wilson wrote:
> The ANSI X9.31 PRNG docs aren't particularly clear on how to increment DT,
> but empirical testing shows we're incrementing from the wrong end. A 10,000
> iteration Monte Carlo RNG test currently winds up not getting the expected
> result.
>
> From http://csrc.nist.gov/groups/STM/cavp/documents/rng/RNGVS.pdf :
>
> # CAVS 4.3
> # ANSI931 MCT
> [X9.31]
> [AES 128-Key]
>
> COUNT = 0
> Key = 9f5b51200bf334b5d82be8c37255c848
> DT = 6376bbe52902ba3b67c925fa701f11ac
> V = 572c8e76872647977e74fbddc49501d1
> R = 48e9bd0d06ee18fbe45790d5c3fc9b73
>
> Currently, we get 0dd08496c4f7178bfa70a2161a79459a after 10000 loops.
>
> Inverting the DT increment routine results in us obtaining the expected result
> of 48e9bd0d06ee18fbe45790d5c3fc9b73. Verified on both x86_64 and ppc64.
>
> Signed-off-by: Jarod Wilson <jarod@redhat.com>
>
> ---
>
> crypto/ansi_cprng.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
> index 486aa93..a7c703d 100644
> --- a/crypto/ansi_cprng.c
> +++ b/crypto/ansi_cprng.c
> @@ -161,7 +161,7 @@ static int _get_more_prng_bytes(struct prng_context *ctx)
> /*
> * Now update our DT value
> */
> - for (i = 0; i < DEFAULT_BLK_SZ; i++) {
> + for (i = DEFAULT_BLK_SZ - 1; i >= 0; i--) {
> ctx->DT[i] += 1;
> if (ctx->DT[i] != 0)
> break;
>
> --
> Jarod Wilson
> jarod@redhat.com
>
>
Looks good, thanks Jarod!
Acked-by: Neil Horman <nhorman@tuxdriver.com>
--
/***************************************************
*Neil Horman
*nhorman@tuxdriver.com
*gpg keyid: 1024D / 0x92A74FA1
*http://pgp.mit.edu
***************************************************/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ansi_cprng: fix inverted DT increment routine
2008-11-13 18:44 ` Neil Horman
@ 2008-11-24 13:20 ` Herbert Xu
0 siblings, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2008-11-24 13:20 UTC (permalink / raw)
To: Neil Horman; +Cc: Jarod Wilson, linux-crypto, davem, linux-kernel
On Thu, Nov 13, 2008 at 01:44:31PM -0500, Neil Horman wrote:
> On Thu, Nov 13, 2008 at 11:36:11AM -0500, Jarod Wilson wrote:
> > The ANSI X9.31 PRNG docs aren't particularly clear on how to increment DT,
> > but empirical testing shows we're incrementing from the wrong end. A 10,000
> > iteration Monte Carlo RNG test currently winds up not getting the expected
> > result.
> >
> > From http://csrc.nist.gov/groups/STM/cavp/documents/rng/RNGVS.pdf :
> >
> > # CAVS 4.3
> > # ANSI931 MCT
> > [X9.31]
> > [AES 128-Key]
> >
> > COUNT = 0
> > Key = 9f5b51200bf334b5d82be8c37255c848
> > DT = 6376bbe52902ba3b67c925fa701f11ac
> > V = 572c8e76872647977e74fbddc49501d1
> > R = 48e9bd0d06ee18fbe45790d5c3fc9b73
> >
> > Currently, we get 0dd08496c4f7178bfa70a2161a79459a after 10000 loops.
> >
> > Inverting the DT increment routine results in us obtaining the expected result
> > of 48e9bd0d06ee18fbe45790d5c3fc9b73. Verified on both x86_64 and ppc64.
> >
> > Signed-off-by: Jarod Wilson <jarod@redhat.com>
Patch applied. Thanks!
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-11-24 13:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-13 16:36 [PATCH] crypto: ansi_cprng: fix inverted DT increment routine Jarod Wilson
2008-11-13 18:44 ` Neil Horman
2008-11-24 13:20 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox