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

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