linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] crypto: make the seed() function optional
@ 2017-09-13 20:09 Mathieu Malaterre
  2017-10-07  3:33 ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Malaterre @ 2017-09-13 20:09 UTC (permalink / raw)
  Cc: PrasannaKumar Muralidharan, Mathieu Malaterre, Neil Horman,
	Herbert Xu, David S. Miller, linux-crypto, linux-kernel

This makes it simplier for driver author to not provide the seed() function
in case of a pseudo RNG where the seed operation is a no-op.

Document that the seed() function pointer is optional in header.

Signed-off-by: Mathieu Malaterre <malat@debian.org>
---
The PRNG as found on Ingenic JZ4780 is one such example. This is found on a
MIPS Creator CI20 SoC.

 crypto/rng.c         | 7 ++++++-
 include/crypto/rng.h | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/crypto/rng.c b/crypto/rng.c
index 5e8469244960..ed08581901a9 100644
--- a/crypto/rng.c
+++ b/crypto/rng.c
@@ -35,9 +35,14 @@ static int crypto_default_rng_refcnt;
 
 int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
 {
+	struct rng_alg *ralg = crypto_rng_alg(tfm);
 	u8 *buf = NULL;
 	int err;
 
+	/* In case of PRNG, no need to seed */
+	if (!ralg->seed)
+		return 0;
+
 	if (!seed && slen) {
 		buf = kmalloc(slen, GFP_KERNEL);
 		if (!buf)
@@ -47,7 +52,7 @@ int crypto_rng_reset(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
 		seed = buf;
 	}
 
-	err = crypto_rng_alg(tfm)->seed(tfm, seed, slen);
+	err = ralg->seed(tfm, seed, slen);
 
 	kzfree(buf);
 	return err;
diff --git a/include/crypto/rng.h b/include/crypto/rng.h
index b95ede354a66..ac5d061d0297 100644
--- a/include/crypto/rng.h
+++ b/include/crypto/rng.h
@@ -32,7 +32,7 @@ struct crypto_rng;
  *		random number generator requires a seed for setting
  *		up a new state, the seed must be provided by the
  *		consumer while invoking this function. The required
- *		size of the seed is defined with @seedsize .
+ *		size of the seed is defined with @seedsize. Optional.
  * @set_ent:	Set entropy that would otherwise be obtained from
  *		entropy source.  Internal use only.
  * @seedsize:	The seed size required for a random number generator
-- 
2.11.0

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

* Re: [RFC PATCH] crypto: make the seed() function optional
  2017-09-13 20:09 [RFC PATCH] crypto: make the seed() function optional Mathieu Malaterre
@ 2017-10-07  3:33 ` Herbert Xu
  2017-10-08 14:11   ` PrasannaKumar Muralidharan
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2017-10-07  3:33 UTC (permalink / raw)
  To: Mathieu Malaterre
  Cc: prasannatsmkumar, malat, nhorman, davem, linux-crypto, linux-kernel

Mathieu Malaterre <malat@debian.org> wrote:
> This makes it simplier for driver author to not provide the seed() function
> in case of a pseudo RNG where the seed operation is a no-op.
> 
> Document that the seed() function pointer is optional in header.
> 
> Signed-off-by: Mathieu Malaterre <malat@debian.org>
> ---
> The PRNG as found on Ingenic JZ4780 is one such example. This is found on a
> MIPS Creator CI20 SoC.

So how does it seed itself? This also contradicts with the JZ4780
driver that's currently in the patch queue as it does contain a
seed function.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [RFC PATCH] crypto: make the seed() function optional
  2017-10-07  3:33 ` Herbert Xu
@ 2017-10-08 14:11   ` PrasannaKumar Muralidharan
  0 siblings, 0 replies; 3+ messages in thread
From: PrasannaKumar Muralidharan @ 2017-10-08 14:11 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Mathieu Malaterre, nhorman, David S . Miller, linux-crypto, linux-kernel

Hi Herbert,

On 7 October 2017 at 09:03, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> Mathieu Malaterre <malat@debian.org> wrote:
>> This makes it simplier for driver author to not provide the seed() function
>> in case of a pseudo RNG where the seed operation is a no-op.
>>
>> Document that the seed() function pointer is optional in header.
>>
>> Signed-off-by: Mathieu Malaterre <malat@debian.org>
>> ---
>> The PRNG as found on Ingenic JZ4780 is one such example. This is found on a
>> MIPS Creator CI20 SoC.
>
> So how does it seed itself? This also contradicts with the JZ4780
> driver that's currently in the patch queue as it does contain a
> seed function.

The current version of JZ4780 driver in the patch queue indeed has
seed function. But when Mathieu sent this email based on v2 of the
driver. V2 did not have seed callback. Using v2 resulted in a NULL
pointer in kernel. This patch prevents that NULL pointer access.

Regardless of what JZ4780 driver has this patch makes sense.

Currently crypto framework does not mandate seed callback's presence.
If mandatory, crypto framework should error out if seed is not
implemented while registering the PRNG.

Thanks,
PrasannaKumar

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

end of thread, other threads:[~2017-10-08 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-13 20:09 [RFC PATCH] crypto: make the seed() function optional Mathieu Malaterre
2017-10-07  3:33 ` Herbert Xu
2017-10-08 14:11   ` PrasannaKumar Muralidharan

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