summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa/dsatest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dsa/dsatest.c')
-rw-r--r--src/lib/libcrypto/dsa/dsatest.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c
index 39bb712c4a..fc25c9a1b7 100644
--- a/src/lib/libcrypto/dsa/dsatest.c
+++ b/src/lib/libcrypto/dsa/dsatest.c
@@ -61,27 +61,30 @@
61#include <string.h> 61#include <string.h>
62#include <sys/types.h> 62#include <sys/types.h>
63#include <sys/stat.h> 63#include <sys/stat.h>
64#include "crypto.h" 64#include <openssl/crypto.h>
65#include "rand.h" 65#include <openssl/rand.h>
66#include "bio.h" 66#include <openssl/bio.h>
67#include "err.h" 67#include <openssl/err.h>
68#include "dsa.h"
69#ifdef WINDOWS 68#ifdef WINDOWS
70#include "../bio/bss_file.c" 69#include "../bio/bss_file.c"
71#endif 70#endif
72 71
72#ifdef NO_DSA
73int main(int argc, char *argv[])
74{
75 printf("No DSA support\n");
76 return(0);
77}
78#else
79#include <openssl/dsa.h>
80
73#ifdef WIN16 81#ifdef WIN16
74#define MS_CALLBACK _far _loadds 82#define MS_CALLBACK _far _loadds
75#else 83#else
76#define MS_CALLBACK 84#define MS_CALLBACK
77#endif 85#endif
78 86
79#ifndef NOPROTO
80static void MS_CALLBACK dsa_cb(int p, int n, char *arg); 87static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
81#else
82static void MS_CALLBACK dsa_cb();
83#endif
84
85static unsigned char seed[20]={ 88static unsigned char seed[20]={
86 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, 89 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
87 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, 90 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
@@ -115,20 +118,24 @@ static unsigned char out_g[]={
115 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, 118 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02,
116 }; 119 };
117 120
121static const unsigned char str1[]="12345678901234567890";
122
118static BIO *bio_err=NULL; 123static BIO *bio_err=NULL;
119 124
120int main(argc, argv) 125int main(int argc, char **argv)
121int argc;
122char **argv;
123 { 126 {
124 DSA *dsa=NULL; 127 DSA *dsa=NULL;
125 int counter,ret=0,i,j; 128 int counter,ret=0,i,j;
126 unsigned char buf[256]; 129 unsigned char buf[256];
127 unsigned long h; 130 unsigned long h;
131 unsigned char sig[256];
132 unsigned int siglen;
128 133
129 if (bio_err == NULL) 134 if (bio_err == NULL)
130 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 135 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
131 136
137 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
138
132 BIO_printf(bio_err,"test generation of DSA parameters\n"); 139 BIO_printf(bio_err,"test generation of DSA parameters\n");
133 BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n"); 140 BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n");
134 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, 141 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,
@@ -178,21 +185,21 @@ char **argv;
178 BIO_printf(bio_err,"g value is wrong\n"); 185 BIO_printf(bio_err,"g value is wrong\n");
179 goto end; 186 goto end;
180 } 187 }
181 188 DSA_generate_key(dsa);
182 ret=1; 189 DSA_sign(0, str1, 20, sig, &siglen, dsa);
190 if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
191 ret=1;
183end: 192end:
184 if (!ret) 193 if (!ret)
185 ERR_print_errors(bio_err); 194 ERR_print_errors(bio_err);
186 if (bio_err != NULL) BIO_free(bio_err);
187 if (dsa != NULL) DSA_free(dsa); 195 if (dsa != NULL) DSA_free(dsa);
196 CRYPTO_mem_leaks(bio_err);
197 if (bio_err != NULL) BIO_free(bio_err);
188 exit(!ret); 198 exit(!ret);
189 return(0); 199 return(0);
190 } 200 }
191 201
192static void MS_CALLBACK dsa_cb(p, n, arg) 202static void MS_CALLBACK dsa_cb(int p, int n, char *arg)
193int p;
194int n;
195char *arg;
196 { 203 {
197 char c='*'; 204 char c='*';
198 static int ok=0,num=0; 205 static int ok=0,num=0;
@@ -202,7 +209,7 @@ char *arg;
202 if (p == 2) { c='*'; ok++; } 209 if (p == 2) { c='*'; ok++; }
203 if (p == 3) c='\n'; 210 if (p == 3) c='\n';
204 BIO_write((BIO *)arg,&c,1); 211 BIO_write((BIO *)arg,&c,1);
205 BIO_flush((BIO *)arg); 212 (void)BIO_flush((BIO *)arg);
206 213
207 if (!ok && (p == 0) && (num > 1)) 214 if (!ok && (p == 0) && (num > 1))
208 { 215 {
@@ -210,5 +217,4 @@ char *arg;
210 exit(1); 217 exit(1);
211 } 218 }
212 } 219 }
213 220#endif
214