Some compilers are quite picky about non-void functions that don't return
[openssl.git] / crypto / dsa / dsatest.c
index c0209936af0e5ecb05e0a595baabaa566f6f7649..1ab90cfd7e493c23bbe3d3d395177a323e24db67 100644 (file)
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#include "../e_os.h"
+
 #include <openssl/crypto.h>
 #include <openssl/rand.h>
 #include <openssl/bio.h>
 #include <openssl/err.h>
-#include <openssl/dsa.h>
-#ifdef WINDOWS
+#include <openssl/engine.h>
+#ifdef OPENSSL_SYS_WINDOWS
 #include "../bio/bss_file.c"
 #endif
 
-#ifdef WIN16
+#ifdef OPENSSL_NO_DSA
+int main(int argc, char *argv[])
+{
+    printf("No DSA support\n");
+    return(0);
+}
+#else
+#include <openssl/dsa.h>
+
+#ifdef OPENSSL_SYS_WIN16
 #define MS_CALLBACK     _far _loadds
 #else
 #define MS_CALLBACK
 #endif
 
-static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
+static void MS_CALLBACK dsa_cb(int p, int n, void *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 */
 static unsigned char seed[20]={
        0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
        0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
@@ -112,6 +127,8 @@ static unsigned char out_g[]={
 
 static const unsigned char str1[]="12345678901234567890";
 
+static const char rnd_seed[] = "string to make the random number generator think it has entropy";
+
 static BIO *bio_err=NULL;
 
 int main(int argc, char **argv)
@@ -126,10 +143,16 @@ int main(int argc, char **argv)
        if (bio_err == NULL)
                bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
 
+       CRYPTO_malloc_debug_init();
+       CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+
+       ERR_load_crypto_strings();
+       RAND_seed(rnd_seed, sizeof rnd_seed);
+
        BIO_printf(bio_err,"test generation of DSA parameters\n");
-       BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n");
-       dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,
-               (char *)bio_err);
+
+       dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,bio_err);
 
        BIO_printf(bio_err,"seed\n");
        for (i=0; i<20; i+=4)
@@ -182,13 +205,27 @@ int main(int argc, char **argv)
 end:
        if (!ret)
                ERR_print_errors(bio_err);
-       if (bio_err != NULL) BIO_free(bio_err);
        if (dsa != NULL) DSA_free(dsa);
-       exit(!ret);
+       CRYPTO_cleanup_all_ex_data();
+       ERR_remove_state(0);
+       ERR_free_strings();
+       CRYPTO_mem_leaks(bio_err);
+       if (bio_err != NULL)
+               {
+               BIO_free(bio_err);
+               bio_err = NULL;
+               }
+       EXIT(!ret);
        return(0);
        }
 
-static void MS_CALLBACK dsa_cb(int p, int n, char *arg)
+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)
        {
        char c='*';
        static int ok=0,num=0;
@@ -197,14 +234,13 @@ static void MS_CALLBACK dsa_cb(int p, int n, char *arg)
        if (p == 1) c='+';
        if (p == 2) { c='*'; ok++; }
        if (p == 3) c='\n';
-       BIO_write((BIO *)arg,&c,1);
-       BIO_flush((BIO *)arg);
+       BIO_write(arg,&c,1);
+       (void)BIO_flush(arg);
 
        if (!ok && (p == 0) && (num > 1))
                {
                BIO_printf((BIO *)arg,"error in dsatest\n");
-               exit(1);
+               cb_exit(1);
                }
        }
-
-
+#endif