summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-01-10 14:47:09 +0000
committertb <>2022-01-10 14:47:09 +0000
commit8451a280e241cb46ada7e92c42530e7322ba5461 (patch)
treeb9905b9b0f6c2e21a29da7d211a879e19f8f0bdd
parent9d81dd22b5444646a181a83d0904867e23ecba07 (diff)
downloadopenbsd-8451a280e241cb46ada7e92c42530e7322ba5461.tar.gz
openbsd-8451a280e241cb46ada7e92c42530e7322ba5461.tar.bz2
openbsd-8451a280e241cb46ada7e92c42530e7322ba5461.zip
Convert testdsa to accessors for opaque DSA
ok inoguchi jsing
-rw-r--r--src/usr.bin/openssl/testdsa.h120
1 files changed, 90 insertions, 30 deletions
diff --git a/src/usr.bin/openssl/testdsa.h b/src/usr.bin/openssl/testdsa.h
index 1bbb09ca70..2845248806 100644
--- a/src/usr.bin/openssl/testdsa.h
+++ b/src/usr.bin/openssl/testdsa.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: testdsa.h,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ 1/* $OpenBSD: testdsa.h,v 1.2 2022/01/10 14:47:09 tb Exp $ */
2 2
3DSA *get_dsa512(void); 3DSA *get_dsa512(void);
4DSA *get_dsa1024(void); 4DSA *get_dsa1024(void);
@@ -41,18 +41,38 @@ DSA *
41get_dsa512() 41get_dsa512()
42{ 42{
43 DSA *dsa; 43 DSA *dsa;
44 BIGNUM *priv_key = NULL, *pub_key = NULL;
45 BIGNUM *p = NULL, *q = NULL, *g = NULL;
44 46
45 if ((dsa = DSA_new()) == NULL) 47 if ((dsa = DSA_new()) == NULL)
46 return (NULL); 48 goto err;
47 dsa->priv_key = BN_bin2bn(dsa512_priv, sizeof(dsa512_priv), NULL); 49
48 dsa->pub_key = BN_bin2bn(dsa512_pub, sizeof(dsa512_pub), NULL); 50 priv_key = BN_bin2bn(dsa512_priv, sizeof(dsa512_priv), NULL);
49 dsa->p = BN_bin2bn(dsa512_p, sizeof(dsa512_p), NULL); 51 pub_key = BN_bin2bn(dsa512_pub, sizeof(dsa512_pub), NULL);
50 dsa->q = BN_bin2bn(dsa512_q, sizeof(dsa512_q), NULL); 52 if (priv_key == NULL || pub_key == NULL)
51 dsa->g = BN_bin2bn(dsa512_g, sizeof(dsa512_g), NULL); 53 goto err;
52 if ((dsa->priv_key == NULL) || (dsa->pub_key == NULL) || 54 if (!DSA_set0_key(dsa, pub_key, priv_key))
53 (dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) 55 goto err;
54 return (NULL); 56
55 return (dsa); 57 p = BN_bin2bn(dsa512_p, sizeof(dsa512_p), NULL);
58 q = BN_bin2bn(dsa512_q, sizeof(dsa512_q), NULL);
59 g = BN_bin2bn(dsa512_g, sizeof(dsa512_g), NULL);
60 if (p == NULL || q == NULL || g == NULL)
61 goto err;
62 if (!DSA_set0_pqg(dsa, p, q, g))
63 goto err;
64
65 return dsa;
66
67 err:
68 DSA_free(dsa);
69 BN_free(priv_key);
70 BN_free(pub_key);
71 BN_free(p);
72 BN_free(q);
73 BN_free(g);
74
75 return NULL;
56} 76}
57 77
58static unsigned char dsa1024_priv[] = { 78static unsigned char dsa1024_priv[] = {
@@ -107,18 +127,39 @@ DSA *
107get_dsa1024() 127get_dsa1024()
108{ 128{
109 DSA *dsa; 129 DSA *dsa;
130 BIGNUM *priv_key = NULL, *pub_key = NULL;
131 BIGNUM *p = NULL, *q = NULL, *g = NULL;
110 132
111 if ((dsa = DSA_new()) == NULL) 133 if ((dsa = DSA_new()) == NULL)
112 return (NULL); 134 goto err;
113 dsa->priv_key = BN_bin2bn(dsa1024_priv, sizeof(dsa1024_priv), NULL); 135
114 dsa->pub_key = BN_bin2bn(dsa1024_pub, sizeof(dsa1024_pub), NULL); 136 priv_key = BN_bin2bn(dsa1024_priv, sizeof(dsa1024_priv), NULL);
115 dsa->p = BN_bin2bn(dsa1024_p, sizeof(dsa1024_p), NULL); 137 pub_key = BN_bin2bn(dsa1024_pub, sizeof(dsa1024_pub), NULL);
116 dsa->q = BN_bin2bn(dsa1024_q, sizeof(dsa1024_q), NULL); 138 if (priv_key == NULL || pub_key == NULL)
117 dsa->g = BN_bin2bn(dsa1024_g, sizeof(dsa1024_g), NULL); 139 goto err;
118 if ((dsa->priv_key == NULL) || (dsa->pub_key == NULL) || 140 if (!DSA_set0_key(dsa, pub_key, priv_key))
119 (dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) 141 goto err;
120 return (NULL); 142
121 return (dsa); 143 p = BN_bin2bn(dsa1024_p, sizeof(dsa1024_p), NULL);
144 q = BN_bin2bn(dsa1024_q, sizeof(dsa1024_q), NULL);
145 g = BN_bin2bn(dsa1024_g, sizeof(dsa1024_g), NULL);
146 if (p == NULL || q == NULL || g == NULL)
147 goto err;
148
149 if (!DSA_set0_pqg(dsa, p, q, g))
150 goto err;
151
152 return dsa;
153
154 err:
155 DSA_free(dsa);
156 BN_free(priv_key);
157 BN_free(pub_key);
158 BN_free(p);
159 BN_free(q);
160 BN_free(g);
161
162 return NULL;
122} 163}
123 164
124static unsigned char dsa2048_priv[] = { 165static unsigned char dsa2048_priv[] = {
@@ -206,16 +247,35 @@ DSA *
206get_dsa2048() 247get_dsa2048()
207{ 248{
208 DSA *dsa; 249 DSA *dsa;
250 BIGNUM *priv_key = NULL, *pub_key = NULL;
251 BIGNUM *p = NULL, *q = NULL, *g = NULL;
209 252
210 if ((dsa = DSA_new()) == NULL) 253 if ((dsa = DSA_new()) == NULL)
211 return (NULL); 254 return (NULL);
212 dsa->priv_key = BN_bin2bn(dsa2048_priv, sizeof(dsa2048_priv), NULL); 255 priv_key = BN_bin2bn(dsa2048_priv, sizeof(dsa2048_priv), NULL);
213 dsa->pub_key = BN_bin2bn(dsa2048_pub, sizeof(dsa2048_pub), NULL); 256 pub_key = BN_bin2bn(dsa2048_pub, sizeof(dsa2048_pub), NULL);
214 dsa->p = BN_bin2bn(dsa2048_p, sizeof(dsa2048_p), NULL); 257 if (priv_key == NULL || pub_key == NULL)
215 dsa->q = BN_bin2bn(dsa2048_q, sizeof(dsa2048_q), NULL); 258 goto err;
216 dsa->g = BN_bin2bn(dsa2048_g, sizeof(dsa2048_g), NULL); 259 if (!DSA_set0_key(dsa, pub_key, priv_key))
217 if ((dsa->priv_key == NULL) || (dsa->pub_key == NULL) || 260 goto err;
218 (dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) 261
219 return (NULL); 262 p = BN_bin2bn(dsa2048_p, sizeof(dsa2048_p), NULL);
220 return (dsa); 263 q = BN_bin2bn(dsa2048_q, sizeof(dsa2048_q), NULL);
264 g = BN_bin2bn(dsa2048_g, sizeof(dsa2048_g), NULL);
265 if (p == NULL || q == NULL || g == NULL)
266 goto err;
267 if (!DSA_set0_pqg(dsa, p, q, g))
268 goto err;
269
270 return dsa;
271
272 err:
273 DSA_free(dsa);
274 BN_free(priv_key);
275 BN_free(pub_key);
276 BN_free(p);
277 BN_free(q);
278 BN_free(g);
279
280 return NULL;
221} 281}