summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c178
1 files changed, 90 insertions, 88 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index 2727e220f9..daf2fa135b 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_lib.c,v 1.47 2024/03/27 01:22:30 tb Exp $ */ 1/* $OpenBSD: dsa_lib.c,v 1.48 2024/03/27 01:49:31 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 *
@@ -146,48 +146,45 @@ DSA_new_method(ENGINE *engine)
146LCRYPTO_ALIAS(DSA_new_method); 146LCRYPTO_ALIAS(DSA_new_method);
147 147
148void 148void
149DSA_free(DSA *r) 149DSA_free(DSA *dsa)
150{ 150{
151 int i; 151 if (dsa == NULL)
152
153 if (r == NULL)
154 return; 152 return;
155 153
156 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA); 154 if (CRYPTO_add(&dsa->references, -1, CRYPTO_LOCK_DSA) > 0)
157 if (i > 0)
158 return; 155 return;
159 156
160 if (r->meth != NULL && r->meth->finish != NULL) 157 if (dsa->meth != NULL && dsa->meth->finish != NULL)
161 r->meth->finish(r); 158 dsa->meth->finish(dsa);
162 159
163 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); 160 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, dsa, &dsa->ex_data);
164 161
165 BN_free(r->p); 162 BN_free(dsa->p);
166 BN_free(r->q); 163 BN_free(dsa->q);
167 BN_free(r->g); 164 BN_free(dsa->g);
168 BN_free(r->pub_key); 165 BN_free(dsa->pub_key);
169 BN_free(r->priv_key); 166 BN_free(dsa->priv_key);
170 BN_free(r->kinv); 167 BN_free(dsa->kinv);
171 BN_free(r->r); 168 BN_free(dsa->r);
172 free(r); 169 free(dsa);
173} 170}
174LCRYPTO_ALIAS(DSA_free); 171LCRYPTO_ALIAS(DSA_free);
175 172
176int 173int
177DSA_up_ref(DSA *r) 174DSA_up_ref(DSA *dsa)
178{ 175{
179 return CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA) > 1; 176 return CRYPTO_add(&dsa->references, 1, CRYPTO_LOCK_DSA) > 1;
180} 177}
181LCRYPTO_ALIAS(DSA_up_ref); 178LCRYPTO_ALIAS(DSA_up_ref);
182 179
183int 180int
184DSA_size(const DSA *r) 181DSA_size(const DSA *dsa)
185{ 182{
186 DSA_SIG signature; 183 DSA_SIG signature;
187 int ret = 0; 184 int ret = 0;
188 185
189 signature.r = r->q; 186 signature.r = dsa->q;
190 signature.s = r->q; 187 signature.s = dsa->q;
191 188
192 if ((ret = i2d_DSA_SIG(&signature, NULL)) < 0) 189 if ((ret = i2d_DSA_SIG(&signature, NULL)) < 0)
193 ret = 0; 190 ret = 0;
@@ -206,102 +203,107 @@ DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
206LCRYPTO_ALIAS(DSA_get_ex_new_index); 203LCRYPTO_ALIAS(DSA_get_ex_new_index);
207 204
208int 205int
209DSA_set_ex_data(DSA *d, int idx, void *arg) 206DSA_set_ex_data(DSA *dsa, int idx, void *arg)
210{ 207{
211 return CRYPTO_set_ex_data(&d->ex_data, idx, arg); 208 return CRYPTO_set_ex_data(&dsa->ex_data, idx, arg);
212} 209}
213LCRYPTO_ALIAS(DSA_set_ex_data); 210LCRYPTO_ALIAS(DSA_set_ex_data);
214 211
215void * 212void *
216DSA_get_ex_data(DSA *d, int idx) 213DSA_get_ex_data(DSA *dsa, int idx)
217{ 214{
218 return CRYPTO_get_ex_data(&d->ex_data, idx); 215 return CRYPTO_get_ex_data(&dsa->ex_data, idx);
219} 216}
220LCRYPTO_ALIAS(DSA_get_ex_data); 217LCRYPTO_ALIAS(DSA_get_ex_data);
221 218
222int 219int
223DSA_security_bits(const DSA *d) 220DSA_security_bits(const DSA *dsa)
224{ 221{
225 if (d->p == NULL || d->q == NULL) 222 if (dsa->p == NULL || dsa->q == NULL)
226 return -1; 223 return -1;
227 224
228 return BN_security_bits(BN_num_bits(d->p), BN_num_bits(d->q)); 225 return BN_security_bits(BN_num_bits(dsa->p), BN_num_bits(dsa->q));
229} 226}
230LCRYPTO_ALIAS(DSA_security_bits); 227LCRYPTO_ALIAS(DSA_security_bits);
231 228
232#ifndef OPENSSL_NO_DH 229#ifndef OPENSSL_NO_DH
233DH * 230DH *
234DSA_dup_DH(const DSA *r) 231DSA_dup_DH(const DSA *dsa)
235{ 232{
236 /* 233 /*
237 * DSA has p, q, g, optional pub_key, optional priv_key. 234 * DSA has p, q, g, optional pub_key, optional priv_key.
238 * DH has p, optional length, g, optional pub_key, optional priv_key, 235 * DH has p, optional length, g, optional pub_key, optional priv_key,
239 * optional q. 236 * optional q.
240 */ 237 */
241 DH *ret = NULL; 238 DH *dh = NULL;
242 239
243 if (r == NULL) 240 if (dsa == NULL)
244 goto err; 241 goto err;
245 ret = DH_new(); 242
246 if (ret == NULL) 243 if ((dh = DH_new()) == NULL)
247 goto err; 244 goto err;
248 if (r->p != NULL) 245
249 if ((ret->p = BN_dup(r->p)) == NULL) 246 if (dsa->p != NULL) {
247 if ((dh->p = BN_dup(dsa->p)) == NULL)
250 goto err; 248 goto err;
251 if (r->q != NULL) { 249 }
252 ret->length = BN_num_bits(r->q); 250 if (dsa->q != NULL) {
253 if ((ret->q = BN_dup(r->q)) == NULL) 251 dh->length = BN_num_bits(dsa->q);
252 if ((dh->q = BN_dup(dsa->q)) == NULL)
254 goto err; 253 goto err;
255 } 254 }
256 if (r->g != NULL) 255 if (dsa->g != NULL) {
257 if ((ret->g = BN_dup(r->g)) == NULL) 256 if ((dh->g = BN_dup(dsa->g)) == NULL)
258 goto err; 257 goto err;
259 if (r->pub_key != NULL) 258 }
260 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL) 259 if (dsa->pub_key != NULL) {
260 if ((dh->pub_key = BN_dup(dsa->pub_key)) == NULL)
261 goto err; 261 goto err;
262 if (r->priv_key != NULL) 262 }
263 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL) 263 if (dsa->priv_key != NULL) {
264 if ((dh->priv_key = BN_dup(dsa->priv_key)) == NULL)
264 goto err; 265 goto err;
266 }
265 267
266 return ret; 268 return dh;
267 269
268err: 270 err:
269 DH_free(ret); 271 DH_free(dh);
270 return NULL; 272 return NULL;
271} 273}
272LCRYPTO_ALIAS(DSA_dup_DH); 274LCRYPTO_ALIAS(DSA_dup_DH);
273#endif 275#endif
274 276
275void 277void
276DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) 278DSA_get0_pqg(const DSA *dsa, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
277{ 279{
278 if (p != NULL) 280 if (p != NULL)
279 *p = d->p; 281 *p = dsa->p;
280 if (q != NULL) 282 if (q != NULL)
281 *q = d->q; 283 *q = dsa->q;
282 if (g != NULL) 284 if (g != NULL)
283 *g = d->g; 285 *g = dsa->g;
284} 286}
285LCRYPTO_ALIAS(DSA_get0_pqg); 287LCRYPTO_ALIAS(DSA_get0_pqg);
286 288
287int 289int
288DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g) 290DSA_set0_pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g)
289{ 291{
290 if ((d->p == NULL && p == NULL) || (d->q == NULL && q == NULL) || 292 if ((dsa->p == NULL && p == NULL) || (dsa->q == NULL && q == NULL) ||
291 (d->g == NULL && g == NULL)) 293 (dsa->g == NULL && g == NULL))
292 return 0; 294 return 0;
293 295
294 if (p != NULL) { 296 if (p != NULL) {
295 BN_free(d->p); 297 BN_free(dsa->p);
296 d->p = p; 298 dsa->p = p;
297 } 299 }
298 if (q != NULL) { 300 if (q != NULL) {
299 BN_free(d->q); 301 BN_free(dsa->q);
300 d->q = q; 302 dsa->q = q;
301 } 303 }
302 if (g != NULL) { 304 if (g != NULL) {
303 BN_free(d->g); 305 BN_free(dsa->g);
304 d->g = g; 306 dsa->g = g;
305 } 307 }
306 308
307 return 1; 309 return 1;
@@ -309,28 +311,28 @@ DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
309LCRYPTO_ALIAS(DSA_set0_pqg); 311LCRYPTO_ALIAS(DSA_set0_pqg);
310 312
311void 313void
312DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key) 314DSA_get0_key(const DSA *dsa, const BIGNUM **pub_key, const BIGNUM **priv_key)
313{ 315{
314 if (pub_key != NULL) 316 if (pub_key != NULL)
315 *pub_key = d->pub_key; 317 *pub_key = dsa->pub_key;
316 if (priv_key != NULL) 318 if (priv_key != NULL)
317 *priv_key = d->priv_key; 319 *priv_key = dsa->priv_key;
318} 320}
319LCRYPTO_ALIAS(DSA_get0_key); 321LCRYPTO_ALIAS(DSA_get0_key);
320 322
321int 323int
322DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key) 324DSA_set0_key(DSA *dsa, BIGNUM *pub_key, BIGNUM *priv_key)
323{ 325{
324 if (d->pub_key == NULL && pub_key == NULL) 326 if (dsa->pub_key == NULL && pub_key == NULL)
325 return 0; 327 return 0;
326 328
327 if (pub_key != NULL) { 329 if (pub_key != NULL) {
328 BN_free(d->pub_key); 330 BN_free(dsa->pub_key);
329 d->pub_key = pub_key; 331 dsa->pub_key = pub_key;
330 } 332 }
331 if (priv_key != NULL) { 333 if (priv_key != NULL) {
332 BN_free(d->priv_key); 334 BN_free(dsa->priv_key);
333 d->priv_key = priv_key; 335 dsa->priv_key = priv_key;
334 } 336 }
335 337
336 return 1; 338 return 1;
@@ -338,63 +340,63 @@ DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
338LCRYPTO_ALIAS(DSA_set0_key); 340LCRYPTO_ALIAS(DSA_set0_key);
339 341
340const BIGNUM * 342const BIGNUM *
341DSA_get0_p(const DSA *d) 343DSA_get0_p(const DSA *dsa)
342{ 344{
343 return d->p; 345 return dsa->p;
344} 346}
345LCRYPTO_ALIAS(DSA_get0_p); 347LCRYPTO_ALIAS(DSA_get0_p);
346 348
347const BIGNUM * 349const BIGNUM *
348DSA_get0_q(const DSA *d) 350DSA_get0_q(const DSA *dsa)
349{ 351{
350 return d->q; 352 return dsa->q;
351} 353}
352LCRYPTO_ALIAS(DSA_get0_q); 354LCRYPTO_ALIAS(DSA_get0_q);
353 355
354const BIGNUM * 356const BIGNUM *
355DSA_get0_g(const DSA *d) 357DSA_get0_g(const DSA *dsa)
356{ 358{
357 return d->g; 359 return dsa->g;
358} 360}
359LCRYPTO_ALIAS(DSA_get0_g); 361LCRYPTO_ALIAS(DSA_get0_g);
360 362
361const BIGNUM * 363const BIGNUM *
362DSA_get0_pub_key(const DSA *d) 364DSA_get0_pub_key(const DSA *dsa)
363{ 365{
364 return d->pub_key; 366 return dsa->pub_key;
365} 367}
366LCRYPTO_ALIAS(DSA_get0_pub_key); 368LCRYPTO_ALIAS(DSA_get0_pub_key);
367 369
368const BIGNUM * 370const BIGNUM *
369DSA_get0_priv_key(const DSA *d) 371DSA_get0_priv_key(const DSA *dsa)
370{ 372{
371 return d->priv_key; 373 return dsa->priv_key;
372} 374}
373LCRYPTO_ALIAS(DSA_get0_priv_key); 375LCRYPTO_ALIAS(DSA_get0_priv_key);
374 376
375void 377void
376DSA_clear_flags(DSA *d, int flags) 378DSA_clear_flags(DSA *dsa, int flags)
377{ 379{
378 d->flags &= ~flags; 380 dsa->flags &= ~flags;
379} 381}
380LCRYPTO_ALIAS(DSA_clear_flags); 382LCRYPTO_ALIAS(DSA_clear_flags);
381 383
382int 384int
383DSA_test_flags(const DSA *d, int flags) 385DSA_test_flags(const DSA *dsa, int flags)
384{ 386{
385 return d->flags & flags; 387 return dsa->flags & flags;
386} 388}
387LCRYPTO_ALIAS(DSA_test_flags); 389LCRYPTO_ALIAS(DSA_test_flags);
388 390
389void 391void
390DSA_set_flags(DSA *d, int flags) 392DSA_set_flags(DSA *dsa, int flags)
391{ 393{
392 d->flags |= flags; 394 dsa->flags |= flags;
393} 395}
394LCRYPTO_ALIAS(DSA_set_flags); 396LCRYPTO_ALIAS(DSA_set_flags);
395 397
396ENGINE * 398ENGINE *
397DSA_get0_engine(DSA *d) 399DSA_get0_engine(DSA *dsa)
398{ 400{
399 return NULL; 401 return NULL;
400} 402}