The des_xcbc_encrypt apparently always fails.
[openssl.git] / crypto / dsa / dsatest.c
index 4018f81862f4573caf5e397b5c6bbb514a6f34da..220f71c26004865b492bb32136226d7e989e58c2 100644 (file)
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include "crypto.h"
-#include "rand.h"
-#include "bio.h"
-#include "err.h"
-#include "dsa.h"
+#include <openssl/crypto.h>
+#include <openssl/rand.h>
+#include <openssl/bio.h>
+#include <openssl/err.h>
 #ifdef WINDOWS
 #include "../bio/bss_file.c"
 #endif
 
+#ifdef NO_DSA
+int main(int argc, char *argv[])
+{
+    printf("No DSA support\n");
+    return(0);
+}
+#else
+#include <openssl/dsa.h>
+
 #ifdef WIN16
 #define MS_CALLBACK     _far _loadds
 #else
 #define MS_CALLBACK
 #endif
 
-#ifndef NOPROTO
 static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
-#else
-static void MS_CALLBACK dsa_cb();
-#endif
-
 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,
@@ -115,6 +118,10 @@ static unsigned char out_g[]={
        0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02,
        };
 
+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)
@@ -124,11 +131,15 @@ int main(int argc, char **argv)
        unsigned char buf[256];
        unsigned long h;
        unsigned char sig[256];
-       int siglen;
+       unsigned int siglen;
+
+       RAND_seed(rnd_seed, sizeof rnd_seed);
 
        if (bio_err == NULL)
                bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
 
+       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+
        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,
@@ -179,14 +190,19 @@ int main(int argc, char **argv)
                goto end;
                }
        DSA_generate_key(dsa);
-       DSA_sign(0, "12345678901234567890", 20, sig, &siglen, dsa);
-       if (DSA_verify(0, "12345678901234567890", 20, sig, siglen, dsa) == 1)
+       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 (bio_err != NULL) BIO_free(bio_err);
        if (dsa != NULL) DSA_free(dsa);
+       CRYPTO_mem_leaks(bio_err);
+       if (bio_err != NULL)
+               {
+               BIO_free(bio_err);
+               bio_err = NULL;
+               }
        exit(!ret);
        return(0);
        }
@@ -201,7 +217,7 @@ static void MS_CALLBACK dsa_cb(int p, int n, char *arg)
        if (p == 2) { c='*'; ok++; }
        if (p == 3) c='\n';
        BIO_write((BIO *)arg,&c,1);
-       BIO_flush((BIO *)arg);
+       (void)BIO_flush((BIO *)arg);
 
        if (!ok && (p == 0) && (num > 1))
                {
@@ -209,5 +225,4 @@ static void MS_CALLBACK dsa_cb(int p, int n, char *arg)
                exit(1);
                }
        }
-
-
+#endif