diff options
Diffstat (limited to 'src/lib/libcrypto/dsa/dsatest.c')
-rw-r--r-- | src/lib/libcrypto/dsa/dsatest.c | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c index 39bb712c4a..12da64f9f4 100644 --- a/src/lib/libcrypto/dsa/dsatest.c +++ b/src/lib/libcrypto/dsa/dsatest.c | |||
@@ -61,27 +61,34 @@ | |||
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" | 68 | #include <openssl/engine.h> |
69 | #ifdef WINDOWS | 69 | #ifdef OPENSSL_SYS_WINDOWS |
70 | #include "../bio/bss_file.c" | 70 | #include "../bio/bss_file.c" |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | #ifdef WIN16 | 73 | #ifdef OPENSSL_NO_DSA |
74 | int main(int argc, char *argv[]) | ||
75 | { | ||
76 | printf("No DSA support\n"); | ||
77 | return(0); | ||
78 | } | ||
79 | #else | ||
80 | #include <openssl/dsa.h> | ||
81 | |||
82 | #ifdef OPENSSL_SYS_WIN16 | ||
74 | #define MS_CALLBACK _far _loadds | 83 | #define MS_CALLBACK _far _loadds |
75 | #else | 84 | #else |
76 | #define MS_CALLBACK | 85 | #define MS_CALLBACK |
77 | #endif | 86 | #endif |
78 | 87 | ||
79 | #ifndef NOPROTO | 88 | static void MS_CALLBACK dsa_cb(int p, int n, void *arg); |
80 | static void MS_CALLBACK dsa_cb(int p, int n, char *arg); | ||
81 | #else | ||
82 | static void MS_CALLBACK dsa_cb(); | ||
83 | #endif | ||
84 | 89 | ||
90 | /* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to | ||
91 | * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */ | ||
85 | static unsigned char seed[20]={ | 92 | static unsigned char seed[20]={ |
86 | 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, | 93 | 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, |
87 | 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, | 94 | 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, |
@@ -115,24 +122,34 @@ static unsigned char out_g[]={ | |||
115 | 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, | 122 | 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, |
116 | }; | 123 | }; |
117 | 124 | ||
125 | static const unsigned char str1[]="12345678901234567890"; | ||
126 | |||
127 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; | ||
128 | |||
118 | static BIO *bio_err=NULL; | 129 | static BIO *bio_err=NULL; |
119 | 130 | ||
120 | int main(argc, argv) | 131 | int main(int argc, char **argv) |
121 | int argc; | ||
122 | char **argv; | ||
123 | { | 132 | { |
124 | DSA *dsa=NULL; | 133 | DSA *dsa=NULL; |
125 | int counter,ret=0,i,j; | 134 | int counter,ret=0,i,j; |
126 | unsigned char buf[256]; | 135 | unsigned char buf[256]; |
127 | unsigned long h; | 136 | unsigned long h; |
137 | unsigned char sig[256]; | ||
138 | unsigned int siglen; | ||
128 | 139 | ||
129 | if (bio_err == NULL) | 140 | if (bio_err == NULL) |
130 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | 141 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); |
131 | 142 | ||
143 | CRYPTO_malloc_debug_init(); | ||
144 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
145 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
146 | |||
147 | ERR_load_crypto_strings(); | ||
148 | RAND_seed(rnd_seed, sizeof rnd_seed); | ||
149 | |||
132 | BIO_printf(bio_err,"test generation of DSA parameters\n"); | 150 | 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"); | 151 | |
134 | dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, | 152 | dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,bio_err); |
135 | (char *)bio_err); | ||
136 | 153 | ||
137 | BIO_printf(bio_err,"seed\n"); | 154 | BIO_printf(bio_err,"seed\n"); |
138 | for (i=0; i<20; i+=4) | 155 | for (i=0; i<20; i+=4) |
@@ -178,21 +195,28 @@ char **argv; | |||
178 | BIO_printf(bio_err,"g value is wrong\n"); | 195 | BIO_printf(bio_err,"g value is wrong\n"); |
179 | goto end; | 196 | goto end; |
180 | } | 197 | } |
181 | 198 | DSA_generate_key(dsa); | |
182 | ret=1; | 199 | DSA_sign(0, str1, 20, sig, &siglen, dsa); |
200 | if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) | ||
201 | ret=1; | ||
183 | end: | 202 | end: |
184 | if (!ret) | 203 | if (!ret) |
185 | ERR_print_errors(bio_err); | 204 | ERR_print_errors(bio_err); |
186 | if (bio_err != NULL) BIO_free(bio_err); | ||
187 | if (dsa != NULL) DSA_free(dsa); | 205 | if (dsa != NULL) DSA_free(dsa); |
206 | CRYPTO_cleanup_all_ex_data(); | ||
207 | ERR_remove_state(0); | ||
208 | ERR_free_strings(); | ||
209 | CRYPTO_mem_leaks(bio_err); | ||
210 | if (bio_err != NULL) | ||
211 | { | ||
212 | BIO_free(bio_err); | ||
213 | bio_err = NULL; | ||
214 | } | ||
188 | exit(!ret); | 215 | exit(!ret); |
189 | return(0); | 216 | return(0); |
190 | } | 217 | } |
191 | 218 | ||
192 | static void MS_CALLBACK dsa_cb(p, n, arg) | 219 | static void MS_CALLBACK dsa_cb(int p, int n, void *arg) |
193 | int p; | ||
194 | int n; | ||
195 | char *arg; | ||
196 | { | 220 | { |
197 | char c='*'; | 221 | char c='*'; |
198 | static int ok=0,num=0; | 222 | static int ok=0,num=0; |
@@ -201,8 +225,8 @@ char *arg; | |||
201 | if (p == 1) c='+'; | 225 | if (p == 1) c='+'; |
202 | if (p == 2) { c='*'; ok++; } | 226 | if (p == 2) { c='*'; ok++; } |
203 | if (p == 3) c='\n'; | 227 | if (p == 3) c='\n'; |
204 | BIO_write((BIO *)arg,&c,1); | 228 | BIO_write(arg,&c,1); |
205 | BIO_flush((BIO *)arg); | 229 | (void)BIO_flush(arg); |
206 | 230 | ||
207 | if (!ok && (p == 0) && (num > 1)) | 231 | if (!ok && (p == 0) && (num > 1)) |
208 | { | 232 | { |
@@ -210,5 +234,4 @@ char *arg; | |||
210 | exit(1); | 234 | exit(1); |
211 | } | 235 | } |
212 | } | 236 | } |
213 | 237 | #endif | |
214 | |||