Remove redundant OPENSSL_NO_DEPRECATED suppression
[openssl.git] / crypto / dsa / dsatest.c
index 1ab90cfd7e493c23bbe3d3d395177a323e24db67..152205f1c01b0069ca8d603eb2904d59abc21182 100644 (file)
 #include <openssl/rand.h>
 #include <openssl/bio.h>
 #include <openssl/err.h>
-#include <openssl/engine.h>
-#ifdef OPENSSL_SYS_WINDOWS
-#include "../bio/bss_file.c"
-#endif
+#include <openssl/bn.h>
 
 #ifdef OPENSSL_NO_DSA
 int main(int argc, char *argv[])
@@ -88,7 +85,7 @@ int main(int argc, char *argv[])
 #define MS_CALLBACK
 #endif
 
-static void MS_CALLBACK dsa_cb(int p, int n, void *arg);
+static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg);
 
 /* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to
  * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */
@@ -133,6 +130,7 @@ static BIO *bio_err=NULL;
 
 int main(int argc, char **argv)
        {
+       BN_GENCB *cb;
        DSA *dsa=NULL;
        int counter,ret=0,i,j;
        unsigned char buf[256];
@@ -152,7 +150,13 @@ int main(int argc, char **argv)
 
        BIO_printf(bio_err,"test generation of DSA parameters\n");
 
-       dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,bio_err);
+       cb = BN_GENCB_new();
+       if(!cb) goto end;
+
+       BN_GENCB_set(cb, dsa_cb, bio_err);
+       if(((dsa = DSA_new()) == NULL) || !DSA_generate_parameters_ex(dsa, 512,
+                               seed, 20, &counter, &h, cb))
+               goto end;
 
        BIO_printf(bio_err,"seed\n");
        for (i=0; i<20; i+=4)
@@ -160,9 +164,8 @@ int main(int argc, char **argv)
                BIO_printf(bio_err,"%02X%02X%02X%02X ",
                        seed[i],seed[i+1],seed[i+2],seed[i+3]);
                }
-       BIO_printf(bio_err,"\ncounter=%d h=%d\n",counter,h);
+       BIO_printf(bio_err,"\ncounter=%d h=%ld\n",counter,h);
                
-       if (dsa == NULL) goto end;
        DSA_print(bio_err,dsa,0);
        if (counter != 105) 
                {
@@ -198,16 +201,26 @@ int main(int argc, char **argv)
                BIO_printf(bio_err,"g value is wrong\n");
                goto end;
                }
+
+       dsa->flags |= DSA_FLAG_NO_EXP_CONSTTIME;
+       DSA_generate_key(dsa);
+       DSA_sign(0, str1, 20, sig, &siglen, dsa);
+       if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
+               ret=1;
+
+       dsa->flags &= ~DSA_FLAG_NO_EXP_CONSTTIME;
        DSA_generate_key(dsa);
        DSA_sign(0, str1, 20, sig, &siglen, dsa);
        if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
                ret=1;
+
 end:
        if (!ret)
                ERR_print_errors(bio_err);
        if (dsa != NULL) DSA_free(dsa);
+       if (cb != NULL) BN_GENCB_free(cb);
        CRYPTO_cleanup_all_ex_data();
-       ERR_remove_state(0);
+       ERR_remove_thread_state(NULL);
        ERR_free_strings();
        CRYPTO_mem_leaks(bio_err);
        if (bio_err != NULL)
@@ -215,17 +228,14 @@ end:
                BIO_free(bio_err);
                bio_err = NULL;
                }
+#ifdef OPENSSL_SYS_NETWARE
+    if (!ret) printf("ERROR\n");
+#endif
        EXIT(!ret);
        return(0);
        }
 
-static int cb_exit(int ec)
-       {
-       EXIT(ec);
-       return(0);              /* To keep some compilers quiet */
-       }
-
-static void MS_CALLBACK dsa_cb(int p, int n, void *arg)
+static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg)
        {
        char c='*';
        static int ok=0,num=0;
@@ -234,13 +244,14 @@ static void MS_CALLBACK dsa_cb(int p, int n, void *arg)
        if (p == 1) c='+';
        if (p == 2) { c='*'; ok++; }
        if (p == 3) c='\n';
-       BIO_write(arg,&c,1);
-       (void)BIO_flush(arg);
+       BIO_write(BN_GENCB_get_arg(arg),&c,1);
+       (void)BIO_flush(BN_GENCB_get_arg(arg));
 
        if (!ok && (p == 0) && (num > 1))
                {
                BIO_printf((BIO *)arg,"error in dsatest\n");
-               cb_exit(1);
+               return 0;
                }
+       return 1;
        }
 #endif