linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Is ansi_cprng.c supposed to implement X9.17/X9.31's RNG?
@ 2014-11-29  2:43 George Spelvin
  2014-11-29 17:26 ` George Spelvin
  0 siblings, 1 reply; 39+ messages in thread
From: George Spelvin @ 2014-11-29  2:43 UTC (permalink / raw)
  To: herbert, jarod, nhorman; +Cc: linux, linux-crypto

I'm trying to understand the Linux crypto layer, and a lot of
the code I read for guidance I instead end up wanting to fix.

My current itch to scratch is crypto/ansi_cprng.c.

There is a lot of questionable code I'll submit patches for, particularly:

- The "rand_data_valid" variable, which is actually the amount of
  INvalid data in ctx->rand_data[].  (I'm renaming it to rand_data_pos.)
- The ctx->I and ctx->last_rand_data buffers, which are completely
  unnecessary (and in the latter case, violate anti-backtracking).
- The fact that cprng_init() calls reset_prng_context() with NULL
  key and V inputs, and the latter has special-case code to handle
  that, when cprng_init() sets PRNG_NEED_RESET, so can just omit
  the call entirely.

But there's one thing that I can't figure out, and that is whether
the code is meant to be an implementation of the ANSI X9.17/X9.31 RNG.

It's currently definitely not, because the spec requires periodic input
of a timestamp with some seed entropy, while the code just uses
an incrementing counter.

So I have two paths available:

1. Clarify in comments that, although "Based on" X9.31 Appendix A.2.4,
   this is very much NOT an implementation thereof.  This is a fully
   deterministic PRNG, while the spec is for an RNG.
2. Alternativelt, change the code to actually use high-resolution
   timestamps for seed material.

In the latter case, I'd use jiffies and random_get_entropy, and provide
a compatible deterministic option for self-testing.  I'd drop the
recommended seedsize to DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ, but keep the
current implementation's support for an optional starting DT value.

If it isn't provided (the default), the code would generate it fresh
on each call to _get_more_prng_bytes, rather than the current default
to zero.

My problem is I don't know which option is intended.  Is it guaranteed that
CRYPTO_ALG_TYPE_RNG is deterministic?

^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2014-12-05 11:29 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).