summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dh
diff options
context:
space:
mode:
authortb <>2023-07-07 06:59:18 +0000
committertb <>2023-07-07 06:59:18 +0000
commitded7e344eeedbff393fe259288df7a0f543c49ba (patch)
treea7603816da4ccfb40c5056865d5382fd66d77983 /src/lib/libcrypto/dh
parent3e9606d3676b918eec4f58130ce87818363373b2 (diff)
downloadopenbsd-ded7e344eeedbff393fe259288df7a0f543c49ba.tar.gz
openbsd-ded7e344eeedbff393fe259288df7a0f543c49ba.tar.bz2
openbsd-ded7e344eeedbff393fe259288df7a0f543c49ba.zip
Mop up remaining uses of ASN1_bn_print()
This removes lots of silly buffers and will allow us to make this API go away. ok jsing
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r--src/lib/libcrypto/dh/dh_ameth.c43
1 files changed, 9 insertions, 34 deletions
diff --git a/src/lib/libcrypto/dh/dh_ameth.c b/src/lib/libcrypto/dh/dh_ameth.c
index 3de0bb9333..61d3d14397 100644
--- a/src/lib/libcrypto/dh/dh_ameth.c
+++ b/src/lib/libcrypto/dh/dh_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_ameth.c,v 1.28 2023/04/17 05:57:17 tb Exp $ */ 1/* $OpenBSD: dh_ameth.c,v 1.29 2023/07/07 06:59:18 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -65,6 +65,7 @@
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66 66
67#include "asn1_local.h" 67#include "asn1_local.h"
68#include "bn_local.h"
68#include "dh_local.h" 69#include "dh_local.h"
69#include "evp_local.h" 70#include "evp_local.h"
70 71
@@ -280,17 +281,6 @@ err:
280 return 0; 281 return 0;
281} 282}
282 283
283static void
284update_buflen(const BIGNUM *b, size_t *pbuflen)
285{
286 size_t i;
287
288 if (!b)
289 return;
290 if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
291 *pbuflen = i;
292}
293
294static int 284static int
295dh_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) 285dh_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
296{ 286{
@@ -313,9 +303,7 @@ dh_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
313static int 303static int
314do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype) 304do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
315{ 305{
316 unsigned char *m = NULL;
317 int reason = ERR_R_BUF_LIB, ret = 0; 306 int reason = ERR_R_BUF_LIB, ret = 0;
318 size_t buf_len = 0;
319 const char *ktype = NULL; 307 const char *ktype = NULL;
320 BIGNUM *priv_key, *pub_key; 308 BIGNUM *priv_key, *pub_key;
321 309
@@ -329,17 +317,6 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
329 else 317 else
330 pub_key = NULL; 318 pub_key = NULL;
331 319
332 update_buflen(x->p, &buf_len);
333
334 if (buf_len == 0) {
335 reason = ERR_R_PASSED_NULL_PARAMETER;
336 goto err;
337 }
338
339 update_buflen(x->g, &buf_len);
340 update_buflen(pub_key, &buf_len);
341 update_buflen(priv_key, &buf_len);
342
343 if (ptype == 2) 320 if (ptype == 2)
344 ktype = "PKCS#3 DH Private-Key"; 321 ktype = "PKCS#3 DH Private-Key";
345 else if (ptype == 1) 322 else if (ptype == 1)
@@ -347,9 +324,8 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
347 else 324 else
348 ktype = "PKCS#3 DH Parameters"; 325 ktype = "PKCS#3 DH Parameters";
349 326
350 m= malloc(buf_len + 10); 327 if (x->p == NULL) {
351 if (m == NULL) { 328 reason = ERR_R_PASSED_NULL_PARAMETER;
352 reason = ERR_R_MALLOC_FAILURE;
353 goto err; 329 goto err;
354 } 330 }
355 331
@@ -359,14 +335,14 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
359 goto err; 335 goto err;
360 indent += 4; 336 indent += 4;
361 337
362 if (!ASN1_bn_print(bp, "private-key:", priv_key, m, indent)) 338 if (!bn_printf(bp, priv_key, indent, "private-key:"))
363 goto err; 339 goto err;
364 if (!ASN1_bn_print(bp, "public-key:", pub_key, m, indent)) 340 if (!bn_printf(bp, pub_key, indent, "public-key:"))
365 goto err; 341 goto err;
366 342
367 if (!ASN1_bn_print(bp, "prime:", x->p, m, indent)) 343 if (!bn_printf(bp, x->p, indent, "prime:"))
368 goto err; 344 goto err;
369 if (!ASN1_bn_print(bp, "generator:", x->g, m, indent)) 345 if (!bn_printf(bp, x->g, indent, "generator:"))
370 goto err; 346 goto err;
371 if (x->length != 0) { 347 if (x->length != 0) {
372 if (!BIO_indent(bp, indent, 128)) 348 if (!BIO_indent(bp, indent, 128))
@@ -378,10 +354,9 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
378 354
379 ret = 1; 355 ret = 1;
380 if (0) { 356 if (0) {
381err: 357 err:
382 DHerror(reason); 358 DHerror(reason);
383 } 359 }
384 free(m);
385 return(ret); 360 return(ret);
386} 361}
387 362