diff options
author | markus <> | 2002-09-05 12:51:52 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 12:51:52 +0000 |
commit | 5514995a9d5ed91db089875adb509c7781357c0e (patch) | |
tree | 2484410a46ba6c05ef94c253da36fbceef990b64 /src/lib/libcrypto/dh/dhtest.c | |
parent | fd9566423b542798f5c8b06e68101a9ea5bb9885 (diff) | |
download | openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.gz openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.bz2 openbsd-5514995a9d5ed91db089875adb509c7781357c0e.zip |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/dh/dhtest.c')
-rw-r--r-- | src/lib/libcrypto/dh/dhtest.c | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c index 488f10fd41..34894ced73 100644 --- a/src/lib/libcrypto/dh/dhtest.c +++ b/src/lib/libcrypto/dh/dhtest.c | |||
@@ -59,53 +59,74 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <string.h> | 61 | #include <string.h> |
62 | #ifdef WINDOWS | 62 | #ifdef OPENSSL_SYS_WINDOWS |
63 | #include "../bio/bss_file.c" | 63 | #include "../bio/bss_file.c" |
64 | #endif | 64 | #endif |
65 | #include "crypto.h" | 65 | #include <openssl/crypto.h> |
66 | #include "bio.h" | 66 | #include <openssl/bio.h> |
67 | #include "bn.h" | 67 | #include <openssl/bn.h> |
68 | #include "dh.h" | 68 | #include <openssl/rand.h> |
69 | #include <openssl/err.h> | ||
70 | |||
71 | #ifdef OPENSSL_NO_DH | ||
72 | int main(int argc, char *argv[]) | ||
73 | { | ||
74 | printf("No DH support\n"); | ||
75 | return(0); | ||
76 | } | ||
77 | #else | ||
78 | #include <openssl/dh.h> | ||
69 | 79 | ||
70 | #ifdef WIN16 | 80 | #ifdef OPENSSL_SYS_WIN16 |
71 | #define MS_CALLBACK _far _loadds | 81 | #define MS_CALLBACK _far _loadds |
72 | #else | 82 | #else |
73 | #define MS_CALLBACK | 83 | #define MS_CALLBACK |
74 | #endif | 84 | #endif |
75 | 85 | ||
76 | #ifndef NOPROTO | 86 | static void MS_CALLBACK cb(int p, int n, void *arg); |
77 | static void MS_CALLBACK cb(int p, int n, char *arg); | 87 | #ifdef OPENSSL_NO_STDIO |
78 | #else | ||
79 | static void MS_CALLBACK cb(); | ||
80 | #endif | ||
81 | |||
82 | #ifdef NO_STDIO | ||
83 | #define APPS_WIN16 | 88 | #define APPS_WIN16 |
84 | #include "bss_file.c" | 89 | #include "bss_file.c" |
85 | #endif | 90 | #endif |
86 | 91 | ||
87 | BIO *out=NULL; | 92 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; |
88 | 93 | ||
89 | int main(argc,argv) | 94 | int main(int argc, char *argv[]) |
90 | int argc; | ||
91 | char *argv[]; | ||
92 | { | 95 | { |
93 | DH *a,*b; | 96 | DH *a; |
97 | DH *b=NULL; | ||
94 | char buf[12]; | 98 | char buf[12]; |
95 | unsigned char *abuf=NULL,*bbuf=NULL; | 99 | unsigned char *abuf=NULL,*bbuf=NULL; |
96 | int i,alen,blen,aout,bout,ret=1; | 100 | int i,alen,blen,aout,bout,ret=1; |
101 | BIO *out; | ||
97 | 102 | ||
98 | #ifdef WIN32 | 103 | CRYPTO_malloc_debug_init(); |
104 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
105 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
106 | |||
107 | #ifdef OPENSSL_SYS_WIN32 | ||
99 | CRYPTO_malloc_init(); | 108 | CRYPTO_malloc_init(); |
100 | #endif | 109 | #endif |
101 | 110 | ||
111 | RAND_seed(rnd_seed, sizeof rnd_seed); | ||
112 | |||
102 | out=BIO_new(BIO_s_file()); | 113 | out=BIO_new(BIO_s_file()); |
103 | if (out == NULL) exit(1); | 114 | if (out == NULL) exit(1); |
104 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | 115 | BIO_set_fp(out,stdout,BIO_NOCLOSE); |
105 | 116 | ||
106 | a=DH_generate_parameters(64,DH_GENERATOR_5,cb,(char *)out); | 117 | a=DH_generate_parameters(64,DH_GENERATOR_5,cb,out); |
107 | if (a == NULL) goto err; | 118 | if (a == NULL) goto err; |
108 | 119 | ||
120 | if (!DH_check(a, &i)) goto err; | ||
121 | if (i & DH_CHECK_P_NOT_PRIME) | ||
122 | BIO_puts(out, "p value is not prime\n"); | ||
123 | if (i & DH_CHECK_P_NOT_SAFE_PRIME) | ||
124 | BIO_puts(out, "p value is not a safe prime\n"); | ||
125 | if (i & DH_UNABLE_TO_CHECK_GENERATOR) | ||
126 | BIO_puts(out, "unable to check the generator value\n"); | ||
127 | if (i & DH_NOT_SUITABLE_GENERATOR) | ||
128 | BIO_puts(out, "the g value is not a generator\n"); | ||
129 | |||
109 | BIO_puts(out,"\np ="); | 130 | BIO_puts(out,"\np ="); |
110 | BN_print(out,a->p); | 131 | BN_print(out,a->p); |
111 | BIO_puts(out,"\ng ="); | 132 | BIO_puts(out,"\ng ="); |
@@ -134,7 +155,7 @@ char *argv[]; | |||
134 | BIO_puts(out,"\n"); | 155 | BIO_puts(out,"\n"); |
135 | 156 | ||
136 | alen=DH_size(a); | 157 | alen=DH_size(a); |
137 | abuf=(unsigned char *)Malloc(alen); | 158 | abuf=(unsigned char *)OPENSSL_malloc(alen); |
138 | aout=DH_compute_key(abuf,b->pub_key,a); | 159 | aout=DH_compute_key(abuf,b->pub_key,a); |
139 | 160 | ||
140 | BIO_puts(out,"key1 ="); | 161 | BIO_puts(out,"key1 ="); |
@@ -146,7 +167,7 @@ char *argv[]; | |||
146 | BIO_puts(out,"\n"); | 167 | BIO_puts(out,"\n"); |
147 | 168 | ||
148 | blen=DH_size(b); | 169 | blen=DH_size(b); |
149 | bbuf=(unsigned char *)Malloc(blen); | 170 | bbuf=(unsigned char *)OPENSSL_malloc(blen); |
150 | bout=DH_compute_key(bbuf,a->pub_key,b); | 171 | bout=DH_compute_key(bbuf,a->pub_key,b); |
151 | 172 | ||
152 | BIO_puts(out,"key2 ="); | 173 | BIO_puts(out,"key2 ="); |
@@ -164,16 +185,21 @@ char *argv[]; | |||
164 | else | 185 | else |
165 | ret=0; | 186 | ret=0; |
166 | err: | 187 | err: |
167 | if (abuf != NULL) Free(abuf); | 188 | ERR_print_errors_fp(stderr); |
168 | if (bbuf != NULL) Free(bbuf); | 189 | |
190 | if (abuf != NULL) OPENSSL_free(abuf); | ||
191 | if (bbuf != NULL) OPENSSL_free(bbuf); | ||
192 | if(b != NULL) DH_free(b); | ||
193 | if(a != NULL) DH_free(a); | ||
194 | BIO_free(out); | ||
195 | CRYPTO_cleanup_all_ex_data(); | ||
196 | ERR_remove_state(0); | ||
197 | CRYPTO_mem_leaks_fp(stderr); | ||
169 | exit(ret); | 198 | exit(ret); |
170 | return(ret); | 199 | return(ret); |
171 | } | 200 | } |
172 | 201 | ||
173 | static void MS_CALLBACK cb(p, n,arg) | 202 | static void MS_CALLBACK cb(int p, int n, void *arg) |
174 | int p; | ||
175 | int n; | ||
176 | char *arg; | ||
177 | { | 203 | { |
178 | char c='*'; | 204 | char c='*'; |
179 | 205 | ||
@@ -182,7 +208,9 @@ char *arg; | |||
182 | if (p == 2) c='*'; | 208 | if (p == 2) c='*'; |
183 | if (p == 3) c='\n'; | 209 | if (p == 3) c='\n'; |
184 | BIO_write((BIO *)arg,&c,1); | 210 | BIO_write((BIO *)arg,&c,1); |
211 | (void)BIO_flush((BIO *)arg); | ||
185 | #ifdef LINT | 212 | #ifdef LINT |
186 | p=n; | 213 | p=n; |
187 | #endif | 214 | #endif |
188 | } | 215 | } |
216 | #endif | ||