summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2021-11-18 15:07:28 +0000
committertb <>2021-11-18 15:07:28 +0000
commitb44b9125107c56a0df5525ef65a3ff84df775c59 (patch)
tree100cff1e9f5ae014fc892150a34a39200c3a2c19 /src
parent76475d10a90dc31c5598bd1f9346a6d20b67d45f (diff)
downloadopenbsd-b44b9125107c56a0df5525ef65a3ff84df775c59.tar.gz
openbsd-b44b9125107c56a0df5525ef65a3ff84df775c59.tar.bz2
openbsd-b44b9125107c56a0df5525ef65a3ff84df775c59.zip
dhtest: fix this to work with opaque BN. This will need more fixes to
work with opaque DH, but one step at a time. While here, add a bunch of missing spaces to reduce the eyebleed.
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/dh/dhtest.c109
1 files changed, 61 insertions, 48 deletions
diff --git a/src/regress/lib/libcrypto/dh/dhtest.c b/src/regress/lib/libcrypto/dh/dhtest.c
index 599c51d5ed..0b2cb741fc 100644
--- a/src/regress/lib/libcrypto/dh/dhtest.c
+++ b/src/regress/lib/libcrypto/dh/dhtest.c
@@ -1,25 +1,25 @@
1/* $OpenBSD: dhtest.c,v 1.5 2018/07/17 17:06:49 tb Exp $ */ 1/* $OpenBSD: dhtest.c,v 1.6 2021/11/18 15:07:28 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -62,6 +62,7 @@
62#undef OPENSSL_NO_DEPRECATED 62#undef OPENSSL_NO_DEPRECATED
63#endif 63#endif
64 64
65#include <err.h>
65#include <stdio.h> 66#include <stdio.h>
66#include <stdlib.h> 67#include <stdlib.h>
67#include <string.h> 68#include <string.h>
@@ -73,39 +74,47 @@
73 74
74#include <openssl/dh.h> 75#include <openssl/dh.h>
75 76
76static int cb(int p, int n, BN_GENCB *arg) 77static int
78cb(int p, int n, BN_GENCB *arg)
77{ 79{
78 char c='*'; 80 char c = '*';
79 81
80 if (p == 0) 82 if (p == 0)
81 c='.'; 83 c = '.';
82 if (p == 1) 84 if (p == 1)
83 c='+'; 85 c = '+';
84 if (p == 2) 86 if (p == 2)
85 c='*'; 87 c = '*';
86 if (p == 3) 88 if (p == 3)
87 c='\n'; 89 c = '\n';
88 BIO_write(arg->arg,&c,1); 90 BIO_write(BN_GENCB_get_arg(arg), &c, 1);
89 (void)BIO_flush(arg->arg); 91 (void)BIO_flush(BN_GENCB_get_arg(arg));
90 return 1; 92 return 1;
91} 93}
92 94
93int main(int argc, char *argv[]) 95int
96main(int argc, char *argv[])
94{ 97{
95 BN_GENCB _cb; 98 BN_GENCB *_cb;
96 DH *a; 99 DH *a;
97 char buf[12]; 100 char buf[12];
98 unsigned char *abuf=NULL; 101 unsigned char *abuf=NULL;
99 int i,alen,aout,ret=1; 102 int i, alen, aout;
100 BIO *out; 103 BIO *out;
104 int ret = 1;
105
106 if ((out = BIO_new(BIO_s_file())) == NULL)
107 err(1, "BIO_new");
108 BIO_set_fp(out, stdout, BIO_NOCLOSE);
109
110 if ((_cb = BN_GENCB_new()) == NULL)
111 err(1, "BN_GENCB_new");
101 112
102 out=BIO_new(BIO_s_file()); 113 BN_GENCB_set(_cb, &cb, out);
103 if (out == NULL) exit(1); 114 if ((a = DH_new()) == NULL)
104 BIO_set_fp(out,stdout,BIO_NOCLOSE); 115 goto err;
105 116
106 BN_GENCB_set(&_cb, &cb, out); 117 if (!DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, _cb))
107 if (((a = DH_new()) == NULL) ||
108 !DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, &_cb))
109 goto err; 118 goto err;
110 119
111 if (!DH_check(a, &i)) 120 if (!DH_check(a, &i))
@@ -119,36 +128,38 @@ int main(int argc, char *argv[])
119 if (i & DH_NOT_SUITABLE_GENERATOR) 128 if (i & DH_NOT_SUITABLE_GENERATOR)
120 BIO_puts(out, "the g value is not a generator\n"); 129 BIO_puts(out, "the g value is not a generator\n");
121 130
122 BIO_puts(out,"\np ="); 131 BIO_puts(out, "\np =");
123 BN_print(out,a->p); 132 BN_print(out, a->p);
124 BIO_puts(out,"\ng ="); 133 BIO_puts(out, "\ng =");
125 BN_print(out,a->g); 134 BN_print(out, a->g);
126 BIO_puts(out,"\n"); 135 BIO_puts(out, "\n");
127 136
128 if (!DH_generate_key(a)) 137 if (!DH_generate_key(a))
129 goto err; 138 goto err;
130 BIO_puts(out,"pri 1="); 139 BIO_puts(out, "pri 1=");
131 BN_print(out,a->priv_key); 140 BN_print(out, a->priv_key);
132 BIO_puts(out,"\npub 1="); 141 BIO_puts(out, "\npub 1=");
133 BN_print(out,a->pub_key); 142 BN_print(out, a->pub_key);
134 BIO_puts(out,"\n"); 143 BIO_puts(out, "\n");
135 144
136 alen=DH_size(a); 145 alen = DH_size(a);
137 abuf=malloc(alen); 146 if ((abuf = malloc(alen)) == NULL)
138 aout=DH_compute_key(abuf,a->pub_key,a); 147 err(1, "malloc");
139 148 aout = DH_compute_key(abuf, a->pub_key, a);
140 BIO_puts(out,"key1 ="); 149
150 BIO_puts(out, "key1 =");
141 for (i=0; i<aout; i++) { 151 for (i=0; i<aout; i++) {
142 snprintf(buf,sizeof buf,"%02X",abuf[i]); 152 snprintf(buf, sizeof buf, "%02X", abuf[i]);
143 BIO_puts(out,buf); 153 BIO_puts(out, buf);
144 } 154 }
145 BIO_puts(out,"\n"); 155 BIO_puts(out, "\n");
146 156
147 if (aout < 4) { 157 if (aout < 4) {
148 fprintf(stderr,"Error in DH routines\n"); 158 fprintf(stderr, "Error in DH routines\n");
149 ret=1; 159 goto err;
150 } else 160 }
151 ret=0; 161
162 ret = 0;
152err: 163err:
153 ERR_print_errors_fp(stderr); 164 ERR_print_errors_fp(stderr);
154 165
@@ -156,5 +167,7 @@ err:
156 if (a != NULL) 167 if (a != NULL)
157 DH_free(a); 168 DH_free(a);
158 BIO_free(out); 169 BIO_free(out);
159 exit(ret); 170 BN_GENCB_free(_cb);
171
172 return (ret);
160} 173}