Linux cryptographic layer development
 help / color / mirror / Atom feed
From: "George Spelvin" <linux@horizon.com>
To: herbert@gondor.apana.org.au, jarod@redhat.com,
	nhorman@tuxdriver.com, stephan.mueller@atsec.com
Cc: linux-crypto@vger.kernel.org
Subject: Is ansi_cprng.c supposed to be an implmentation of X9.31?
Date: 28 Nov 2014 18:23:51 -0500	[thread overview]
Message-ID: <20141128232351.27607.qmail@ns.horizon.com> (raw)

I've been trying to understand the crypto layer, and it's a bit of a
struggle because I'm trying to learn how it's supposed to work by
reading the code, and I keep finding code I want to fix.

ansi_cprng.c is the current itch I'm eager to scratch.

Other than enough implementation stupidities to make me scream
(particularly the "rand_data_valid" variable name which is actually a
count of INvalid data, and  keeping 5 blocks of state, including sensitive
previous output, when only 3 are needed), one thing I can't help noticing
is that this is definitely NOT conformant with the X9.17/X9.31 spec.

That's because the spec requires a timestamp for each output block
to provide additional entropy, and a counter won't cut it.

I'm fixing the obvious things, but on this point, I have two choices:

1. Add some comments clarifying that the "Based on" part of the header
   is anything but a claim of compliance; those specs are for an RNG,
   while this is a PRNG.  And probably delete all the FIPS stuff, as
   there's no spec to claim compliance with.  Or
2. Fix the code to use random_get_entropy() and jiffies for the
   DT seed vector.

In the latter case, I'd have to leave the current deterministic code as
an option for self-testing, but I'd drop the recommended seedsize
to DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ (one key and one IV), and have
an internal flag indicating whether to use an incrementing DT vector
or generate it fresh.

If some code (like the current self-test code) provides an extra
DEFAULT_BLK_SZ of seed material, it would go into determinsitic mode,
but if it's missing, DT would be generated dynamically.

But that's a question of design intent, and I can't intuit that from the
code.  Can someome enlighten me as to which option is preferred?

             reply	other threads:[~2014-11-28 23:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-28 23:23 George Spelvin [this message]
2014-11-29 17:58 ` Is ansi_cprng.c supposed to be an implmentation of X9.31? Neil Horman
2014-11-29 19:32   ` George Spelvin
2014-11-30  1:16     ` Neil Horman
2014-11-30 14:36     ` Stephan Mueller
2014-12-02  4:55       ` George Spelvin
2014-12-02 13:22         ` Neil Horman
2014-12-02 17:56           ` George Spelvin
2014-11-30 14:31   ` Stephan Mueller
2014-11-30 14:26 ` Stephan Mueller
2014-12-02  5:39   ` George Spelvin
2014-12-02 13:44     ` Neil Horman
2014-12-02 19:43       ` George Spelvin

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=20141128232351.27607.qmail@ns.horizon.com \
    --to=linux@horizon.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jarod@redhat.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=stephan.mueller@atsec.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