New functions CRYPTO_set_idptr_callback(),
[openssl.git] / crypto / rand / md_rand.c
index eeffc0df4cb3e9aaab348e776d249a32c15574eb..4aa13f715646eb35ff7249b25ab390ba4eb9ce60 100644 (file)
@@ -145,7 +145,8 @@ static unsigned int crypto_lock_rand = 0; /* may be set only when a thread
                                            * holds CRYPTO_LOCK_RAND
                                            * (to prevent double locking) */
 /* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */
-static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */
+static unsigned long locking_thread_id = 0; /* valid iff crypto_lock_rand is set */
+static void *locking_thread_idptr = NULL; /* valid iff crypto_lock_rand is set */
 
 
 #ifdef PREDICT
@@ -214,7 +215,7 @@ static void ssleay_rand_add(const void *buf, int num, double add)
        if (crypto_lock_rand)
                {
                CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
-               do_not_lock = (locking_thread == CRYPTO_thread_id());
+               do_not_lock = (locking_thread_id == CRYPTO_thread_id()) && (locking_thread_idptr == CRYPTO_thread_idptr());
                CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
                }
        else
@@ -300,7 +301,7 @@ static void ssleay_rand_add(const void *buf, int num, double add)
         * other thread's seeding remains without effect (except for
         * the incremented counter).  By XORing it we keep at least as
         * much entropy as fits into md. */
-       for (k = 0; k < sizeof md; k++)
+       for (k = 0; k < (int)sizeof(md); k++)
                {
                md[k] ^= local_md[k];
                }
@@ -315,7 +316,7 @@ static void ssleay_rand_add(const void *buf, int num, double add)
 
 static void ssleay_rand_seed(const void *buf, int num)
        {
-       ssleay_rand_add(buf, num, num);
+       ssleay_rand_add(buf, num, (double)num);
        }
 
 static int ssleay_rand_bytes(unsigned char *buf, int num)
@@ -372,7 +373,8 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
 
        /* prevent ssleay_rand_bytes() from trying to obtain the lock again */
        CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
-       locking_thread = CRYPTO_thread_id();
+       locking_thread_id = CRYPTO_thread_id();
+       locking_thread_idptr = CRYPTO_thread_idptr();
        CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
        crypto_lock_rand = 1;
 
@@ -520,7 +522,7 @@ static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num)
                err = ERR_peek_error();
                if (ERR_GET_LIB(err) == ERR_LIB_RAND &&
                    ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED)
-                       (void)ERR_get_error();
+                       ERR_clear_error();
                }
        return (ret);
        }
@@ -535,7 +537,7 @@ static int ssleay_rand_status(void)
        if (crypto_lock_rand)
                {
                CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
-               do_not_lock = (locking_thread == CRYPTO_thread_id());
+               do_not_lock = (locking_thread_id == CRYPTO_thread_id()) && (locking_thread_idptr == CRYPTO_thread_idptr());
                CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
                }
        else
@@ -547,7 +549,8 @@ static int ssleay_rand_status(void)
                
                /* prevent ssleay_rand_bytes() from trying to obtain the lock again */
                CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
-               locking_thread = CRYPTO_thread_id();
+               locking_thread_id = CRYPTO_thread_id();
+               locking_thread_idptr = CRYPTO_thread_idptr();
                CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
                crypto_lock_rand = 1;
                }