LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] crypto: extend ansi_cprng to allow resetting of DT value
@ 2008-11-03 21:22 Neil Horman
2008-11-04 21:04 ` Jarod Wilson
0 siblings, 1 reply; 3+ messages in thread
From: Neil Horman @ 2008-11-03 21:22 UTC (permalink / raw)
To: herbert, davem, linux-crypto, linux-kernel; +Cc: nhorman, jarod
Hey all-
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.
Regards
Neil
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
ansi_cprng.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index 72db0fd..486aa93 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,
return get_prng_bytes(rdata, dlen, prng);
}
+/*
+ * This is the cprng_registered reset method the seed value is
+ * interpreted as the tuple { V KEY DT}
+ * V and KEY are required during reset, and DT is optional, detected
+ * as being present by testing the length of the seed
+ */
static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
{
struct prng_context *prng = crypto_rng_ctx(tfm);
- u8 *key = seed + DEFAULT_PRNG_KSZ;
+ u8 *key = seed + DEFAULT_BLK_SZ;
+ u8 *dt = NULL;
if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ)
return -EINVAL;
- reset_prng_context(prng, key, DEFAULT_PRNG_KSZ, seed, NULL);
+ if (slen >= (2 * DEFAULT_BLK_SZ + DEFAULT_PRNG_KSZ))
+ dt = key + DEFAULT_PRNG_KSZ;
+
+ reset_prng_context(prng, key, DEFAULT_PRNG_KSZ, seed, dt);
if (prng->flags & PRNG_NEED_RESET)
return -EINVAL;
@@ -379,7 +389,7 @@ static struct crypto_alg rng_alg = {
.rng = {
.rng_make_random = cprng_get_random,
.rng_reset = cprng_reset,
- .seedsize = DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ,
+ .seedsize = DEFAULT_PRNG_KSZ + 2*DEFAULT_BLK_SZ,
}
}
};
--
/****************************************************
* Neil Horman <nhorman@tuxdriver.com>
* Software Engineer, Red Hat
****************************************************/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: extend ansi_cprng to allow resetting of DT value
2008-11-03 21:22 [PATCH] crypto: extend ansi_cprng to allow resetting of DT value Neil Horman
@ 2008-11-04 21:04 ` Jarod Wilson
2008-11-05 4:13 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Jarod Wilson @ 2008-11-04 21:04 UTC (permalink / raw)
To: Neil Horman; +Cc: herbert, davem, linux-crypto, linux-kernel
On Monday 03 November 2008 16:22:40 Neil Horman wrote:
> Hey all-
> 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.
>
> Regards
> Neil
>
> Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Even better than my original version, since it lets providing a DT value be
optional. Go ahead and slap this on there too:
Signed-off-by: Jarod Wilson <jarod@redhat.com>
> ansi_cprng.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
>
> diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
> index 72db0fd..486aa93 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, return get_prng_bytes(rdata, dlen, prng);
> }
>
> +/*
> + * This is the cprng_registered reset method the seed value is
> + * interpreted as the tuple { V KEY DT}
> + * V and KEY are required during reset, and DT is optional, detected
> + * as being present by testing the length of the seed
> + */
> static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int
> slen) {
> struct prng_context *prng = crypto_rng_ctx(tfm);
> - u8 *key = seed + DEFAULT_PRNG_KSZ;
> + u8 *key = seed + DEFAULT_BLK_SZ;
> + u8 *dt = NULL;
>
> if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ)
> return -EINVAL;
>
> - reset_prng_context(prng, key, DEFAULT_PRNG_KSZ, seed, NULL);
> + if (slen >= (2 * DEFAULT_BLK_SZ + DEFAULT_PRNG_KSZ))
> + dt = key + DEFAULT_PRNG_KSZ;
> +
> + reset_prng_context(prng, key, DEFAULT_PRNG_KSZ, seed, dt);
>
> if (prng->flags & PRNG_NEED_RESET)
> return -EINVAL;
> @@ -379,7 +389,7 @@ static struct crypto_alg rng_alg = {
> .rng = {
> .rng_make_random = cprng_get_random,
> .rng_reset = cprng_reset,
> - .seedsize = DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ,
> + .seedsize = DEFAULT_PRNG_KSZ + 2*DEFAULT_BLK_SZ,
> }
> }
> };
--
Jarod Wilson
jarod@redhat.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-11-05 4:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-03 21:22 [PATCH] crypto: extend ansi_cprng to allow resetting of DT value Neil Horman
2008-11-04 21:04 ` Jarod Wilson
2008-11-05 4:13 ` Herbert Xu
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).