summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-01-14 08:40:57 +0000
committertb <>2022-01-14 08:40:57 +0000
commit7de4d3a68913b50be213d1f95ad168ee17570641 (patch)
treef4107fef050d8e49767a68206c4485731507efa2
parent11d03b6dcd305ef8269fb1b034e0f623f6d08d93 (diff)
downloadopenbsd-7de4d3a68913b50be213d1f95ad168ee17570641.tar.gz
openbsd-7de4d3a68913b50be213d1f95ad168ee17570641.tar.bz2
openbsd-7de4d3a68913b50be213d1f95ad168ee17570641.zip
Implement new-style OpenSSL BIO callbacks
This provides support for new-style BIO callbacks in BIO_{read,write,gets,puts}() and a helper function to work out whether it should call the new or the old style callback. It also adds a few typedefs and minor code cleanup as well as the BIO_{get,set}_callback_ex() from jsing, ok tb
-rw-r--r--src/lib/libcrypto/asn1/bio_asn1.c6
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c6
-rw-r--r--src/lib/libcrypto/bio/bf_lbuf.c6
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c6
-rw-r--r--src/lib/libcrypto/bio/bf_null.c6
-rw-r--r--src/lib/libcrypto/bio/bio.h29
-rw-r--r--src/lib/libcrypto/bio/bio_err.c3
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c288
-rw-r--r--src/lib/libcrypto/bio/bio_local.h8
-rw-r--r--src/lib/libcrypto/bio/bio_meth.c8
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c21
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c6
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c6
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c6
-rw-r--r--src/lib/libcrypto/evp/bio_md.c6
15 files changed, 266 insertions, 145 deletions
diff --git a/src/lib/libcrypto/asn1/bio_asn1.c b/src/lib/libcrypto/asn1/bio_asn1.c
index 6bc42009f7..9017786f1f 100644
--- a/src/lib/libcrypto/asn1/bio_asn1.c
+++ b/src/lib/libcrypto/asn1/bio_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_asn1.c,v 1.16 2022/01/07 09:02:17 tb Exp $ */ 1/* $OpenBSD: bio_asn1.c,v 1.17 2022/01/14 08:40:57 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. 3 * project.
4 */ 4 */
@@ -118,7 +118,7 @@ static int asn1_bio_gets(BIO *h, char *str, int size);
118static long asn1_bio_ctrl(BIO *h, int cmd, long arg1, void *arg2); 118static long asn1_bio_ctrl(BIO *h, int cmd, long arg1, void *arg2);
119static int asn1_bio_new(BIO *h); 119static int asn1_bio_new(BIO *h);
120static int asn1_bio_free(BIO *data); 120static int asn1_bio_free(BIO *data);
121static long asn1_bio_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); 121static long asn1_bio_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
122 122
123static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx, 123static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
124 asn1_ps_func *cleanup, asn1_bio_state_t next); 124 asn1_ps_func *cleanup, asn1_bio_state_t next);
@@ -346,7 +346,7 @@ asn1_bio_gets(BIO *b, char *str, int size)
346} 346}
347 347
348static long 348static long
349asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 349asn1_bio_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
350{ 350{
351 if (b->next_bio == NULL) 351 if (b->next_bio == NULL)
352 return (0); 352 return (0);
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
index 42414bb51a..aa079c5f9e 100644
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ b/src/lib/libcrypto/bio/bf_buff.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bf_buff.c,v 1.26 2022/01/07 09:02:17 tb Exp $ */ 1/* $OpenBSD: bf_buff.c,v 1.27 2022/01/14 08:40:57 tb 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 *
@@ -72,7 +72,7 @@ static int buffer_gets(BIO *h, char *str, int size);
72static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); 72static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
73static int buffer_new(BIO *h); 73static int buffer_new(BIO *h);
74static int buffer_free(BIO *data); 74static int buffer_free(BIO *data);
75static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); 75static long buffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
76#define DEFAULT_BUFFER_SIZE 4096 76#define DEFAULT_BUFFER_SIZE 4096
77 77
78static const BIO_METHOD methods_buffer = { 78static const BIO_METHOD methods_buffer = {
@@ -452,7 +452,7 @@ malloc_error:
452} 452}
453 453
454static long 454static long
455buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 455buffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
456{ 456{
457 long ret = 1; 457 long ret = 1;
458 458
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c
index 5d9ec0f025..d65150881c 100644
--- a/src/lib/libcrypto/bio/bf_lbuf.c
+++ b/src/lib/libcrypto/bio/bf_lbuf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bf_lbuf.c,v 1.14 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: bf_lbuf.c,v 1.15 2022/01/14 08:40:57 tb 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 *
@@ -69,7 +69,7 @@ static int linebuffer_gets(BIO *h, char *str, int size);
69static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); 69static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int linebuffer_new(BIO *h); 70static int linebuffer_new(BIO *h);
71static int linebuffer_free(BIO *data); 71static int linebuffer_free(BIO *data);
72static long linebuffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); 72static long linebuffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
73 73
74/* A 10k maximum should be enough for most purposes */ 74/* A 10k maximum should be enough for most purposes */
75#define DEFAULT_LINEBUFFER_SIZE 1024*10 75#define DEFAULT_LINEBUFFER_SIZE 1024*10
@@ -348,7 +348,7 @@ malloc_error:
348} 348}
349 349
350static long 350static long
351linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 351linebuffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
352{ 352{
353 long ret = 1; 353 long ret = 1;
354 354
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
index c0a5ab2bcb..086479ec4c 100644
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ b/src/lib/libcrypto/bio/bf_nbio.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bf_nbio.c,v 1.21 2022/01/07 09:02:17 tb Exp $ */ 1/* $OpenBSD: bf_nbio.c,v 1.22 2022/01/14 08:40:57 tb 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 *
@@ -74,7 +74,7 @@ static int nbiof_gets(BIO *h, char *str, int size);
74static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2); 74static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2);
75static int nbiof_new(BIO *h); 75static int nbiof_new(BIO *h);
76static int nbiof_free(BIO *data); 76static int nbiof_free(BIO *data);
77static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); 77static long nbiof_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
78 78
79typedef struct nbio_test_st { 79typedef struct nbio_test_st {
80 /* only set if we sent a 'should retry' error */ 80 /* only set if we sent a 'should retry' error */
@@ -223,7 +223,7 @@ nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
223} 223}
224 224
225static long 225static long
226nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 226nbiof_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
227{ 227{
228 long ret = 1; 228 long ret = 1;
229 229
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c
index 1a935cf26b..129def8c99 100644
--- a/src/lib/libcrypto/bio/bf_null.c
+++ b/src/lib/libcrypto/bio/bf_null.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bf_null.c,v 1.13 2022/01/07 09:02:17 tb Exp $ */ 1/* $OpenBSD: bf_null.c,v 1.14 2022/01/14 08:40:57 tb 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 *
@@ -73,7 +73,7 @@ static int nullf_gets(BIO *h, char *str, int size);
73static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2); 73static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
74static int nullf_new(BIO *h); 74static int nullf_new(BIO *h);
75static int nullf_free(BIO *data); 75static int nullf_free(BIO *data);
76static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); 76static long nullf_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
77 77
78static const BIO_METHOD methods_nullf = { 78static const BIO_METHOD methods_nullf = {
79 .type = BIO_TYPE_NULL_FILTER, 79 .type = BIO_TYPE_NULL_FILTER,
@@ -167,7 +167,7 @@ nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
167} 167}
168 168
169static long 169static long
170nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 170nullf_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
171{ 171{
172 long ret = 1; 172 long ret = 1;
173 173
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
index 8feb98d457..679e88a3bc 100644
--- a/src/lib/libcrypto/bio/bio.h
+++ b/src/lib/libcrypto/bio/bio.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio.h,v 1.53 2022/01/14 08:18:55 tb Exp $ */ 1/* $OpenBSD: bio.h,v 1.54 2022/01/14 08:40:57 tb 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 *
@@ -250,21 +250,30 @@ void BIO_clear_flags(BIO *b, int flags);
250#define BIO_CB_GETS 0x05 250#define BIO_CB_GETS 0x05
251#define BIO_CB_CTRL 0x06 251#define BIO_CB_CTRL 0x06
252 252
253/* The callback is called before and after the underling operation, 253/*
254 * The BIO_CB_RETURN flag indicates if it is after the call */ 254 * The callback is called before and after the underling operation,
255 * the BIO_CB_RETURN flag indicates if it is after the call.
256 */
255#define BIO_CB_RETURN 0x80 257#define BIO_CB_RETURN 0x80
256#define BIO_CB_return(a) ((a)|BIO_CB_RETURN)) 258#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
257#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) 259#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
258#define BIO_cb_post(a) ((a)&BIO_CB_RETURN) 260#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
259 261
260long (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, 262typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi,
261 int, long, long); 263 long argl, long ret);
262void BIO_set_callback(BIO *b, 264typedef long (*BIO_callback_fn_ex)(BIO *b, int oper, const char *argp,
263 long (*callback)(struct bio_st *, int, const char *, int, long, long)); 265 size_t len, int argi, long argl, int ret, size_t *processed);
266
267BIO_callback_fn BIO_get_callback(const BIO *b);
268void BIO_set_callback(BIO *b, BIO_callback_fn callback);
269
270BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b);
271void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback);
272
264char *BIO_get_callback_arg(const BIO *b); 273char *BIO_get_callback_arg(const BIO *b);
265void BIO_set_callback_arg(BIO *b, char *arg); 274void BIO_set_callback_arg(BIO *b, char *arg);
266 275
267const char * BIO_method_name(const BIO *b); 276const char *BIO_method_name(const BIO *b);
268int BIO_method_type(const BIO *b); 277int BIO_method_type(const BIO *b);
269 278
270typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); 279typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
@@ -563,8 +572,7 @@ int BIO_write(BIO *b, const void *data, int len)
563int BIO_puts(BIO *bp, const char *buf); 572int BIO_puts(BIO *bp, const char *buf);
564int BIO_indent(BIO *b, int indent, int max); 573int BIO_indent(BIO *b, int indent, int max);
565long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); 574long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
566long BIO_callback_ctrl(BIO *b, int cmd, 575long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp);
567 void (*fp)(struct bio_st *, int, const char *, int, long, long));
568char * BIO_ptr_ctrl(BIO *bp, int cmd, long larg); 576char * BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
569long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg); 577long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
570BIO * BIO_push(BIO *b, BIO *append); 578BIO * BIO_push(BIO *b, BIO *append);
@@ -732,6 +740,7 @@ void ERR_load_BIO_strings(void);
732#define BIO_R_INVALID_PORT_NUMBER 129 740#define BIO_R_INVALID_PORT_NUMBER 129
733#define BIO_R_IN_USE 123 741#define BIO_R_IN_USE 123
734#define BIO_R_KEEPALIVE 109 742#define BIO_R_KEEPALIVE 109
743#define BIO_R_LENGTH_TOO_LONG 130
735#define BIO_R_NBIO_CONNECT_ERROR 110 744#define BIO_R_NBIO_CONNECT_ERROR 110
736#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 745#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
737#define BIO_R_NO_HOSTNAME_SPECIFIED 112 746#define BIO_R_NO_HOSTNAME_SPECIFIED 112
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
index 2920e32103..cda693d036 100644
--- a/src/lib/libcrypto/bio/bio_err.c
+++ b/src/lib/libcrypto/bio/bio_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_err.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: bio_err.c,v 1.18 2022/01/14 08:40:57 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -92,6 +92,7 @@ static ERR_STRING_DATA BIO_str_reasons[] = {
92 {ERR_REASON(BIO_R_INVALID_PORT_NUMBER) , "invalid port number"}, 92 {ERR_REASON(BIO_R_INVALID_PORT_NUMBER) , "invalid port number"},
93 {ERR_REASON(BIO_R_IN_USE) , "in use"}, 93 {ERR_REASON(BIO_R_IN_USE) , "in use"},
94 {ERR_REASON(BIO_R_KEEPALIVE) , "keepalive"}, 94 {ERR_REASON(BIO_R_KEEPALIVE) , "keepalive"},
95 {ERR_REASON(BIO_R_LENGTH_TOO_LONG) , "too long"},
95 {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) , "nbio connect error"}, 96 {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) , "nbio connect error"},
96 {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"}, 97 {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"},
97 {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) , "no hostname specified"}, 98 {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) , "no hostname specified"},
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index 59c1317296..0b6c9ecac0 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_lib.c,v 1.34 2022/01/07 09:02:17 tb Exp $ */ 1/* $OpenBSD: bio_lib.c,v 1.35 2022/01/14 08:40:57 tb 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <errno.h> 59#include <errno.h>
60#include <limits.h>
60#include <stdio.h> 61#include <stdio.h>
61 62
62#include <openssl/bio.h> 63#include <openssl/bio.h>
@@ -66,6 +67,55 @@
66 67
67#include "bio_local.h" 68#include "bio_local.h"
68 69
70/*
71 * Helper function to work out whether to call the new style callback or the old
72 * one, and translate between the two.
73 *
74 * This has a long return type for consistency with the old callback. Similarly
75 * for the "long" used for "inret"
76 */
77static long
78bio_call_callback(BIO *b, int oper, const char *argp, size_t len, int argi,
79 long argl, long inret, size_t *processed)
80{
81 long ret;
82 int bareoper;
83
84 if (b->callback_ex != NULL)
85 return b->callback_ex(b, oper, argp, len, argi, argl, inret,
86 processed);
87
88 /*
89 * We have an old style callback, so we will have to do nasty casts and
90 * check for overflows.
91 */
92
93 bareoper = oper & ~BIO_CB_RETURN;
94
95 if (bareoper == BIO_CB_READ || bareoper == BIO_CB_WRITE ||
96 bareoper == BIO_CB_GETS) {
97 /* In this case len is set and should be used instead of argi. */
98 if (len > INT_MAX)
99 return -1;
100 argi = (int)len;
101 }
102
103 if (inret > 0 && (oper & BIO_CB_RETURN) && bareoper != BIO_CB_CTRL) {
104 if (*processed > INT_MAX)
105 return -1;
106 inret = *processed;
107 }
108
109 ret = b->callback(b, oper, argp, argi, argl, inret);
110
111 if (ret > 0 && (oper & BIO_CB_RETURN) && bareoper != BIO_CB_CTRL) {
112 *processed = (size_t)ret;
113 ret = 1;
114 }
115
116 return ret;
117}
118
69int 119int
70BIO_get_new_index(void) 120BIO_get_new_index(void)
71{ 121{
@@ -85,6 +135,7 @@ BIO_new(const BIO_METHOD *method)
85{ 135{
86 BIO *ret = NULL; 136 BIO *ret = NULL;
87 137
138 /* XXX calloc */
88 ret = malloc(sizeof(BIO)); 139 ret = malloc(sizeof(BIO));
89 if (ret == NULL) { 140 if (ret == NULL) {
90 BIOerror(ERR_R_MALLOC_FAILURE); 141 BIOerror(ERR_R_MALLOC_FAILURE);
@@ -102,6 +153,7 @@ BIO_set(BIO *bio, const BIO_METHOD *method)
102{ 153{
103 bio->method = method; 154 bio->method = method;
104 bio->callback = NULL; 155 bio->callback = NULL;
156 bio->callback_ex = NULL;
105 bio->cb_arg = NULL; 157 bio->cb_arg = NULL;
106 bio->init = 0; 158 bio->init = 0;
107 bio->shutdown = 1; 159 bio->shutdown = 1;
@@ -115,29 +167,32 @@ BIO_set(BIO *bio, const BIO_METHOD *method)
115 bio->num_read = 0L; 167 bio->num_read = 0L;
116 bio->num_write = 0L; 168 bio->num_write = 0L;
117 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); 169 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
118 if (method->create != NULL) 170 if (method->create != NULL) {
119 if (!method->create(bio)) { 171 if (!method->create(bio)) {
120 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, 172 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio,
121 &bio->ex_data); 173 &bio->ex_data);
122 return (0); 174 return (0);
123 } 175 }
176 }
124 return (1); 177 return (1);
125} 178}
126 179
127int 180int
128BIO_free(BIO *a) 181BIO_free(BIO *a)
129{ 182{
130 int i; 183 int ret;
131 184
132 if (a == NULL) 185 if (a == NULL)
133 return (0); 186 return (0);
134 187
135 i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO); 188 if (CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO) > 0)
136 if (i > 0)
137 return (1); 189 return (1);
138 if ((a->callback != NULL) && 190
139 ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0)) 191 if (a->callback != NULL || a->callback_ex != NULL) {
140 return (i); 192 if ((ret = (int)bio_call_callback(a, BIO_CB_FREE, NULL, 0, 0,
193 0L, 1L, NULL)) <= 0)
194 return (ret);
195 }
141 196
142 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); 197 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
143 198
@@ -214,20 +269,30 @@ BIO_set_flags(BIO *b, int flags)
214 b->flags |= flags; 269 b->flags |= flags;
215} 270}
216 271
217long 272BIO_callback_fn
218(*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, int, 273BIO_get_callback(const BIO *b)
219 long, long)
220{ 274{
221 return b->callback; 275 return b->callback;
222} 276}
223 277
224void 278void
225BIO_set_callback(BIO *b, long (*cb)(struct bio_st *, int, const char *, int, 279BIO_set_callback(BIO *b, BIO_callback_fn cb)
226 long, long))
227{ 280{
228 b->callback = cb; 281 b->callback = cb;
229} 282}
230 283
284BIO_callback_fn_ex
285BIO_get_callback_ex(const BIO *b)
286{
287 return b->callback_ex;
288}
289
290void
291BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex cb)
292{
293 b->callback_ex = cb;
294}
295
231void 296void
232BIO_set_callback_arg(BIO *b, char *arg) 297BIO_set_callback_arg(BIO *b, char *arg)
233{ 298{
@@ -255,8 +320,8 @@ BIO_method_type(const BIO *b)
255int 320int
256BIO_read(BIO *b, void *out, int outl) 321BIO_read(BIO *b, void *out, int outl)
257{ 322{
258 int i; 323 size_t readbytes = 0;
259 long (*cb)(BIO *, int, const char *, int, long, long); 324 int ret;
260 325
261 if (b == NULL) 326 if (b == NULL)
262 return (0); 327 return (0);
@@ -269,33 +334,44 @@ BIO_read(BIO *b, void *out, int outl)
269 return (-2); 334 return (-2);
270 } 335 }
271 336
272 cb = b->callback; 337 if (b->callback != NULL || b->callback_ex != NULL) {
273 if ((cb != NULL) && 338 if ((ret = (int)bio_call_callback(b, BIO_CB_READ, out, outl, 0,
274 ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0)) 339 0L, 1L, NULL)) <= 0)
275 return (i); 340 return (ret);
341 }
276 342
277 if (!b->init) { 343 if (!b->init) {
278 BIOerror(BIO_R_UNINITIALIZED); 344 BIOerror(BIO_R_UNINITIALIZED);
279 return (-2); 345 return (-2);
280 } 346 }
281 347
282 i = b->method->bread(b, out, outl); 348 if ((ret = b->method->bread(b, out, outl)) > 0)
349 readbytes = (size_t)ret;
283 350
284 if (i > 0) 351 b->num_read += readbytes;
285 b->num_read += (unsigned long)i;
286 352
287 if (cb != NULL) 353 if (b->callback != NULL || b->callback_ex != NULL) {
288 i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, 354 ret = (int)bio_call_callback(b, BIO_CB_READ | BIO_CB_RETURN,
289 0L, (long)i); 355 out, outl, 0, 0L, (ret > 0) ? 1 : ret, &readbytes);
356 }
290 357
291 return (i); 358 if (ret > 0) {
359 if (readbytes > INT_MAX) {
360 BIOerror(BIO_R_LENGTH_TOO_LONG);
361 ret = -1;
362 } else {
363 ret = (int)readbytes;
364 }
365 }
366
367 return (ret);
292} 368}
293 369
294int 370int
295BIO_write(BIO *b, const void *in, int inl) 371BIO_write(BIO *b, const void *in, int inl)
296{ 372{
297 int i; 373 size_t writebytes = 0;
298 long (*cb)(BIO *, int, const char *, int, long, long); 374 int ret;
299 375
300 if (b == NULL) 376 if (b == NULL)
301 return (0); 377 return (0);
@@ -308,86 +384,123 @@ BIO_write(BIO *b, const void *in, int inl)
308 return (-2); 384 return (-2);
309 } 385 }
310 386
311 cb = b->callback; 387 if (b->callback != NULL || b->callback_ex != NULL) {
312 if ((cb != NULL) && 388 if ((ret = (int)bio_call_callback(b, BIO_CB_WRITE, in, inl, 0,
313 ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0)) 389 0L, 1L, NULL)) <= 0)
314 return (i); 390 return (ret);
391 }
315 392
316 if (!b->init) { 393 if (!b->init) {
317 BIOerror(BIO_R_UNINITIALIZED); 394 BIOerror(BIO_R_UNINITIALIZED);
318 return (-2); 395 return (-2);
319 } 396 }
320 397
321 i = b->method->bwrite(b, in, inl); 398 if ((ret = b->method->bwrite(b, in, inl)) > 0)
399 writebytes = ret;
400
401 b->num_write += writebytes;
402
403 if (b->callback != NULL || b->callback_ex != NULL) {
404 ret = (int)bio_call_callback(b, BIO_CB_WRITE | BIO_CB_RETURN,
405 in, inl, 0, 0L, (ret > 0) ? 1 : ret, &writebytes);
406 }
322 407
323 if (i > 0) 408 if (ret > 0) {
324 b->num_write += (unsigned long)i; 409 if (writebytes > INT_MAX) {
410 BIOerror(BIO_R_LENGTH_TOO_LONG);
411 ret = -1;
412 } else {
413 ret = (int)writebytes;
414 }
415 }
325 416
326 if (cb != NULL) 417 return (ret);
327 i = (int)cb(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl,
328 0L, (long)i);
329 return (i);
330} 418}
331 419
332int 420int
333BIO_puts(BIO *b, const char *in) 421BIO_puts(BIO *b, const char *in)
334{ 422{
335 int i; 423 size_t writebytes = 0;
336 long (*cb)(BIO *, int, const char *, int, long, long); 424 int ret;
337 425
338 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) { 426 if (b == NULL || b->method == NULL || b->method->bputs == NULL) {
339 BIOerror(BIO_R_UNSUPPORTED_METHOD); 427 BIOerror(BIO_R_UNSUPPORTED_METHOD);
340 return (-2); 428 return (-2);
341 } 429 }
342 430
343 cb = b->callback; 431 if (b->callback != NULL || b->callback_ex != NULL) {
344 432 if ((ret = (int)bio_call_callback(b, BIO_CB_PUTS, in, 0, 0, 0L,
345 if ((cb != NULL) && 433 1L, NULL)) <= 0)
346 ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0)) 434 return (ret);
347 return (i); 435 }
348 436
349 if (!b->init) { 437 if (!b->init) {
350 BIOerror(BIO_R_UNINITIALIZED); 438 BIOerror(BIO_R_UNINITIALIZED);
351 return (-2); 439 return (-2);
352 } 440 }
353 441
354 i = b->method->bputs(b, in); 442 if ((ret = b->method->bputs(b, in)) > 0)
443 writebytes = ret;
355 444
356 if (i > 0) 445 b->num_write += writebytes;
357 b->num_write += (unsigned long)i;
358 446
359 if (cb != NULL) 447 if (b->callback != NULL || b->callback_ex != NULL) {
360 i = (int)cb(b, BIO_CB_PUTS|BIO_CB_RETURN, in, 0, 0L, (long)i); 448 ret = (int)bio_call_callback(b, BIO_CB_PUTS | BIO_CB_RETURN,
361 return (i); 449 in, 0, 0, 0L, (ret > 0) ? 1 : ret, &writebytes);
450 }
451
452 if (ret > 0) {
453 if (writebytes > INT_MAX) {
454 BIOerror(BIO_R_LENGTH_TOO_LONG);
455 ret = -1;
456 } else {
457 ret = (int)writebytes;
458 }
459 }
460
461 return (ret);
362} 462}
363 463
364int 464int
365BIO_gets(BIO *b, char *in, int inl) 465BIO_gets(BIO *b, char *in, int inl)
366{ 466{
367 int i; 467 size_t readbytes;
368 long (*cb)(BIO *, int, const char *, int, long, long); 468 int ret;
369 469
370 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) { 470 if (b == NULL || b->method == NULL || b->method->bgets == NULL) {
371 BIOerror(BIO_R_UNSUPPORTED_METHOD); 471 BIOerror(BIO_R_UNSUPPORTED_METHOD);
372 return (-2); 472 return (-2);
373 } 473 }
374 474
375 cb = b->callback; 475 if (b->callback != NULL || b->callback_ex != NULL) {
376 476 if ((ret = (int)bio_call_callback(b, BIO_CB_GETS, in, inl, 0, 0L,
377 if ((cb != NULL) && 477 1, NULL)) <= 0)
378 ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0)) 478 return (ret);
379 return (i); 479 }
380 480
381 if (!b->init) { 481 if (!b->init) {
382 BIOerror(BIO_R_UNINITIALIZED); 482 BIOerror(BIO_R_UNINITIALIZED);
383 return (-2); 483 return (-2);
384 } 484 }
385 485
386 i = b->method->bgets(b, in, inl); 486 if ((ret = b->method->bgets(b, in, inl)) > 0)
487 readbytes = ret;
488
489 if (b->callback != NULL || b->callback_ex != NULL) {
490 ret = (int)bio_call_callback(b, BIO_CB_GETS | BIO_CB_RETURN, in,
491 inl, 0, 0L, (ret > 0) ? 1 : ret, &readbytes);
492 }
493
494 if (ret > 0) {
495 if (readbytes > INT_MAX) {
496 BIOerror(BIO_R_LENGTH_TOO_LONG);
497 ret = -1;
498 } else {
499 ret = (int)readbytes;
500 }
501 }
387 502
388 if (cb != NULL) 503 return (ret);
389 i = (int)cb(b, BIO_CB_GETS|BIO_CB_RETURN, in, inl, 0L, (long)i);
390 return (i);
391} 504}
392 505
393int 506int
@@ -427,54 +540,58 @@ long
427BIO_ctrl(BIO *b, int cmd, long larg, void *parg) 540BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
428{ 541{
429 long ret; 542 long ret;
430 long (*cb)(BIO *, int, const char *, int, long, long);
431 543
432 if (b == NULL) 544 if (b == NULL)
433 return (0); 545 return (0);
434 546
435 if ((b->method == NULL) || (b->method->ctrl == NULL)) { 547 if (b->method == NULL || b->method->ctrl == NULL) {
436 BIOerror(BIO_R_UNSUPPORTED_METHOD); 548 BIOerror(BIO_R_UNSUPPORTED_METHOD);
437 return (-2); 549 return (-2);
438 } 550 }
439 551
440 cb = b->callback; 552 if (b->callback != NULL || b->callback_ex != NULL) {
441 553 if ((ret = bio_call_callback(b, BIO_CB_CTRL, parg, 0, cmd, larg,
442 if ((cb != NULL) && 554 1L, NULL)) <= 0)
443 ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0)) 555 return (ret);
444 return (ret); 556 }
445 557
446 ret = b->method->ctrl(b, cmd, larg, parg); 558 ret = b->method->ctrl(b, cmd, larg, parg);
447 559
448 if (cb != NULL) 560 if (b->callback != NULL || b->callback_ex != NULL) {
449 ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret); 561 ret = bio_call_callback(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, 0,
562 cmd, larg, ret, NULL);
563 }
564
450 return (ret); 565 return (ret);
451} 566}
452 567
453long 568long
454BIO_callback_ctrl(BIO *b, int cmd, 569BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
455 void (*fp)(struct bio_st *, int, const char *, int, long, long))
456{ 570{
457 long ret; 571 long ret;
458 long (*cb)(BIO *, int, const char *, int, long, long);
459 572
460 if (b == NULL) 573 if (b == NULL)
461 return (0); 574 return (0);
462 575
463 if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) { 576 if (b->method == NULL || b->method->callback_ctrl == NULL ||
577 cmd != BIO_CTRL_SET_CALLBACK) {
464 BIOerror(BIO_R_UNSUPPORTED_METHOD); 578 BIOerror(BIO_R_UNSUPPORTED_METHOD);
465 return (-2); 579 return (-2);
466 } 580 }
467 581
468 cb = b->callback; 582 if (b->callback != NULL || b->callback_ex != NULL) {
469 583 if ((ret = bio_call_callback(b, BIO_CB_CTRL, (void *)&fp, 0,
470 if ((cb != NULL) && 584 cmd, 0, 1L, NULL)) <= 0)
471 ((ret = cb(b, BIO_CB_CTRL, (void *)&fp, cmd, 0, 1L)) <= 0)) 585 return (ret);
472 return (ret); 586 }
473 587
474 ret = b->method->callback_ctrl(b, cmd, fp); 588 ret = b->method->callback_ctrl(b, cmd, fp);
475 589
476 if (cb != NULL) 590 if (b->callback != NULL || b->callback_ex != NULL) {
477 ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, (void *)&fp, cmd, 0, ret); 591 ret = bio_call_callback(b, BIO_CB_CTRL | BIO_CB_RETURN,
592 (void *)&fp, 0, cmd, 0, ret, NULL);
593 }
594
478 return (ret); 595 return (ret);
479} 596}
480 597
@@ -628,6 +745,7 @@ BIO_dup_chain(BIO *in)
628 if ((new_bio = BIO_new(bio->method)) == NULL) 745 if ((new_bio = BIO_new(bio->method)) == NULL)
629 goto err; 746 goto err;
630 new_bio->callback = bio->callback; 747 new_bio->callback = bio->callback;
748 new_bio->callback_ex = bio->callback_ex;
631 new_bio->cb_arg = bio->cb_arg; 749 new_bio->cb_arg = bio->cb_arg;
632 new_bio->init = bio->init; 750 new_bio->init = bio->init;
633 new_bio->shutdown = bio->shutdown; 751 new_bio->shutdown = bio->shutdown;
diff --git a/src/lib/libcrypto/bio/bio_local.h b/src/lib/libcrypto/bio/bio_local.h
index 62a9793d00..7e1885f393 100644
--- a/src/lib/libcrypto/bio/bio_local.h
+++ b/src/lib/libcrypto/bio/bio_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_local.h,v 1.2 2022/01/14 08:18:55 tb Exp $ */ 1/* $OpenBSD: bio_local.h,v 1.3 2022/01/14 08:40:57 tb 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 *
@@ -71,13 +71,13 @@ struct bio_method_st {
71 long (*ctrl)(BIO *, int, long, void *); 71 long (*ctrl)(BIO *, int, long, void *);
72 int (*create)(BIO *); 72 int (*create)(BIO *);
73 int (*destroy)(BIO *); 73 int (*destroy)(BIO *);
74 long (*callback_ctrl)(BIO *, int, bio_info_cb *); 74 long (*callback_ctrl)(BIO *, int, BIO_info_cb *);
75} /* BIO_METHOD */; 75} /* BIO_METHOD */;
76 76
77struct bio_st { 77struct bio_st {
78 const BIO_METHOD *method; 78 const BIO_METHOD *method;
79 /* bio, mode, argp, argi, argl, ret */ 79 BIO_callback_fn callback;
80 long (*callback)(struct bio_st *, int, const char *, int, long, long); 80 BIO_callback_fn_ex callback_ex;
81 char *cb_arg; /* first argument for the callback */ 81 char *cb_arg; /* first argument for the callback */
82 82
83 int init; 83 int init;
diff --git a/src/lib/libcrypto/bio/bio_meth.c b/src/lib/libcrypto/bio/bio_meth.c
index b9c07d5111..d7d100df95 100644
--- a/src/lib/libcrypto/bio/bio_meth.c
+++ b/src/lib/libcrypto/bio/bio_meth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_meth.c,v 1.7 2022/01/07 09:02:17 tb Exp $ */ 1/* $OpenBSD: bio_meth.c,v 1.8 2022/01/14 08:40:57 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> 3 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
4 * 4 *
@@ -135,15 +135,13 @@ BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *))
135long 135long
136(*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *) 136(*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *)
137{ 137{
138 return 138 return biom->callback_ctrl;
139 (long (*)(BIO *, int, BIO_info_cb *))biom->callback_ctrl; /* XXX */
140} 139}
141 140
142int 141int
143BIO_meth_set_callback_ctrl(BIO_METHOD *biom, 142BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
144 long (*callback_ctrl)(BIO *, int, BIO_info_cb *)) 143 long (*callback_ctrl)(BIO *, int, BIO_info_cb *))
145{ 144{
146 biom->callback_ctrl = 145 biom->callback_ctrl = callback_ctrl;
147 (long (*)(BIO *, int, bio_info_cb *))callback_ctrl; /* XXX */
148 return 1; 146 return 1;
149} 147}
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
index 8ed8d2076d..8e30bccd51 100644
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bss_conn.c,v 1.36 2022/01/07 09:02:17 tb Exp $ */ 1/* $OpenBSD: bss_conn.c,v 1.37 2022/01/14 08:40:57 tb 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 *
@@ -92,7 +92,7 @@ typedef struct bio_connect_st {
92 /* called when the connection is initially made 92 /* called when the connection is initially made
93 * callback(BIO,state,ret); The callback should return 93 * callback(BIO,state,ret); The callback should return
94 * 'ret'. state is for compatibility with the ssl info_callback */ 94 * 'ret'. state is for compatibility with the ssl info_callback */
95 int (*info_callback)(const BIO *bio, int state, int ret); 95 BIO_info_cb *info_callback;
96} BIO_CONNECT; 96} BIO_CONNECT;
97 97
98static int conn_write(BIO *h, const char *buf, int num); 98static int conn_write(BIO *h, const char *buf, int num);
@@ -101,7 +101,7 @@ static int conn_puts(BIO *h, const char *str);
101static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2); 101static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2);
102static int conn_new(BIO *h); 102static int conn_new(BIO *h);
103static int conn_free(BIO *data); 103static int conn_free(BIO *data);
104static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *); 104static long conn_callback_ctrl(BIO *h, int cmd, BIO_info_cb *);
105 105
106static int conn_state(BIO *b, BIO_CONNECT *c); 106static int conn_state(BIO *b, BIO_CONNECT *c);
107static void conn_close_socket(BIO *data); 107static void conn_close_socket(BIO *data);
@@ -126,7 +126,7 @@ conn_state(BIO *b, BIO_CONNECT *c)
126 int ret = -1, i; 126 int ret = -1, i;
127 unsigned long l; 127 unsigned long l;
128 char *p, *q; 128 char *p, *q;
129 int (*cb)(const BIO *, int, int) = NULL; 129 BIO_info_cb *cb = NULL;
130 130
131 if (c->info_callback != NULL) 131 if (c->info_callback != NULL)
132 cb = c->info_callback; 132 cb = c->info_callback;
@@ -523,9 +523,7 @@ conn_ctrl(BIO *b, int cmd, long num, void *ptr)
523 BIO_set_conn_hostname(dbio, 523 BIO_set_conn_hostname(dbio,
524 data->param_hostname); 524 data->param_hostname);
525 BIO_set_nbio(dbio, data->nbio); 525 BIO_set_nbio(dbio, data->nbio);
526 /* FIXME: the cast of the function seems unlikely to be a good idea */ 526 (void)BIO_set_info_callback(dbio, data->info_callback);
527 (void)BIO_set_info_callback(dbio,
528 (bio_info_cb *)data->info_callback);
529 } 527 }
530 break; 528 break;
531 case BIO_CTRL_SET_CALLBACK: 529 case BIO_CTRL_SET_CALLBACK:
@@ -540,9 +538,8 @@ conn_ctrl(BIO *b, int cmd, long num, void *ptr)
540 break; 538 break;
541 case BIO_CTRL_GET_CALLBACK: 539 case BIO_CTRL_GET_CALLBACK:
542 { 540 {
543 int (**fptr)(const BIO *bio, int state, int xret); 541 BIO_info_cb **fptr = ptr;
544 542
545 fptr = (int (**)(const BIO *bio, int state, int xret))ptr;
546 *fptr = data->info_callback; 543 *fptr = data->info_callback;
547 } 544 }
548 break; 545 break;
@@ -554,7 +551,7 @@ conn_ctrl(BIO *b, int cmd, long num, void *ptr)
554} 551}
555 552
556static long 553static long
557conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 554conn_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
558{ 555{
559 long ret = 1; 556 long ret = 1;
560 BIO_CONNECT *data; 557 BIO_CONNECT *data;
@@ -563,9 +560,7 @@ conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
563 560
564 switch (cmd) { 561 switch (cmd) {
565 case BIO_CTRL_SET_CALLBACK: 562 case BIO_CTRL_SET_CALLBACK:
566 { 563 data->info_callback = (BIO_info_cb *)fp;
567 data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
568 }
569 break; 564 break;
570 default: 565 default:
571 ret = 0; 566 ret = 0;
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
index 4c527d57de..bdcd7e0f35 100644
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: c_zlib.c,v 1.21 2022/01/09 23:50:10 tb Exp $ */ 1/* $OpenBSD: c_zlib.c,v 1.22 2022/01/14 08:40:57 tb Exp $ */
2#include <stdio.h> 2#include <stdio.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
@@ -234,7 +234,7 @@ static int bio_zlib_free(BIO *bi);
234static int bio_zlib_read(BIO *b, char *out, int outl); 234static int bio_zlib_read(BIO *b, char *out, int outl);
235static int bio_zlib_write(BIO *b, const char *in, int inl); 235static int bio_zlib_write(BIO *b, const char *in, int inl);
236static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr); 236static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr);
237static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp); 237static long bio_zlib_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp);
238 238
239static BIO_METHOD bio_meth_zlib = { 239static BIO_METHOD bio_meth_zlib = {
240 .type = BIO_TYPE_COMP, 240 .type = BIO_TYPE_COMP,
@@ -555,7 +555,7 @@ bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
555 555
556 556
557static long 557static long
558bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 558bio_zlib_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
559{ 559{
560 if (!b->next_bio) 560 if (!b->next_bio)
561 return 0; 561 return 0;
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
index c1ec25d9c4..b61a342a3e 100644
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_b64.c,v 1.24 2022/01/07 09:02:18 tb Exp $ */ 1/* $OpenBSD: bio_b64.c,v 1.25 2022/01/14 08:40:57 tb 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 *
@@ -73,7 +73,7 @@ static int b64_puts(BIO *h, const char *str);
73static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2); 73static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2);
74static int b64_new(BIO *h); 74static int b64_new(BIO *h);
75static int b64_free(BIO *data); 75static int b64_free(BIO *data);
76static long b64_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); 76static long b64_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
77#define B64_BLOCK_SIZE 1024 77#define B64_BLOCK_SIZE 1024
78#define B64_BLOCK_SIZE2 768 78#define B64_BLOCK_SIZE2 768
79#define B64_NONE 0 79#define B64_NONE 0
@@ -550,7 +550,7 @@ again:
550} 550}
551 551
552static long 552static long
553b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 553b64_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
554{ 554{
555 long ret = 1; 555 long ret = 1;
556 556
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index 6ab07e13d9..2a0f76fcbe 100644
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_enc.c,v 1.25 2022/01/07 09:02:18 tb Exp $ */ 1/* $OpenBSD: bio_enc.c,v 1.26 2022/01/14 08:40:57 tb 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 *
@@ -73,7 +73,7 @@ static int enc_read(BIO *h, char *buf, int size);
73static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2); 73static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2);
74static int enc_new(BIO *h); 74static int enc_new(BIO *h);
75static int enc_free(BIO *data); 75static int enc_free(BIO *data);
76static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps); 76static long enc_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fps);
77#define ENC_BLOCK_SIZE (1024*4) 77#define ENC_BLOCK_SIZE (1024*4)
78#define BUF_OFFSET (EVP_MAX_BLOCK_LENGTH*2) 78#define BUF_OFFSET (EVP_MAX_BLOCK_LENGTH*2)
79 79
@@ -373,7 +373,7 @@ again:
373} 373}
374 374
375static long 375static long
376enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 376enc_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
377{ 377{
378 long ret = 1; 378 long ret = 1;
379 379
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
index a83088a963..4ae5f1f496 100644
--- a/src/lib/libcrypto/evp/bio_md.c
+++ b/src/lib/libcrypto/evp/bio_md.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_md.c,v 1.17 2022/01/07 09:02:18 tb Exp $ */ 1/* $OpenBSD: bio_md.c,v 1.18 2022/01/14 08:40:57 tb 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 *
@@ -75,7 +75,7 @@ static int md_gets(BIO *h, char *str, int size);
75static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2); 75static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2);
76static int md_new(BIO *h); 76static int md_new(BIO *h);
77static int md_free(BIO *data); 77static int md_free(BIO *data);
78static long md_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); 78static long md_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
79 79
80static const BIO_METHOD methods_md = { 80static const BIO_METHOD methods_md = {
81 .type = BIO_TYPE_MD, 81 .type = BIO_TYPE_MD,
@@ -241,7 +241,7 @@ md_ctrl(BIO *b, int cmd, long num, void *ptr)
241} 241}
242 242
243static long 243static long
244md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) 244md_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
245{ 245{
246 long ret = 1; 246 long ret = 1;
247 247