Skip to contentSkip to conversation

: fix bad ERRPTR check in prng

cyrpto Neil Horman 1 participant 1 message Jul 15, 2008 Crypto API

lore
Share & tools
lore
#0 lore raw

Patch to correct a bad return code check from crypto_alloc_blkcipher Also correct Kconfig to pull in the needed ciphers to make prng work when its enabled

 Kconfig |    3 +++
 prng.c  |    8 ++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
crypto/Kconfig +3 -0
index ea50357..91e0d07 100644
@@ -670,6 +670,9 @@ comment "Random Number Generation"
 
 config CRYPTO_PRNG
 	tristate "Pseudo Random Number Generation for Cryptographic modules"
+	select CRYPTO_AES
+	select CRYPTO_CTR
+	depends on CRYPTO
 	help
 	  This option enables the generic pseudo random number generator
 	  for cryptographic modules.  Uses the Algorithm specified in
crypto/prng.c +6 -2
index 11b9306..b28f89a 100644
@@ -300,6 +300,9 @@ struct prng_context *alloc_prng_context(void)
 	struct prng_context *ctx = kzalloc(sizeof(struct prng_context),
 					GFP_KERNEL);
 
+	if (!ctx)
+		return NULL;
+
 	spin_lock_init(&ctx->prng_lock);
 
 	if (reset_prng_context(ctx, NULL, NULL, NULL, NULL)) {
@@ -357,9 +360,10 @@ int reset_prng_context(struct prng_context *ctx,
 		crypto_free_blkcipher(ctx->tfm);
 
 	ctx->tfm = crypto_alloc_blkcipher("rfc3686(ctr(aes))", 0, 0);
-	if (!ctx->tfm) {
+	if (IS_ERR(ctx->tfm)) {
 		dbgprint(KERN_CRIT "Failed to alloc tfm for context %p\n",
-			ctx->tfm);
+			ctx);
+		ctx->tfm = NULL;
 		goto out;
 	}
 
Signature · 4 lines
/****************************************************
 * Neil Horman <[email protected]>
 * Software Engineer, Red Hat
 ****************************************************/