diff options
-rw-r--r-- | src/lib/libcrypto/ec/eck_prn.c | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/src/lib/libcrypto/ec/eck_prn.c b/src/lib/libcrypto/ec/eck_prn.c index 45e0bc80e9..2798d53d0c 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.29 2023/11/21 16:31:31 tb Exp $ */ | 1 | /* $OpenBSD: eck_prn.c,v 1.30 2023/11/21 22:05:33 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -161,10 +161,6 @@ ECParameters_print(BIO *bp, const EC_KEY *x) | |||
161 | LCRYPTO_ALIAS(ECParameters_print); | 161 | LCRYPTO_ALIAS(ECParameters_print); |
162 | 162 | ||
163 | static int | 163 | static int |
164 | print_bin(BIO *fp, const char *str, const unsigned char *num, | ||
165 | size_t len, int off); | ||
166 | |||
167 | static int | ||
168 | ecpk_print_asn1_parameters(BIO *bp, const EC_GROUP *group, int off) | 164 | ecpk_print_asn1_parameters(BIO *bp, const EC_GROUP *group, int off) |
169 | { | 165 | { |
170 | const char *nist_name; | 166 | const char *nist_name; |
@@ -289,8 +285,33 @@ ecpk_print_explicit_parameters(BIO *bp, const EC_GROUP *group, int off) | |||
289 | if (!bn_printf(bp, cofactor, off, "Cofactor: ")) | 285 | if (!bn_printf(bp, cofactor, off, "Cofactor: ")) |
290 | goto err; | 286 | goto err; |
291 | if ((seed = EC_GROUP_get0_seed(group)) != NULL) { | 287 | if ((seed = EC_GROUP_get0_seed(group)) != NULL) { |
288 | size_t i; | ||
289 | |||
292 | seed_len = EC_GROUP_get_seed_len(group); | 290 | seed_len = EC_GROUP_get_seed_len(group); |
293 | if (!print_bin(bp, "Seed:", seed, seed_len, off)) | 291 | |
292 | /* XXX - ecx_buf_print() has a CBS version of this - dedup. */ | ||
293 | if (!BIO_indent(bp, off, 128)) | ||
294 | goto err; | ||
295 | if (BIO_printf(bp, "Seed:") <= 0) | ||
296 | goto err; | ||
297 | |||
298 | for (i = 0; i < seed_len; i++) { | ||
299 | const char *sep = ":"; | ||
300 | |||
301 | if (i % 15 == 0) { | ||
302 | if (BIO_printf(bp, "\n") <= 0) | ||
303 | goto err; | ||
304 | if (!BIO_indent(bp, off + 4, 128)) | ||
305 | goto err; | ||
306 | } | ||
307 | |||
308 | if (i + 1 == seed_len) | ||
309 | sep = ""; | ||
310 | if (BIO_printf(bp, "%02x%s", seed[i], sep) <= 0) | ||
311 | goto err; | ||
312 | } | ||
313 | |||
314 | if (BIO_printf(bp, "\n") <= 0) | ||
294 | goto err; | 315 | goto err; |
295 | } | 316 | } |
296 | 317 | ||
@@ -316,39 +337,3 @@ ECPKParameters_print(BIO *bp, const EC_GROUP *group, int off) | |||
316 | return ecpk_print_explicit_parameters(bp, group, off); | 337 | return ecpk_print_explicit_parameters(bp, group, off); |
317 | } | 338 | } |
318 | LCRYPTO_ALIAS(ECPKParameters_print); | 339 | LCRYPTO_ALIAS(ECPKParameters_print); |
319 | |||
320 | static int | ||
321 | print_bin(BIO *fp, const char *name, const unsigned char *buf, | ||
322 | size_t len, int off) | ||
323 | { | ||
324 | size_t i; | ||
325 | /* XXX - redo the function with asprintf/strlcat. */ | ||
326 | char str[128 + 1 + 4]; | ||
327 | |||
328 | if (buf == NULL) | ||
329 | return 1; | ||
330 | if (off) { | ||
331 | if (off > 128) | ||
332 | off = 128; | ||
333 | memset(str, ' ', off); | ||
334 | if (BIO_write(fp, str, off) <= 0) | ||
335 | return 0; | ||
336 | } | ||
337 | if (BIO_printf(fp, "%s", name) <= 0) | ||
338 | return 0; | ||
339 | |||
340 | for (i = 0; i < len; i++) { | ||
341 | if ((i % 15) == 0) { | ||
342 | str[0] = '\n'; | ||
343 | memset(&(str[1]), ' ', off + 4); | ||
344 | if (BIO_write(fp, str, off + 1 + 4) <= 0) | ||
345 | return 0; | ||
346 | } | ||
347 | if (BIO_printf(fp, "%02x%s", buf[i], ((i + 1) == len) ? "" : ":") <= 0) | ||
348 | return 0; | ||
349 | } | ||
350 | if (BIO_write(fp, "\n", 1) <= 0) | ||
351 | return 0; | ||
352 | |||
353 | return 1; | ||
354 | } | ||