diff options
author | Neil Horman <nhorman@tuxdriver.com> | 2008-11-04 23:13:14 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-12-24 19:01:21 -0500 |
commit | 2566578a6feb9d9e39da41326afe8ed6022db3c5 (patch) | |
tree | 4fb341d8912afbf5b1c47e0938f251210843ef2d /crypto/ansi_cprng.c | |
parent | 420a4b20c504e4674bf253601f793bdb254f99fa (diff) |
crypto: ansi_cprng - Allow resetting of DT value
This is a patch that was sent to me by Jarod Wilson, marking off my
outstanding todo to allow the ansi cprng to set/reset the DT counter value in a
cprng instance. Currently crytpo_rng_reset accepts a seed byte array which is
interpreted by the ansi_cprng as a {V key} tuple. This patch extends that tuple
to now be {V key DT}, with DT an optional value during reset. This patch also
fixes a bug we noticed in which the offset of the key area of the seed is
started at DEFAULT_PRNG_KSZ rather than DEFAULT_BLK_SZ as it should be.
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/ansi_cprng.c')
-rw-r--r-- | crypto/ansi_cprng.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c index 72db0fd763cc..486aa93646f7 100644 --- a/crypto/ansi_cprng.c +++ b/crypto/ansi_cprng.c | |||
@@ -349,15 +349,25 @@ static int cprng_get_random(struct crypto_rng *tfm, u8 *rdata, | |||
349 | return get_prng_bytes(rdata, dlen, prng); | 349 | return get_prng_bytes(rdata, dlen, prng); |
350 | } | 350 | } |
351 | 351 | ||
352 | /* | ||
353 | * This is the cprng_registered reset method the seed value is | ||
354 | * interpreted as the tuple { V KEY DT} | ||
355 | * V and KEY are required during reset, and DT is optional, detected | ||
356 | * as being present by testing the length of the seed | ||
357 | */ | ||
352 | static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen) | 358 | static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen) |
353 | { | 359 | { |
354 | struct prng_context *prng = crypto_rng_ctx(tfm); | 360 | struct prng_context *prng = crypto_rng_ctx(tfm); |
355 | u8 *key = seed + DEFAULT_PRNG_KSZ; | 361 | u8 *key = seed + DEFAULT_BLK_SZ; |
362 | u8 *dt = NULL; | ||
356 | 363 | ||
357 | if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ) | 364 | if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ) |
358 | return -EINVAL; | 365 | return -EINVAL; |
359 | 366 | ||
360 | reset_prng_context(prng, key, DEFAULT_PRNG_KSZ, seed, NULL); | 367 | if (slen >= (2 * DEFAULT_BLK_SZ + DEFAULT_PRNG_KSZ)) |
368 | dt = key + DEFAULT_PRNG_KSZ; | ||
369 | |||
370 | reset_prng_context(prng, key, DEFAULT_PRNG_KSZ, seed, dt); | ||
361 | 371 | ||
362 | if (prng->flags & PRNG_NEED_RESET) | 372 | if (prng->flags & PRNG_NEED_RESET) |
363 | return -EINVAL; | 373 | return -EINVAL; |
@@ -379,7 +389,7 @@ static struct crypto_alg rng_alg = { | |||
379 | .rng = { | 389 | .rng = { |
380 | .rng_make_random = cprng_get_random, | 390 | .rng_make_random = cprng_get_random, |
381 | .rng_reset = cprng_reset, | 391 | .rng_reset = cprng_reset, |
382 | .seedsize = DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ, | 392 | .seedsize = DEFAULT_PRNG_KSZ + 2*DEFAULT_BLK_SZ, |
383 | } | 393 | } |
384 | } | 394 | } |
385 | }; | 395 | }; |