Blow up in people's faces if they don't reseed.
authorBen Laurie <ben@openssl.org>
Wed, 12 May 2004 14:11:10 +0000 (14:11 +0000)
committerBen Laurie <ben@openssl.org>
Wed, 12 May 2004 14:11:10 +0000 (14:11 +0000)
crypto/rand/rand.h
crypto/rand/rand_err.c
fips/fingerprint.sha1
fips/fips.c
fips/rand/fingerprint.sha1
fips/rand/fips_rand.c

index b22dd613fbba8ae538357d321f062e524da42779..f8a369794aef03c6c53e803a050ccab748a5315f 100644 (file)
@@ -127,6 +127,8 @@ void ERR_load_RAND_strings(void);
 
 /* Reason codes. */
 #define RAND_R_NON_FIPS_METHOD                          101
+#define RAND_R_PRNG_NOT_REKEYED                                 103
+#define RAND_R_PRNG_NOT_RESEEDED                        104
 #define RAND_R_PRNG_NOT_SEEDED                          100
 #define RAND_R_PRNG_STUCK                               102
 
index b8083094966dbd3fd94bc357c1b858bf3be5fac2..6a6ae3e9f672867255e565e37f5a785583f4b90d 100644 (file)
@@ -75,6 +75,8 @@ static ERR_STRING_DATA RAND_str_functs[]=
 static ERR_STRING_DATA RAND_str_reasons[]=
        {
 {RAND_R_NON_FIPS_METHOD                  ,"non fips method"},
+{RAND_R_PRNG_NOT_REKEYED                 ,"prng not rekeyed"},
+{RAND_R_PRNG_NOT_RESEEDED                ,"prng not reseeded"},
 {RAND_R_PRNG_NOT_SEEDED                  ,"PRNG not seeded"},
 {RAND_R_PRNG_STUCK                       ,"prng stuck"},
 {0,NULL}
index ff911c04c505bb94175cfad9371fe27c6a86d2b6..7e6d85afeab002fdf93fa89accdd30f78b7d3764 100644 (file)
@@ -1,4 +1,4 @@
-HMAC-SHA1(fips.c)= 5b66ece7a9df3e471f21937165887be733f251e0
+HMAC-SHA1(fips.c)= 01d0a11be4f9c2cb2b2a57ab6ec473f61b206de6
 HMAC-SHA1(fips_err_wrapper.c)= d3e2be316062510312269e98f964cb87e7577898
 HMAC-SHA1(fips.h)= 4496c0e51c18d30bdc0ce440c384886870a61c40
 HMAC-SHA1(fips_err.h)= f4203a47100a815c21cf3a97092f91a595938f7c
index 912bb9d1f771d18a788a92813790b7ce97ba098c..3a1a733be6243948eb3145bf5386f66d5452294c 100644 (file)
@@ -150,7 +150,11 @@ int FIPS_mode_set(int onoff,const char *path)
        /* automagically seed PRNG if not already seeded */
        if(!FIPS_rand_seeded())
            {
-           RAND_bytes(buf,sizeof buf);
+           if(RAND_bytes(buf,sizeof buf) <= 0)
+               {
+               FIPS_selftest_fail=1;
+               return 0;
+               }
            FIPS_set_prng_key(buf,buf+8);
            FIPS_rand_seed(buf+16,8);
            }
index 493cba205cbcacb4c14f57bdeca5286d4d0f4aea..11421113e08f1bfce07ec17afa5485489c5bc72a 100644 (file)
@@ -1,2 +1,2 @@
-HMAC-SHA1(fips_rand.c)= dfc608a14c5c674e9923d08bd9bb5c4b7f1bf615
+HMAC-SHA1(fips_rand.c)= 58be68c405269c9a4c35ee19642c4da982374769
 HMAC-SHA1(fips_rand.h)= 889afc9a526fe59138326134950b733627a7e9cf
index e1557edd90a1f354f5426b54c29a9202f4df5a88..2ff197ebb07754d4f25988b15d2e82e9fde18d81 100644 (file)
@@ -84,6 +84,11 @@ static int key_set;
 static int test_mode;
 static unsigned char test_faketime[8];
 
+#ifndef GETPID_IS_MEANINGLESS
+static int seed_pid;
+static int key_pid;
+#endif
+
 static void fips_rand_cleanup(void);
 static void fips_rand_add(const void *buf, int num, double add_entropy);
 static int fips_rand_bytes(unsigned char *buf, int num);
@@ -111,6 +116,9 @@ void FIPS_set_prng_key(const unsigned char k1[8],const unsigned char k2[8])
     memcpy(&key1,k1,sizeof key1);
     memcpy(&key2,k2,sizeof key2);
     key_set=1;
+#ifndef GETPID_IS_MEANINGLESS
+    key_pid=getpid();
+#endif
     second=0;
     }
 
@@ -224,6 +232,10 @@ void FIPS_rand_seed(const void *buf_, int num)
            n_seed+=t;
        }
 
+#ifndef GETPID_IS_MEANINGLESS
+    seed_pid=getpid();
+#endif
+
     CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
     }
 
@@ -239,6 +251,9 @@ static int fips_rand_bytes(unsigned char *buf,int num)
     unsigned char intermediate[SEED_SIZE];
     unsigned char output[SEED_SIZE];
     static unsigned char previous[SEED_SIZE];
+#ifndef GETPID_IS_MEANINGLESS
+    int pid;
+#endif
 
     if(n_seed < sizeof seed)
        {
@@ -246,6 +261,20 @@ static int fips_rand_bytes(unsigned char *buf,int num)
        return 0;
        }
 
+#ifndef GETPID_IS_MEANINGLESS
+    pid=getpid();
+    if(pid != seed_pid)
+       {
+       RANDerr(RAND_F_FIPS_RAND_BYTES,RAND_R_PRNG_NOT_RESEEDED);
+       return 0;
+       }
+    if(pid != key_pid)
+       {
+       RANDerr(RAND_F_FIPS_RAND_BYTES,RAND_R_PRNG_NOT_REKEYED);
+       return 0;
+       }
+#endif
+
     fips_gettime(timeseed);
     fips_rand_encrypt(intermediate,timeseed);