diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2022-11-10 13:09:35 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2022-11-10 13:09:35 +0000 |
commit | e1897cc8d2a1a5af2ab473c5db8438ac3b76a3f6 (patch) | |
tree | 4f5667035f1fd3fc9b0d96cf8a79c81329aca0a1 | |
parent | 77e60a482934be2ad6812b9225a2a2a353949b52 (diff) |
Port ASN1_buf_print() from OpenSSL 1.1.
This is needed to print byte array based keys, such as Ed25519 and X25519.
ok beck@ tb@
-rw-r--r-- | lib/libcrypto/asn1/asn1.h | 5 | ||||
-rw-r--r-- | lib/libcrypto/asn1/t_pkey.c | 31 |
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/libcrypto/asn1/asn1.h b/lib/libcrypto/asn1/asn1.h index ff42e45676d..24ba6a66685 100644 --- a/lib/libcrypto/asn1/asn1.h +++ b/lib/libcrypto/asn1/asn1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1.h,v 1.70 2022/09/11 17:22:52 tb Exp $ */ +/* $OpenBSD: asn1.h,v 1.71 2022/11/10 13:09:34 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -838,6 +838,9 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v); int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags); int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *buf, int off); +#if defined(LIBRESSL_NEXT_API) || defined(LIBRESSL_INTERNAL) +int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int indent); +#endif int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent); int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump); #endif diff --git a/lib/libcrypto/asn1/t_pkey.c b/lib/libcrypto/asn1/t_pkey.c index a3073812313..d1f77219ea2 100644 --- a/lib/libcrypto/asn1/t_pkey.c +++ b/lib/libcrypto/asn1/t_pkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: t_pkey.c,v 1.17 2021/12/04 16:08:32 tb Exp $ */ +/* $OpenBSD: t_pkey.c,v 1.18 2022/11/10 13:09:34 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -114,3 +114,32 @@ ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, } return (1); } + +#define ASN1_BUF_PRINT_WIDTH 15 +#define ASN1_BUF_PRINT_MAX_INDENT 64 + +int +ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int indent) +{ + size_t i; + + for (i = 0; i < buflen; i++) { + if ((i % ASN1_BUF_PRINT_WIDTH) == 0) { + if (i > 0 && BIO_puts(bp, "\n") <= 0) + return 0; + if (!BIO_indent(bp, indent, ASN1_BUF_PRINT_MAX_INDENT)) + return 0; + } + /* + * Use colon separators for each octet for compatibility as + * this function is used to print out key components. + */ + if (BIO_printf(bp, "%02x%s", buf[i], + (i == buflen - 1) ? "" : ":") <= 0) + return 0; + } + if (BIO_write(bp, "\n", 1) <= 0) + return 0; + + return 1; +} |