Blame SOURCES/openssl-fips-0.9.8e-rng-seed.patch

5820f5
Seed the FIPS rng directly from the kernel random device.
5820f5
diff -up openssl-fips-0.9.8e/crypto/rand/rand_lcl.h.rng-seed openssl-fips-0.9.8e/crypto/rand/rand_lcl.h
5820f5
--- openssl-fips-0.9.8e/crypto/rand/rand_lcl.h.rng-seed	2009-04-15 13:48:50.000000000 +0200
5820f5
+++ openssl-fips-0.9.8e/crypto/rand/rand_lcl.h	2009-04-15 13:48:51.000000000 +0200
5820f5
@@ -112,7 +112,7 @@
5820f5
 #ifndef HEADER_RAND_LCL_H
5820f5
 #define HEADER_RAND_LCL_H
5820f5
 
5820f5
-#define ENTROPY_NEEDED 32  /* require 256 bits = 32 bytes of randomness */
5820f5
+#define ENTROPY_NEEDED 48  /* we need 48 bytes of randomness for FIPS rng */
5820f5
 
5820f5
 
5820f5
 #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
5820f5
diff -up openssl-fips-0.9.8e/fips/fips.c.rng-seed openssl-fips-0.9.8e/fips/fips.c
5820f5
--- openssl-fips-0.9.8e/fips/fips.c.rng-seed	2009-04-15 13:48:51.000000000 +0200
5820f5
+++ openssl-fips-0.9.8e/fips/fips.c	2009-04-15 13:48:51.000000000 +0200
5820f5
@@ -508,22 +508,22 @@ int FIPS_mode_set(int onoff)
5820f5
 	    goto end;
5820f5
 	    }
5820f5
 
5820f5
+	/* now switch into FIPS mode */
5820f5
+	fips_set_rand_check(FIPS_rand_method());
5820f5
+	RAND_set_rand_method(FIPS_rand_method());
5820f5
+
5820f5
 	/* automagically seed PRNG if not already seeded */
5820f5
 	if(!FIPS_rand_status())
5820f5
 	    {
5820f5
-	    if(RAND_bytes(buf,sizeof buf) <= 0)
5820f5
+	    RAND_poll();
5820f5
+	    if (!FIPS_rand_status())
5820f5
 		{
5820f5
 		fips_selftest_fail = 1;
5820f5
 		ret = 0;
5820f5
 		goto end;
5820f5
 		}
5820f5
-	    FIPS_rand_set_key(buf,32);
5820f5
-	    FIPS_rand_seed(buf+32,16);
5820f5
 	    }
5820f5
 
5820f5
-	/* now switch into FIPS mode */
5820f5
-	fips_set_rand_check(FIPS_rand_method());
5820f5
-	RAND_set_rand_method(FIPS_rand_method());
5820f5
 	if(FIPS_selftest())
5820f5
 	    fips_set_mode(1);
5820f5
 	else
5820f5
diff -up openssl-fips-0.9.8e/fips/rand/fips_rand.c.rng-seed openssl-fips-0.9.8e/fips/rand/fips_rand.c
5820f5
--- openssl-fips-0.9.8e/fips/rand/fips_rand.c.rng-seed	2007-09-12 19:46:05.000000000 +0200
5820f5
+++ openssl-fips-0.9.8e/fips/rand/fips_rand.c	2009-06-29 18:34:00.000000000 +0200
5820f5
@@ -155,7 +155,18 @@ static int fips_set_prng_seed(FIPS_PRNG_
5820f5
 	{
5820f5
 	int i;
5820f5
 	if (!ctx->keyed)
5820f5
-		return 0;
5820f5
+		{
5820f5
+		FIPS_RAND_SIZE_T keylen = 16;
5820f5
+
5820f5
+		if (seedlen - keylen < AES_BLOCK_LENGTH)
5820f5
+			return 0;
5820f5
+		if (seedlen - keylen - 8 >= AES_BLOCK_LENGTH)
5820f5
+			keylen += 8;
5820f5
+		if (seedlen - keylen - 8 >= AES_BLOCK_LENGTH)
5820f5
+			keylen += 8;
5820f5
+		seedlen -= keylen;
5820f5
+		fips_set_prng_key(ctx, seed+seedlen, keylen);
5820f5
+		}
5820f5
 	/* In test mode seed is just supplied data */
5820f5
 	if (ctx->test_mode)
5820f5
 		{
5820f5
@@ -276,6 +287,7 @@ static int fips_rand(FIPS_PRNG_CTX *ctx,
5820f5
 	unsigned char R[AES_BLOCK_LENGTH], I[AES_BLOCK_LENGTH];
5820f5
 	unsigned char tmp[AES_BLOCK_LENGTH];
5820f5
 	int i;
5820f5
+	FIPS_selftest_check();
5820f5
 	if (ctx->error)
5820f5
 		{
5820f5
 		RANDerr(RAND_F_FIPS_RAND,RAND_R_PRNG_ERROR);