Skip to content

Commit

Permalink
crypto: ansi_cprng - enforce key != seed in fips mode
Browse files Browse the repository at this point in the history
Apparently, NIST is tightening up its requirements for FIPS validation
with respect to RNGs. Its always been required that in fips mode, the
ansi cprng not be fed key and seed material that was identical, but
they're now interpreting FIPS 140-2, section AS07.09 as requiring that
the implementation itself must enforce the requirement. Easy fix, we
just do a memcmp of key and seed in fips_cprng_reset and call it a day.

v2: Per Neil's advice, ensure slen is sufficiently long before we
compare key and seed to avoid looking at potentially unallocated mem.

CC: Stephan Mueller <[email protected]>
CC: Steve Grubb <[email protected]>
Signed-off-by: Jarod Wilson <[email protected]>
Acked-by: Neil Horman <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
jarodwilson authored and herbertx committed Nov 9, 2011
1 parent bae6d30 commit 505172e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crypto/ansi_cprng.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,18 @@ static int fips_cprng_get_random(struct crypto_rng *tfm, u8 *rdata,
static int fips_cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
{
u8 rdata[DEFAULT_BLK_SZ];
u8 *key = seed + DEFAULT_BLK_SZ;
int rc;

struct prng_context *prng = crypto_rng_ctx(tfm);

if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ)
return -EINVAL;

/* fips strictly requires seed != key */
if (!memcmp(seed, key, DEFAULT_PRNG_KSZ))
return -EINVAL;

rc = cprng_reset(tfm, seed, slen);

if (!rc)
Expand Down

0 comments on commit 505172e

Please sign in to comment.