diff options
| author | tb <> | 2023-07-22 17:20:50 +0000 |
|---|---|---|
| committer | tb <> | 2023-07-22 17:20:50 +0000 |
| commit | 6dde2d6b9d87c7389aaa7f2e087f05b6fdd01f49 (patch) | |
| tree | e15f6f77238e76df3d53faa4988e79686c4df817 | |
| parent | 33ad44fd18e396d1567b966b15ffe32070ce2262 (diff) | |
| download | openbsd-6dde2d6b9d87c7389aaa7f2e087f05b6fdd01f49.tar.gz openbsd-6dde2d6b9d87c7389aaa7f2e087f05b6fdd01f49.tar.bz2 openbsd-6dde2d6b9d87c7389aaa7f2e087f05b6fdd01f49.zip | |
Adapt bn_print() for EdDSA key printing
This is essentially a reimplementation of ASN1_buf_print(). The latter was
only added for these printing purposes and it will be removed again since
nothing uses it. We can then simply remove t_pkey.c in the upcoming bump.
ok jsing
| -rw-r--r-- | src/lib/libcrypto/ec/ecx_methods.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/src/lib/libcrypto/ec/ecx_methods.c b/src/lib/libcrypto/ec/ecx_methods.c index 1040ee6fc3..55670c1a59 100644 --- a/src/lib/libcrypto/ec/ecx_methods.c +++ b/src/lib/libcrypto/ec/ecx_methods.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecx_methods.c,v 1.7 2023/07/05 20:56:29 bcook Exp $ */ | 1 | /* $OpenBSD: ecx_methods.c,v 1.8 2023/07/22 17:20:50 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -292,6 +292,42 @@ ecx_pub_cmp(const EVP_PKEY *pkey1, const EVP_PKEY *pkey2) | |||
| 292 | pkey1->pkey.ecx->pub_key_len) == 0; | 292 | pkey1->pkey.ecx->pub_key_len) == 0; |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | /* Reimplementation of ASN1_buf_print() that adds a secondary indent of 4. */ | ||
| 296 | static int | ||
| 297 | ecx_buf_print(BIO *bio, const uint8_t *buf, size_t buf_len, int indent) | ||
| 298 | { | ||
| 299 | uint8_t u8; | ||
| 300 | size_t octets = 0; | ||
| 301 | const char *sep = ":", *nl = ""; | ||
| 302 | CBS cbs; | ||
| 303 | |||
| 304 | if (indent > 64) | ||
| 305 | indent = 64; | ||
| 306 | indent += 4; | ||
| 307 | if (indent < 0) | ||
| 308 | indent = 0; | ||
| 309 | |||
| 310 | CBS_init(&cbs, buf, buf_len); | ||
| 311 | while (CBS_len(&cbs) > 0) { | ||
| 312 | if (!CBS_get_u8(&cbs, &u8)) | ||
| 313 | return 0; | ||
| 314 | if (octets++ % 15 == 0) { | ||
| 315 | if (BIO_printf(bio, "%s%*s", nl, indent, "") < 0) | ||
| 316 | return 0; | ||
| 317 | nl = "\n"; | ||
| 318 | } | ||
| 319 | if (CBS_len(&cbs) == 0) | ||
| 320 | sep = ""; | ||
| 321 | if (BIO_printf(bio, "%02x%s", u8, sep) <= 0) | ||
| 322 | return 0; | ||
| 323 | } | ||
| 324 | |||
| 325 | if (BIO_printf(bio, "\n") <= 0) | ||
| 326 | return 0; | ||
| 327 | |||
| 328 | return 1; | ||
| 329 | } | ||
| 330 | |||
| 295 | static int | 331 | static int |
| 296 | ecx_pub_print(BIO *bio, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx) | 332 | ecx_pub_print(BIO *bio, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx) |
| 297 | { | 333 | { |
| @@ -309,8 +345,7 @@ ecx_pub_print(BIO *bio, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx) | |||
| 309 | return 0; | 345 | return 0; |
| 310 | if (BIO_printf(bio, "%*spub:\n", indent, "") <= 0) | 346 | if (BIO_printf(bio, "%*spub:\n", indent, "") <= 0) |
| 311 | return 0; | 347 | return 0; |
| 312 | if (ASN1_buf_print(bio, ecx_key->pub_key, ecx_key->pub_key_len, | 348 | if (!ecx_buf_print(bio, ecx_key->pub_key, ecx_key->pub_key_len, indent)) |
| 313 | indent + 4) == 0) | ||
| 314 | return 0; | 349 | return 0; |
| 315 | 350 | ||
| 316 | return 1; | 351 | return 1; |
| @@ -422,13 +457,11 @@ ecx_priv_print(BIO *bio, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx) | |||
| 422 | return 0; | 457 | return 0; |
| 423 | if (BIO_printf(bio, "%*spriv:\n", indent, "") <= 0) | 458 | if (BIO_printf(bio, "%*spriv:\n", indent, "") <= 0) |
| 424 | return 0; | 459 | return 0; |
| 425 | if (ASN1_buf_print(bio, ecx_key->priv_key, ecx_key->priv_key_len, | 460 | if (!ecx_buf_print(bio, ecx_key->priv_key, ecx_key->priv_key_len, indent)) |
| 426 | indent + 4) == 0) | ||
| 427 | return 0; | 461 | return 0; |
| 428 | if (BIO_printf(bio, "%*spub:\n", indent, "") <= 0) | 462 | if (BIO_printf(bio, "%*spub:\n", indent, "") <= 0) |
| 429 | return 0; | 463 | return 0; |
| 430 | if (ASN1_buf_print(bio, ecx_key->pub_key, ecx_key->pub_key_len, | 464 | if (!ecx_buf_print(bio, ecx_key->pub_key, ecx_key->pub_key_len, indent)) |
| 431 | indent + 4) == 0) | ||
| 432 | return 0; | 465 | return 0; |
| 433 | 466 | ||
| 434 | return 1; | 467 | return 1; |
