Change the command line options of mkerr.pl so -static is now default and
[oweals/openssl.git] / crypto / bn / bntest.c
index ec48bad73835169ad0b77e4bcc8bdf08feb9bb68..fb9d2a99f83cf5de5bf87f0447470855d088cabe 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "e_os.h"
-#include "bio.h"
-#include "bn.h"
-#include "rand.h"
-#include "x509.h"
-#include "err.h"
+#include <openssl/e_os.h>
+#include <openssl/bio.h>
+#include <openssl/bn.h>
+#include <openssl/rand.h>
+#include <openssl/x509.h>
+#include <openssl/err.h>
 
 #ifdef WINDOWS
 #include "../bio/bss_file.c"
@@ -85,6 +85,7 @@ int test_mont(BIO *bp,BN_CTX *ctx);
 int test_mod(BIO *bp,BN_CTX *ctx);
 int test_mod_mul(BIO *bp,BN_CTX *ctx);
 int test_mod_exp(BIO *bp,BN_CTX *ctx);
+int test_exp(BIO *bp,BN_CTX *ctx);
 int rand_neg(void);
 #else
 int test_add ();
@@ -100,6 +101,7 @@ int test_mont ();
 int test_mod ();
 int test_mod_mul ();
 int test_mod_exp ();
+int test_exp ();
 int rand_neg();
 #endif
 
@@ -110,9 +112,7 @@ static int results=0;
 #include "bss_file.c"
 #endif
 
-int main(argc,argv)
-int argc;
-char *argv[];
+int main(int argc, char *argv[])
        {
        BN_CTX *ctx;
        BIO *out;
@@ -214,6 +214,10 @@ char *argv[];
        if (!test_mod_exp(out,ctx)) goto err;
        fflush(stdout);
 
+       fprintf(stderr,"test BN_exp\n");
+       if (!test_exp(out,ctx)) goto err;
+       fflush(stdout);
+
 /**/
        exit(0);
 err:
@@ -223,8 +227,7 @@ err:
        return(1);
        }
 
-int test_add(bp)
-BIO *bp;
+int test_add(BIO *bp)
        {
        BIGNUM a,b,c;
        int i;
@@ -263,8 +266,7 @@ BIO *bp;
        return(1);
        }
 
-int test_sub(bp)
-BIO *bp;
+int test_sub(BIO *bp)
        {
        BIGNUM a,b,c;
        int i;
@@ -303,9 +305,7 @@ BIO *bp;
        return(1);
        }
 
-int test_div(bp,ctx)
-BIO *bp;
-BN_CTX *ctx;
+int test_div(BIO *bp, BN_CTX *ctx)
        {
        BIGNUM a,b,c,d;
        int i;
@@ -356,9 +356,7 @@ BN_CTX *ctx;
        return(1);
        }
 
-int test_div_recp(bp,ctx)
-BIO *bp;
-BN_CTX *ctx;
+int test_div_recp(BIO *bp, BN_CTX *ctx)
        {
        BIGNUM a,b,c,d;
        BN_RECP_CTX recp;
@@ -413,8 +411,7 @@ BN_CTX *ctx;
        return(1);
        }
 
-int test_mul(bp)
-BIO *bp;
+int test_mul(BIO *bp)
        {
        BIGNUM a,b,c;
        int i;
@@ -458,9 +455,7 @@ BIO *bp;
        return(1);
        }
 
-int test_sqr(bp,ctx)
-BIO *bp;
-BN_CTX *ctx;
+int test_sqr(BIO *bp, BN_CTX *ctx)
        {
        BIGNUM a,c;
        int i;
@@ -495,9 +490,7 @@ BN_CTX *ctx;
        return(1);
        }
 
-int test_mont(bp,ctx)
-BIO *bp;
-BN_CTX *ctx;
+int test_mont(BIO *bp, BN_CTX *ctx)
        {
        BIGNUM a,b,c,A,B;
        BIGNUM n;
@@ -557,9 +550,7 @@ BN_num_bits(mont->N));
        return(1);
        }
 
-int test_mod(bp,ctx)
-BIO *bp;
-BN_CTX *ctx;
+int test_mod(BIO *bp, BN_CTX *ctx)
        {
        BIGNUM *a,*b,*c;
        int i;
@@ -598,9 +589,7 @@ BN_CTX *ctx;
        return(1);
        }
 
-int test_mod_mul(bp,ctx)
-BIO *bp;
-BN_CTX *ctx;
+int test_mod_mul(BIO *bp, BN_CTX *ctx)
        {
        BIGNUM *a,*b,*c,*d,*e;
        int i;
@@ -654,9 +643,7 @@ BN_CTX *ctx;
        return(1);
        }
 
-int test_mod_exp(bp,ctx)
-BIO *bp;
-BN_CTX *ctx;
+int test_mod_exp(BIO *bp, BN_CTX *ctx)
        {
        BIGNUM *a,*b,*c,*d,*e;
        int i;
@@ -699,8 +686,45 @@ BN_CTX *ctx;
        return(1);
        }
 
-int test_lshift(bp)
-BIO *bp;
+int test_exp(BIO *bp, BN_CTX *ctx)
+       {
+       BIGNUM *a,*b,*d,*e;
+       int i;
+
+       a=BN_new();
+       b=BN_new();
+       d=BN_new();
+       e=BN_new();
+
+       for (i=0; i<6; i++)
+               {
+               BN_rand(a,20+i*5,0,0); /**/
+               BN_rand(b,2+i,0,0); /**/
+
+               if (!BN_exp(d,a,b,ctx))
+                       return(00);
+
+               if (bp != NULL)
+                       {
+                       if (!results)
+                               {
+                               BN_print(bp,a);
+                               BIO_puts(bp," ^ ");
+                               BN_print(bp,b);
+                               BIO_puts(bp," - ");
+                               }
+                       BN_print(bp,d);
+                       BIO_puts(bp,"\n");
+                       }
+               }
+       BN_free(a);
+       BN_free(b);
+       BN_free(d);
+       BN_free(e);
+       return(1);
+       }
+
+int test_lshift(BIO *bp)
        {
        BIGNUM *a,*b,*c;
        int i;
@@ -735,8 +759,7 @@ BIO *bp;
        return(1);
        }
 
-int test_lshift1(bp)
-BIO *bp;
+int test_lshift1(BIO *bp)
        {
        BIGNUM *a,*b;
        int i;
@@ -767,8 +790,7 @@ BIO *bp;
        return(1);
        }
 
-int test_rshift(bp)
-BIO *bp;
+int test_rshift(BIO *bp)
        {
        BIGNUM *a,*b,*c;
        int i;
@@ -803,8 +825,7 @@ BIO *bp;
        return(1);
        }
 
-int test_rshift1(bp)
-BIO *bp;
+int test_rshift1(BIO *bp)
        {
        BIGNUM *a,*b;
        int i;
@@ -835,7 +856,7 @@ BIO *bp;
        return(1);
        }
 
-int rand_neg()
+int rand_neg(void)
        {
        static unsigned int neg=0;
        static int sign[8]={0,0,0,1,1,0,1,1};