summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-07-01 08:15:31 +0000
committertb <>2023-07-01 08:15:31 +0000
commitbd7bccfb2c9f1e8e7fc579eeada0cd974fc86288 (patch)
tree8162c514896bec506dd2ac9a1aeafe802bd4b38d
parent42667117575942e586641155aedeb571db5e3d43 (diff)
downloadopenbsd-bd7bccfb2c9f1e8e7fc579eeada0cd974fc86288.tar.gz
openbsd-bd7bccfb2c9f1e8e7fc579eeada0cd974fc86288.tar.bz2
openbsd-bd7bccfb2c9f1e8e7fc579eeada0cd974fc86288.zip
Simplify ASN1_bn_print() usage in ec/
ASN1_bn_print() doesn't print anything if the BIGNUM passed in is NULL. Also simplify the handling of the point conversion form of the generator. ok jsing
-rw-r--r--src/lib/libcrypto/ec/ec_ameth.c8
-rw-r--r--src/lib/libcrypto/ec/eck_prn.c42
2 files changed, 20 insertions, 30 deletions
diff --git a/src/lib/libcrypto/ec/ec_ameth.c b/src/lib/libcrypto/ec/ec_ameth.c
index e47dcbc7c0..45f51e9dd8 100644
--- a/src/lib/libcrypto/ec/ec_ameth.c
+++ b/src/lib/libcrypto/ec/ec_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_ameth.c,v 1.38 2023/03/07 07:01:35 tb Exp $ */ 1/* $OpenBSD: ec_ameth.c,v 1.39 2023/07/01 08:15:31 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 */
@@ -500,11 +500,9 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
500 BN_num_bits(order)) <= 0) 500 BN_num_bits(order)) <= 0)
501 goto err; 501 goto err;
502 502
503 if ((priv_key != NULL) && !ASN1_bn_print(bp, "priv:", priv_key, 503 if (!ASN1_bn_print(bp, "priv:", priv_key, buffer, off))
504 buffer, off))
505 goto err; 504 goto err;
506 if ((pub_key != NULL) && !ASN1_bn_print(bp, "pub: ", pub_key, 505 if (!ASN1_bn_print(bp, "pub: ", pub_key, buffer, off))
507 buffer, off))
508 goto err; 506 goto err;
509 if (!ECPKParameters_print(bp, group, off)) 507 if (!ECPKParameters_print(bp, group, off))
510 goto err; 508 goto err;
diff --git a/src/lib/libcrypto/ec/eck_prn.c b/src/lib/libcrypto/ec/eck_prn.c
index e1f734cbe7..04eccad061 100644
--- a/src/lib/libcrypto/ec/eck_prn.c
+++ b/src/lib/libcrypto/ec/eck_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eck_prn.c,v 1.21 2023/06/27 07:32:29 tb Exp $ */ 1/* $OpenBSD: eck_prn.c,v 1.22 2023/07/01 08:15:31 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -172,10 +172,6 @@ ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
172 size_t seed_len = 0; 172 size_t seed_len = 0;
173 const char *nname; 173 const char *nname;
174 174
175 static const char *gen_compressed = "Generator (compressed):";
176 static const char *gen_uncompressed = "Generator (uncompressed):";
177 static const char *gen_hybrid = "Generator (hybrid):";
178
179 if (!x) { 175 if (!x) {
180 reason = ERR_R_PASSED_NULL_PARAMETER; 176 reason = ERR_R_PASSED_NULL_PARAMETER;
181 goto err; 177 goto err;
@@ -209,6 +205,7 @@ ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
209 } else { 205 } else {
210 /* explicit parameters */ 206 /* explicit parameters */
211 point_conversion_form_t form; 207 point_conversion_form_t form;
208 const char *conversion;
212 209
213 if ((p = BN_new()) == NULL || (a = BN_new()) == NULL || 210 if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
214 (b = BN_new()) == NULL || (order = BN_new()) == NULL || 211 (b = BN_new()) == NULL || (order = BN_new()) == NULL ||
@@ -265,30 +262,25 @@ ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
265 if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(nid)) <= 0) 262 if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(nid)) <= 0)
266 goto err; 263 goto err;
267 264
268 if ((p != NULL) && !ASN1_bn_print(bp, "Prime:", p, buffer, off)) 265 if (!ASN1_bn_print(bp, "Prime:", p, buffer, off))
269 goto err; 266 goto err;
270 if ((a != NULL) && !ASN1_bn_print(bp, "A: ", a, buffer, off)) 267 if (!ASN1_bn_print(bp, "A: ", a, buffer, off))
271 goto err; 268 goto err;
272 if ((b != NULL) && !ASN1_bn_print(bp, "B: ", b, buffer, off)) 269 if (!ASN1_bn_print(bp, "B: ", b, buffer, off))
273 goto err; 270 goto err;
274 if (form == POINT_CONVERSION_COMPRESSED) { 271 if (form == POINT_CONVERSION_COMPRESSED)
275 if ((gen != NULL) && !ASN1_bn_print(bp, gen_compressed, gen, 272 conversion = "Generator (compressed):";
276 buffer, off)) 273 else if (form == POINT_CONVERSION_UNCOMPRESSED)
277 goto err; 274 conversion = "Generator (uncompressed):";
278 } else if (form == POINT_CONVERSION_UNCOMPRESSED) { 275 else if (form == POINT_CONVERSION_HYBRID)
279 if ((gen != NULL) && !ASN1_bn_print(bp, gen_uncompressed, gen, 276 conversion = "Generator (hybrid):";
280 buffer, off)) 277 else
281 goto err; 278 conversion = "Generator (unknown):";
282 } else { /* form == POINT_CONVERSION_HYBRID */ 279 if (!ASN1_bn_print(bp, conversion, gen, buffer, off))
283 if ((gen != NULL) && !ASN1_bn_print(bp, gen_hybrid, gen, 280 goto err;
284 buffer, off)) 281 if (!ASN1_bn_print(bp, "Order: ", order, buffer, off))
285 goto err;
286 }
287 if ((order != NULL) && !ASN1_bn_print(bp, "Order: ", order,
288 buffer, off))
289 goto err; 282 goto err;
290 if ((cofactor != NULL) && !ASN1_bn_print(bp, "Cofactor: ", cofactor, 283 if (!ASN1_bn_print(bp, "Cofactor: ", cofactor, buffer, off))
291 buffer, off))
292 goto err; 284 goto err;
293 if (seed && !print_bin(bp, "Seed:", seed, seed_len, off)) 285 if (seed && !print_bin(bp, "Seed:", seed, seed_len, off))
294 goto err; 286 goto err;