summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2022-11-10 13:09:34 +0000
committerjsing <>2022-11-10 13:09:34 +0000
commit6cfcf5c709af8f66b8747a256f9649e7e1f2c614 (patch)
tree1980a3bfc2b8cbd7de3fd3e491d3e87a70eef42d /src/lib
parent6a541f1320841c1e3d7113d4f768fe0636440b53 (diff)
downloadopenbsd-6cfcf5c709af8f66b8747a256f9649e7e1f2c614.tar.gz
openbsd-6cfcf5c709af8f66b8747a256f9649e7e1f2c614.tar.bz2
openbsd-6cfcf5c709af8f66b8747a256f9649e7e1f2c614.zip
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@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/asn1/asn1.h5
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c31
2 files changed, 34 insertions, 2 deletions
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index ff42e45676..24ba6a6668 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1.h,v 1.70 2022/09/11 17:22:52 tb Exp $ */ 1/* $OpenBSD: asn1.h,v 1.71 2022/11/10 13:09:34 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -838,6 +838,9 @@ int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
838int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags); 838int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, unsigned long flags);
839int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num, 839int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
840 unsigned char *buf, int off); 840 unsigned char *buf, int off);
841#if defined(LIBRESSL_NEXT_API) || defined(LIBRESSL_INTERNAL)
842int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int indent);
843#endif
841int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent); 844int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent);
842int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump); 845int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump);
843#endif 846#endif
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
index a307381231..d1f77219ea 100644
--- a/src/lib/libcrypto/asn1/t_pkey.c
+++ b/src/lib/libcrypto/asn1/t_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_pkey.c,v 1.17 2021/12/04 16:08:32 tb Exp $ */ 1/* $OpenBSD: t_pkey.c,v 1.18 2022/11/10 13:09:34 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -114,3 +114,32 @@ ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
114 } 114 }
115 return (1); 115 return (1);
116} 116}
117
118#define ASN1_BUF_PRINT_WIDTH 15
119#define ASN1_BUF_PRINT_MAX_INDENT 64
120
121int
122ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int indent)
123{
124 size_t i;
125
126 for (i = 0; i < buflen; i++) {
127 if ((i % ASN1_BUF_PRINT_WIDTH) == 0) {
128 if (i > 0 && BIO_puts(bp, "\n") <= 0)
129 return 0;
130 if (!BIO_indent(bp, indent, ASN1_BUF_PRINT_MAX_INDENT))
131 return 0;
132 }
133 /*
134 * Use colon separators for each octet for compatibility as
135 * this function is used to print out key components.
136 */
137 if (BIO_printf(bp, "%02x%s", buf[i],
138 (i == buflen - 1) ? "" : ":") <= 0)
139 return 0;
140 }
141 if (BIO_write(bp, "\n", 1) <= 0)
142 return 0;
143
144 return 1;
145}