diff options
Diffstat (limited to 'src/regress/lib')
-rw-r--r-- | src/regress/lib/libcrypto/dh/dhtest.c | 96 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/dsa/dsatest.c | 7 |
2 files changed, 33 insertions, 70 deletions
diff --git a/src/regress/lib/libcrypto/dh/dhtest.c b/src/regress/lib/libcrypto/dh/dhtest.c index f1ddc5ccf5..9c2d507d97 100644 --- a/src/regress/lib/libcrypto/dh/dhtest.c +++ b/src/regress/lib/libcrypto/dh/dhtest.c | |||
@@ -73,16 +73,30 @@ | |||
73 | 73 | ||
74 | #include <openssl/dh.h> | 74 | #include <openssl/dh.h> |
75 | 75 | ||
76 | static int cb(int p, int n, BN_GENCB *arg); | 76 | static int cb(int p, int n, BN_GENCB *arg) |
77 | { | ||
78 | char c='*'; | ||
79 | |||
80 | if (p == 0) | ||
81 | c='.'; | ||
82 | if (p == 1) | ||
83 | c='+'; | ||
84 | if (p == 2) | ||
85 | c='*'; | ||
86 | if (p == 3) | ||
87 | c='\n'; | ||
88 | BIO_write(arg->arg,&c,1); | ||
89 | (void)BIO_flush(arg->arg); | ||
90 | return 1; | ||
91 | } | ||
77 | 92 | ||
78 | int main(int argc, char *argv[]) | 93 | int main(int argc, char *argv[]) |
79 | { | 94 | { |
80 | BN_GENCB _cb; | 95 | BN_GENCB _cb; |
81 | DH *a; | 96 | DH *a; |
82 | DH *b=NULL; | ||
83 | char buf[12]; | 97 | char buf[12]; |
84 | unsigned char *abuf=NULL,*bbuf=NULL; | 98 | unsigned char *abuf=NULL; |
85 | int i,alen,blen,aout,bout,ret=1; | 99 | int i,alen,aout,ret=1; |
86 | BIO *out; | 100 | BIO *out; |
87 | 101 | ||
88 | out=BIO_new(BIO_s_file()); | 102 | out=BIO_new(BIO_s_file()); |
@@ -90,11 +104,12 @@ int main(int argc, char *argv[]) | |||
90 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | 104 | BIO_set_fp(out,stdout,BIO_NOCLOSE); |
91 | 105 | ||
92 | BN_GENCB_set(&_cb, &cb, out); | 106 | BN_GENCB_set(&_cb, &cb, out); |
93 | if(((a = DH_new()) == NULL) || !DH_generate_parameters_ex(a, 64, | 107 | if (((a = DH_new()) == NULL) || |
94 | DH_GENERATOR_5, &_cb)) | 108 | !DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, &_cb)) |
95 | goto err; | 109 | goto err; |
96 | 110 | ||
97 | if (!DH_check(a, &i)) goto err; | 111 | if (!DH_check(a, &i)) |
112 | goto err; | ||
98 | if (i & DH_CHECK_P_NOT_PRIME) | 113 | if (i & DH_CHECK_P_NOT_PRIME) |
99 | BIO_puts(out, "p value is not prime\n"); | 114 | BIO_puts(out, "p value is not prime\n"); |
100 | if (i & DH_CHECK_P_NOT_SAFE_PRIME) | 115 | if (i & DH_CHECK_P_NOT_SAFE_PRIME) |
@@ -110,81 +125,36 @@ int main(int argc, char *argv[]) | |||
110 | BN_print(out,a->g); | 125 | BN_print(out,a->g); |
111 | BIO_puts(out,"\n"); | 126 | BIO_puts(out,"\n"); |
112 | 127 | ||
113 | b=DH_new(); | 128 | if (!DH_generate_key(a)) |
114 | if (b == NULL) goto err; | 129 | goto err; |
115 | |||
116 | b->p=BN_dup(a->p); | ||
117 | b->g=BN_dup(a->g); | ||
118 | if ((b->p == NULL) || (b->g == NULL)) goto err; | ||
119 | |||
120 | /* Set a to run with normal modexp and b to use constant time */ | ||
121 | a->flags &= ~DH_FLAG_NO_EXP_CONSTTIME; | ||
122 | b->flags |= DH_FLAG_NO_EXP_CONSTTIME; | ||
123 | |||
124 | if (!DH_generate_key(a)) goto err; | ||
125 | BIO_puts(out,"pri 1="); | 130 | BIO_puts(out,"pri 1="); |
126 | BN_print(out,a->priv_key); | 131 | BN_print(out,a->priv_key); |
127 | BIO_puts(out,"\npub 1="); | 132 | BIO_puts(out,"\npub 1="); |
128 | BN_print(out,a->pub_key); | 133 | BN_print(out,a->pub_key); |
129 | BIO_puts(out,"\n"); | 134 | BIO_puts(out,"\n"); |
130 | 135 | ||
131 | if (!DH_generate_key(b)) goto err; | ||
132 | BIO_puts(out,"pri 2="); | ||
133 | BN_print(out,b->priv_key); | ||
134 | BIO_puts(out,"\npub 2="); | ||
135 | BN_print(out,b->pub_key); | ||
136 | BIO_puts(out,"\n"); | ||
137 | |||
138 | alen=DH_size(a); | 136 | alen=DH_size(a); |
139 | abuf=malloc(alen); | 137 | abuf=malloc(alen); |
140 | aout=DH_compute_key(abuf,b->pub_key,a); | 138 | aout=DH_compute_key(abuf,a->pub_key,a); |
141 | 139 | ||
142 | BIO_puts(out,"key1 ="); | 140 | BIO_puts(out,"key1 ="); |
143 | for (i=0; i<aout; i++) | 141 | for (i=0; i<aout; i++) { |
144 | { | ||
145 | snprintf(buf,sizeof buf,"%02X",abuf[i]); | 142 | snprintf(buf,sizeof buf,"%02X",abuf[i]); |
146 | BIO_puts(out,buf); | 143 | BIO_puts(out,buf); |
147 | } | 144 | } |
148 | BIO_puts(out,"\n"); | 145 | BIO_puts(out,"\n"); |
149 | 146 | ||
150 | blen=DH_size(b); | 147 | if (aout < 4) { |
151 | bbuf=malloc(blen); | ||
152 | bout=DH_compute_key(bbuf,a->pub_key,b); | ||
153 | |||
154 | BIO_puts(out,"key2 ="); | ||
155 | for (i=0; i<bout; i++) | ||
156 | { | ||
157 | snprintf(buf,sizeof buf,"%02X",bbuf[i]); | ||
158 | BIO_puts(out,buf); | ||
159 | } | ||
160 | BIO_puts(out,"\n"); | ||
161 | if ((aout < 4) || (bout != aout) || (memcmp(abuf,bbuf,aout) != 0)) | ||
162 | { | ||
163 | fprintf(stderr,"Error in DH routines\n"); | 148 | fprintf(stderr,"Error in DH routines\n"); |
164 | ret=1; | 149 | ret=1; |
165 | } | 150 | } else |
166 | else | ||
167 | ret=0; | 151 | ret=0; |
168 | err: | 152 | err: |
169 | ERR_print_errors_fp(stderr); | 153 | ERR_print_errors_fp(stderr); |
170 | 154 | ||
171 | free(abuf); | 155 | free(abuf); |
172 | free(bbuf); | 156 | if (a != NULL) |
173 | if(b != NULL) DH_free(b); | 157 | DH_free(a); |
174 | if(a != NULL) DH_free(a); | ||
175 | BIO_free(out); | 158 | BIO_free(out); |
176 | exit(ret); | 159 | exit(ret); |
177 | } | 160 | } |
178 | |||
179 | static int cb(int p, int n, BN_GENCB *arg) | ||
180 | { | ||
181 | char c='*'; | ||
182 | |||
183 | if (p == 0) c='.'; | ||
184 | if (p == 1) c='+'; | ||
185 | if (p == 2) c='*'; | ||
186 | if (p == 3) c='\n'; | ||
187 | BIO_write(arg->arg,&c,1); | ||
188 | (void)BIO_flush(arg->arg); | ||
189 | return 1; | ||
190 | } | ||
diff --git a/src/regress/lib/libcrypto/dsa/dsatest.c b/src/regress/lib/libcrypto/dsa/dsatest.c index 1fb929a689..444cda532d 100644 --- a/src/regress/lib/libcrypto/dsa/dsatest.c +++ b/src/regress/lib/libcrypto/dsa/dsatest.c | |||
@@ -182,13 +182,6 @@ int main(int argc, char **argv) | |||
182 | goto end; | 182 | goto end; |
183 | } | 183 | } |
184 | 184 | ||
185 | dsa->flags |= DSA_FLAG_NO_EXP_CONSTTIME; | ||
186 | DSA_generate_key(dsa); | ||
187 | DSA_sign(0, str1, 20, sig, &siglen, dsa); | ||
188 | if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) | ||
189 | ret=1; | ||
190 | |||
191 | dsa->flags &= ~DSA_FLAG_NO_EXP_CONSTTIME; | ||
192 | DSA_generate_key(dsa); | 185 | DSA_generate_key(dsa); |
193 | DSA_sign(0, str1, 20, sig, &siglen, dsa); | 186 | DSA_sign(0, str1, 20, sig, &siglen, dsa); |
194 | if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) | 187 | if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) |