Integrate my implementation of a countermeasure against
[openssl.git] / crypto / bn / exptest.c
index d64905df1b59c70f92463d987b0d3117b212a9f2..3e86f2ea0e0b3897a24e437b38a73824e1993110 100644 (file)
@@ -69,6 +69,8 @@
 
 #define NUM_BITS       (BN_BITS*2)
 
+static const char rnd_seed[] = "string to make the random number generator think it has entropy";
+
 int main(int argc, char *argv[])
        {
        BN_CTX *ctx;
@@ -77,6 +79,10 @@ int main(int argc, char *argv[])
        unsigned char c;
        BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m;
 
+       RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't
+                                              * even check its return value
+                                              * (which we should) */
+
        ERR_load_BN_strings();
 
        ctx=BN_CTX_new();
@@ -167,6 +173,7 @@ int main(int argc, char *argv[])
        BN_free(b);
        BN_free(m);
        BN_CTX_free(ctx);
+       ERR_remove_state(0);
        CRYPTO_mem_leaks(out);
        BIO_free(out);
        printf(" done\n");