]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - crypto/bn/exptest.c
Netware-specific changes,
[thirdparty/openssl.git] / crypto / bn / exptest.c
index d64905df1b59c70f92463d987b0d3117b212a9f2..37aec55b893da755cdff81696d2e1094f491380d 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#include "../e_os.h"
+
 #include <openssl/bio.h>
 #include <openssl/bn.h>
 #include <openssl/rand.h>
 #include <openssl/err.h>
-#ifdef WINDOWS
-#include "../bio/bss_file.c"
-#endif
 
 #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,10 +79,14 @@ 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();
-       if (ctx == NULL) exit(1);
+       if (ctx == NULL) EXIT(1);
        r_mont=BN_new();
        r_recp=BN_new();
        r_simple=BN_new();
@@ -93,7 +99,7 @@ int main(int argc, char *argv[])
 
        out=BIO_new(BIO_s_file());
 
-       if (out == NULL) exit(1);
+       if (out == NULL) EXIT(1);
        BIO_set_fp(out,stdout,BIO_NOCLOSE);
 
        for (i=0; i<200; i++)
@@ -118,7 +124,7 @@ int main(int argc, char *argv[])
                        {
                        printf("BN_mod_exp_mont() problems\n");
                        ERR_print_errors(out);
-                       exit(1);
+                       EXIT(1);
                        }
 
                ret=BN_mod_exp_recp(r_recp,a,b,m,ctx);
@@ -126,7 +132,7 @@ int main(int argc, char *argv[])
                        {
                        printf("BN_mod_exp_recp() problems\n");
                        ERR_print_errors(out);
-                       exit(1);
+                       EXIT(1);
                        }
 
                ret=BN_mod_exp_simple(r_simple,a,b,m,ctx);
@@ -134,7 +140,7 @@ int main(int argc, char *argv[])
                        {
                        printf("BN_mod_exp_simple() problems\n");
                        ERR_print_errors(out);
-                       exit(1);
+                       EXIT(1);
                        }
 
                if (BN_cmp(r_simple, r_mont) == 0
@@ -157,7 +163,7 @@ int main(int argc, char *argv[])
                        printf("\nrecp     ="); BN_print(out,r_recp);
                        printf("\nmont     ="); BN_print(out,r_mont);
                        printf("\n");
-                       exit(1);
+                       EXIT(1);
                        }
                }
        BN_free(r_mont);
@@ -167,14 +173,18 @@ 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");
-       exit(0);
+       EXIT(0);
 err:
        ERR_load_crypto_strings();
        ERR_print_errors(out);
-       exit(1);
+#ifdef OPENSSL_SYS_NETWARE
+    printf("ERROR\n");
+#endif
+       EXIT(1);
        return(1);
        }