diff options
author | tb <> | 2024-03-27 01:49:31 +0000 |
---|---|---|
committer | tb <> | 2024-03-27 01:49:31 +0000 |
commit | 0ebac5b8389e8df2fef0cc0020d68180ada55044 (patch) | |
tree | 307a291fe42852de8b3d20ede11b3dbb8a14ba5a /src/lib | |
parent | efa9d2333ae33cbad7579ecb053433a2a93d1d5b (diff) | |
download | openbsd-0ebac5b8389e8df2fef0cc0020d68180ada55044.tar.gz openbsd-0ebac5b8389e8df2fef0cc0020d68180ada55044.tar.bz2 openbsd-0ebac5b8389e8df2fef0cc0020d68180ada55044.zip |
Use dsa for DSA and dh for DH
This unifies variable names and does some other cleanup. Only change in
generated assembly is line number changes.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_lib.c | 178 |
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) | |||
146 | LCRYPTO_ALIAS(DSA_new_method); | 146 | LCRYPTO_ALIAS(DSA_new_method); |
147 | 147 | ||
148 | void | 148 | void |
149 | DSA_free(DSA *r) | 149 | DSA_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 | } |
174 | LCRYPTO_ALIAS(DSA_free); | 171 | LCRYPTO_ALIAS(DSA_free); |
175 | 172 | ||
176 | int | 173 | int |
177 | DSA_up_ref(DSA *r) | 174 | DSA_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 | } |
181 | LCRYPTO_ALIAS(DSA_up_ref); | 178 | LCRYPTO_ALIAS(DSA_up_ref); |
182 | 179 | ||
183 | int | 180 | int |
184 | DSA_size(const DSA *r) | 181 | DSA_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, | |||
206 | LCRYPTO_ALIAS(DSA_get_ex_new_index); | 203 | LCRYPTO_ALIAS(DSA_get_ex_new_index); |
207 | 204 | ||
208 | int | 205 | int |
209 | DSA_set_ex_data(DSA *d, int idx, void *arg) | 206 | DSA_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 | } |
213 | LCRYPTO_ALIAS(DSA_set_ex_data); | 210 | LCRYPTO_ALIAS(DSA_set_ex_data); |
214 | 211 | ||
215 | void * | 212 | void * |
216 | DSA_get_ex_data(DSA *d, int idx) | 213 | DSA_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 | } |
220 | LCRYPTO_ALIAS(DSA_get_ex_data); | 217 | LCRYPTO_ALIAS(DSA_get_ex_data); |
221 | 218 | ||
222 | int | 219 | int |
223 | DSA_security_bits(const DSA *d) | 220 | DSA_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 | } |
230 | LCRYPTO_ALIAS(DSA_security_bits); | 227 | LCRYPTO_ALIAS(DSA_security_bits); |
231 | 228 | ||
232 | #ifndef OPENSSL_NO_DH | 229 | #ifndef OPENSSL_NO_DH |
233 | DH * | 230 | DH * |
234 | DSA_dup_DH(const DSA *r) | 231 | DSA_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 | ||
268 | err: | 270 | err: |
269 | DH_free(ret); | 271 | DH_free(dh); |
270 | return NULL; | 272 | return NULL; |
271 | } | 273 | } |
272 | LCRYPTO_ALIAS(DSA_dup_DH); | 274 | LCRYPTO_ALIAS(DSA_dup_DH); |
273 | #endif | 275 | #endif |
274 | 276 | ||
275 | void | 277 | void |
276 | DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g) | 278 | DSA_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 | } |
285 | LCRYPTO_ALIAS(DSA_get0_pqg); | 287 | LCRYPTO_ALIAS(DSA_get0_pqg); |
286 | 288 | ||
287 | int | 289 | int |
288 | DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g) | 290 | DSA_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) | |||
309 | LCRYPTO_ALIAS(DSA_set0_pqg); | 311 | LCRYPTO_ALIAS(DSA_set0_pqg); |
310 | 312 | ||
311 | void | 313 | void |
312 | DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key) | 314 | DSA_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 | } |
319 | LCRYPTO_ALIAS(DSA_get0_key); | 321 | LCRYPTO_ALIAS(DSA_get0_key); |
320 | 322 | ||
321 | int | 323 | int |
322 | DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key) | 324 | DSA_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) | |||
338 | LCRYPTO_ALIAS(DSA_set0_key); | 340 | LCRYPTO_ALIAS(DSA_set0_key); |
339 | 341 | ||
340 | const BIGNUM * | 342 | const BIGNUM * |
341 | DSA_get0_p(const DSA *d) | 343 | DSA_get0_p(const DSA *dsa) |
342 | { | 344 | { |
343 | return d->p; | 345 | return dsa->p; |
344 | } | 346 | } |
345 | LCRYPTO_ALIAS(DSA_get0_p); | 347 | LCRYPTO_ALIAS(DSA_get0_p); |
346 | 348 | ||
347 | const BIGNUM * | 349 | const BIGNUM * |
348 | DSA_get0_q(const DSA *d) | 350 | DSA_get0_q(const DSA *dsa) |
349 | { | 351 | { |
350 | return d->q; | 352 | return dsa->q; |
351 | } | 353 | } |
352 | LCRYPTO_ALIAS(DSA_get0_q); | 354 | LCRYPTO_ALIAS(DSA_get0_q); |
353 | 355 | ||
354 | const BIGNUM * | 356 | const BIGNUM * |
355 | DSA_get0_g(const DSA *d) | 357 | DSA_get0_g(const DSA *dsa) |
356 | { | 358 | { |
357 | return d->g; | 359 | return dsa->g; |
358 | } | 360 | } |
359 | LCRYPTO_ALIAS(DSA_get0_g); | 361 | LCRYPTO_ALIAS(DSA_get0_g); |
360 | 362 | ||
361 | const BIGNUM * | 363 | const BIGNUM * |
362 | DSA_get0_pub_key(const DSA *d) | 364 | DSA_get0_pub_key(const DSA *dsa) |
363 | { | 365 | { |
364 | return d->pub_key; | 366 | return dsa->pub_key; |
365 | } | 367 | } |
366 | LCRYPTO_ALIAS(DSA_get0_pub_key); | 368 | LCRYPTO_ALIAS(DSA_get0_pub_key); |
367 | 369 | ||
368 | const BIGNUM * | 370 | const BIGNUM * |
369 | DSA_get0_priv_key(const DSA *d) | 371 | DSA_get0_priv_key(const DSA *dsa) |
370 | { | 372 | { |
371 | return d->priv_key; | 373 | return dsa->priv_key; |
372 | } | 374 | } |
373 | LCRYPTO_ALIAS(DSA_get0_priv_key); | 375 | LCRYPTO_ALIAS(DSA_get0_priv_key); |
374 | 376 | ||
375 | void | 377 | void |
376 | DSA_clear_flags(DSA *d, int flags) | 378 | DSA_clear_flags(DSA *dsa, int flags) |
377 | { | 379 | { |
378 | d->flags &= ~flags; | 380 | dsa->flags &= ~flags; |
379 | } | 381 | } |
380 | LCRYPTO_ALIAS(DSA_clear_flags); | 382 | LCRYPTO_ALIAS(DSA_clear_flags); |
381 | 383 | ||
382 | int | 384 | int |
383 | DSA_test_flags(const DSA *d, int flags) | 385 | DSA_test_flags(const DSA *dsa, int flags) |
384 | { | 386 | { |
385 | return d->flags & flags; | 387 | return dsa->flags & flags; |
386 | } | 388 | } |
387 | LCRYPTO_ALIAS(DSA_test_flags); | 389 | LCRYPTO_ALIAS(DSA_test_flags); |
388 | 390 | ||
389 | void | 391 | void |
390 | DSA_set_flags(DSA *d, int flags) | 392 | DSA_set_flags(DSA *dsa, int flags) |
391 | { | 393 | { |
392 | d->flags |= flags; | 394 | dsa->flags |= flags; |
393 | } | 395 | } |
394 | LCRYPTO_ALIAS(DSA_set_flags); | 396 | LCRYPTO_ALIAS(DSA_set_flags); |
395 | 397 | ||
396 | ENGINE * | 398 | ENGINE * |
397 | DSA_get0_engine(DSA *d) | 399 | DSA_get0_engine(DSA *dsa) |
398 | { | 400 | { |
399 | return NULL; | 401 | return NULL; |
400 | } | 402 | } |