X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fdsa%2Fdsatest.c;h=2dac421970656f12e79c5369dfa9e147e7f79519;hp=a30dae6b7266fc8e41ce1496007e37e6f8cc731f;hb=6d23cf97443bfedf755341b4f2d0d7fce254e020;hpb=38e33cef15e7965ad9fd9db4b08fb2f5dc1bc573 diff --git a/crypto/dsa/dsatest.c b/crypto/dsa/dsatest.c index a30dae6b72..2dac421970 100644 --- a/crypto/dsa/dsatest.c +++ b/crypto/dsa/dsatest.c @@ -61,15 +61,16 @@ #include #include #include + +#include "../e_os.h" + #include #include #include #include -#ifdef WINDOWS -#include "../bio/bss_file.c" -#endif +#include -#ifdef NO_DSA +#ifdef OPENSSL_NO_DSA int main(int argc, char *argv[]) { printf("No DSA support\n"); @@ -78,13 +79,10 @@ int main(int argc, char *argv[]) #else #include -#ifdef WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif +static int dsa_cb(int p, int n, BN_GENCB *arg); -static void MS_CALLBACK dsa_cb(int p, int n, char *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, @@ -126,6 +124,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]; @@ -133,17 +132,25 @@ int main(int argc, char **argv) unsigned char sig[256]; unsigned int siglen; - RAND_seed(rnd_seed, sizeof rnd_seed); - 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 3 lines of '.'s and '+'s\n"); - dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, - (char *)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) @@ -151,9 +158,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) { @@ -189,25 +195,41 @@ 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_thread_state(NULL); + ERR_free_strings(); CRYPTO_mem_leaks(bio_err); if (bio_err != NULL) { BIO_free(bio_err); bio_err = NULL; } - exit(!ret); +#ifdef OPENSSL_SYS_NETWARE + if (!ret) printf("ERROR\n"); +#endif + EXIT(!ret); return(0); } -static void MS_CALLBACK dsa_cb(int p, int n, char *arg) +static int dsa_cb(int p, int n, BN_GENCB *arg) { char c='*'; static int ok=0,num=0; @@ -216,13 +238,14 @@ 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); - (void)BIO_flush((BIO *)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"); - exit(1); + return 0; } + return 1; } #endif