[openssl-commits] [openssl] master update
Matt Caswell
matt at openssl.org
Tue Mar 29 16:46:05 UTC 2016
The branch master has been updated
via eb47aae5d33de3d39379c15e20cbbd12ea8a29be (commit)
via 85556b4dec97b1402e1edeaef6ffc0e9cd931457 (commit)
via 173755255837d22c2bfbfe455164c67758224cb1 (commit)
via a146ae55ba479a5c7aa2a6afba1b2b93102a152c (commit)
via f334461facc4078adbad6552563f77799c174cab (commit)
via 1a50b8139a6221d65bc526ab415c77b0561ff708 (commit)
from bbe9769ba66ab2512678a87b0d9b266ba970db05 (commit)
- Log -----------------------------------------------------------------
commit eb47aae5d33de3d39379c15e20cbbd12ea8a29be
Author: Matt Caswell <matt at openssl.org>
Date: Tue Mar 29 16:03:08 2016 +0100
Add a CHANGES entry for opaque BIOs
Reviewed-by: Richard Levitte <levitte at openssl.org>
commit 85556b4dec97b1402e1edeaef6ffc0e9cd931457
Author: Matt Caswell <matt at openssl.org>
Date: Tue Mar 29 14:25:23 2016 +0100
Add documentation for BIO functions
Add the documentation for new BIO functions added as a result of
making BIO and BIO_METHOD opaque.
Reviewed-by: Richard Levitte <levitte at openssl.org>
commit 173755255837d22c2bfbfe455164c67758224cb1
Author: Matt Caswell <matt at openssl.org>
Date: Wed Mar 23 15:05:27 2016 +0000
make update
Reviewed-by: Richard Levitte <levitte at openssl.org>
commit a146ae55ba479a5c7aa2a6afba1b2b93102a152c
Author: Matt Caswell <matt at openssl.org>
Date: Tue Mar 22 09:21:29 2016 +0000
Make BIO opaque
Move the the BIO_METHOD and BIO structures into internal header files,
provide appropriate accessor methods and update all internal code to use
the new accessors where appropriate.
Reviewed-by: Richard Levitte <levitte at openssl.org>
commit f334461facc4078adbad6552563f77799c174cab
Author: Matt Caswell <matt at openssl.org>
Date: Tue Mar 22 11:34:32 2016 +0000
Add functions for creating BIO_METHODs
BIO_METHODs are soon to be opaque so we need to have functions available
to set them up.
Reviewed-by: Richard Levitte <levitte at openssl.org>
commit 1a50b8139a6221d65bc526ab415c77b0561ff708
Author: FdaSilvaYY <fdasilvayy at gmail.com>
Date: Sat Mar 19 00:40:11 2016 +0100
Fix a big leak when using stack-allocated BIO items.
Reviewed-by: Richard Levitte <levitte at openssl.org>
Reviewed-by: Matt Caswell <matt at openssl.org>
-----------------------------------------------------------------------
Summary of changes:
CHANGES | 7 +-
crypto/asn1/asn_mime.c | 1 +
crypto/asn1/bio_asn1.c | 67 ++++++-----
crypto/bio/Makefile.in | 4 +-
crypto/bio/bf_buff.c | 2 +-
crypto/bio/bf_nbio.c | 2 +-
crypto/bio/bf_null.c | 2 +-
crypto/bio/bio_cb.c | 2 +-
crypto/bio/bio_lcl.h | 45 ++++++-
crypto/bio/bio_lib.c | 42 ++++++-
crypto/{engine/tb_digest.c => bio/bio_meth.c} | 134 +++++++++++++--------
crypto/bio/bss_bio.c | 2 +-
crypto/bio/bss_log.c | 1 +
crypto/bio/bss_mem.c | 2 +-
crypto/bio/bss_null.c | 2 +-
crypto/bio/bss_sock.c | 1 +
crypto/bio/build.info | 2 +-
crypto/err/err_prn.c | 29 ++---
crypto/evp/bio_b64.c | 85 ++++++++-----
crypto/evp/bio_enc.c | 100 +++++++++------
crypto/evp/bio_md.c | 100 +++++++--------
crypto/evp/bio_ok.c | 97 +++++++++------
doc/crypto/BIO_get_data.pod | 56 +++++++++
doc/crypto/BIO_meth_new.pod | 117 ++++++++++++++++++
doc/crypto/BIO_push.pod | 19 ++-
doc/crypto/BIO_should_retry.pod | 20 ++-
.../internal/async.h => include/internal/bio.h | 21 +++-
include/openssl/bio.h | 94 ++++++---------
ssl/bio_ssl.c | 120 +++++++++---------
ssl/ssl_lib.c | 4 +-
util/libcrypto.num | 26 ++++
31 files changed, 807 insertions(+), 399 deletions(-)
copy crypto/{engine/tb_digest.c => bio/bio_meth.c} (53%)
create mode 100644 doc/crypto/BIO_get_data.pod
create mode 100644 doc/crypto/BIO_meth_new.pod
copy crypto/include/internal/async.h => include/internal/bio.h (86%)
diff --git a/CHANGES b/CHANGES
index cdc8518..8597b8a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,8 +4,13 @@
Changes between 1.0.2g and 1.1.0 [xx XXX xxxx]
+ *) Made BIO and BIO_METHOD opaque. The structures for managing BIOs have been
+ moved out of the public header files. New functions for managing these
+ have been added.
+ [Matt Caswell]
+
*) Removed no-rijndael as a config option. Rijndael is an old name for AES.
- [Matt Caswell}
+ [Matt Caswell]
*) Removed the mk1mf build scripts.
[Richard Levitte]
diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c
index 6ac9b2c..851fb91 100644
--- a/crypto/asn1/asn_mime.c
+++ b/crypto/asn1/asn_mime.c
@@ -60,6 +60,7 @@
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include "internal/evp_int.h"
+#include "internal/bio.h"
#include "asn1_locl.h"
/*
diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c
index 80206aa..1657ac7 100644
--- a/crypto/asn1/bio_asn1.c
+++ b/crypto/asn1/bio_asn1.c
@@ -63,7 +63,7 @@
*/
#include <string.h>
-#include <openssl/bio.h>
+#include <internal/bio.h>
#include <openssl/asn1.h>
/* Must be large enough for biggest tag+length */
@@ -152,9 +152,9 @@ static int asn1_bio_new(BIO *b)
OPENSSL_free(ctx);
return 0;
}
- b->init = 1;
- b->ptr = (char *)ctx;
- b->flags = 0;
+ BIO_set_data(b, ctx);
+ BIO_set_init(b, 1);
+
return 1;
}
@@ -178,15 +178,20 @@ static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
static int asn1_bio_free(BIO *b)
{
- BIO_ASN1_BUF_CTX *ctx = (BIO_ASN1_BUF_CTX *)b->ptr;
+ BIO_ASN1_BUF_CTX *ctx;
+
+ if (b == NULL)
+ return 0;
+ ctx = BIO_get_data(b);
if (ctx == NULL)
return 0;
+
OPENSSL_free(ctx->buf);
OPENSSL_free(ctx);
- b->init = 0;
- b->ptr = NULL;
- b->flags = 0;
+ BIO_set_data(b, NULL);
+ BIO_set_init(b, 0);
+
return 1;
}
@@ -195,10 +200,11 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
BIO_ASN1_BUF_CTX *ctx;
int wrmax, wrlen, ret;
unsigned char *p;
- if (!in || (inl < 0) || (b->next_bio == NULL))
- return 0;
- ctx = (BIO_ASN1_BUF_CTX *)b->ptr;
- if (ctx == NULL)
+ BIO *next;
+
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
+ if (in == NULL || inl < 0 || ctx == NULL || next == NULL)
return 0;
wrlen = 0;
@@ -236,7 +242,7 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
break;
case ASN1_STATE_HEADER_COPY:
- ret = BIO_write(b->next_bio, ctx->buf + ctx->bufpos, ctx->buflen);
+ ret = BIO_write(next, ctx->buf + ctx->bufpos, ctx->buflen);
if (ret <= 0)
goto done;
@@ -256,7 +262,7 @@ static int asn1_bio_write(BIO *b, const char *in, int inl)
wrmax = ctx->copylen;
else
wrmax = inl;
- ret = BIO_write(b->next_bio, in, wrmax);
+ ret = BIO_write(next, in, wrmax);
if (ret <= 0)
break;
wrlen += ret;
@@ -292,10 +298,11 @@ static int asn1_bio_flush_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
asn1_ps_func *cleanup, asn1_bio_state_t next)
{
int ret;
+
if (ctx->ex_len <= 0)
return 1;
for (;;) {
- ret = BIO_write(b->next_bio, ctx->ex_buf + ctx->ex_pos, ctx->ex_len);
+ ret = BIO_write(BIO_next(b), ctx->ex_buf + ctx->ex_pos, ctx->ex_len);
if (ret <= 0)
break;
ctx->ex_len -= ret;
@@ -330,9 +337,10 @@ static int asn1_bio_setup_ex(BIO *b, BIO_ASN1_BUF_CTX *ctx,
static int asn1_bio_read(BIO *b, char *in, int inl)
{
- if (!b->next_bio)
+ BIO *next = BIO_next(b);
+ if (next == NULL)
return 0;
- return BIO_read(b->next_bio, in, inl);
+ return BIO_read(next, in, inl);
}
static int asn1_bio_puts(BIO *b, const char *str)
@@ -342,16 +350,18 @@ static int asn1_bio_puts(BIO *b, const char *str)
static int asn1_bio_gets(BIO *b, char *str, int size)
{
- if (!b->next_bio)
+ BIO *next = BIO_next(b);
+ if (next == NULL)
return 0;
- return BIO_gets(b->next_bio, str, size);
+ return BIO_gets(next, str, size);
}
static long asn1_bio_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
- if (b->next_bio == NULL)
- return (0);
- return BIO_callback_ctrl(b->next_bio, cmd, fp);
+ BIO *next = BIO_next(b);
+ if (next == NULL)
+ return 0;
+ return BIO_callback_ctrl(next, cmd, fp);
}
static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
@@ -359,9 +369,12 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
BIO_ASN1_BUF_CTX *ctx;
BIO_ASN1_EX_FUNCS *ex_func;
long ret = 1;
- ctx = (BIO_ASN1_BUF_CTX *)b->ptr;
+ BIO *next;
+
+ ctx = BIO_get_data(b);
if (ctx == NULL)
return 0;
+ next = BIO_next(b);
switch (cmd) {
case BIO_C_SET_PREFIX:
@@ -397,7 +410,7 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
break;
case BIO_CTRL_FLUSH:
- if (!b->next_bio)
+ if (next == NULL)
return 0;
/* Call post function if possible */
@@ -415,16 +428,16 @@ static long asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2)
}
if (ctx->state == ASN1_STATE_DONE)
- return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
+ return BIO_ctrl(next, cmd, arg1, arg2);
else {
BIO_clear_retry_flags(b);
return 0;
}
default:
- if (!b->next_bio)
+ if (next == NULL)
return 0;
- return BIO_ctrl(b->next_bio, cmd, arg1, arg2);
+ return BIO_ctrl(next, cmd, arg1, arg2);
}
diff --git a/crypto/bio/Makefile.in b/crypto/bio/Makefile.in
index 12cf6c6..f57d357 100644
--- a/crypto/bio/Makefile.in
+++ b/crypto/bio/Makefile.in
@@ -20,14 +20,14 @@ LIBSRC= bio_lib.c bio_cb.c bio_err.c \
bss_file.c bss_sock.c bss_conn.c \
bf_null.c bf_buff.c b_print.c b_dump.c b_addr.c \
b_sock.c b_sock2.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c \
- bss_dgram.c
+ bss_dgram.c bio_meth.c
# bf_lbuf.c
LIBOBJ= bio_lib.o bio_cb.o bio_err.o \
bss_mem.o bss_null.o bss_fd.o \
bss_file.o bss_sock.o bss_conn.o \
bf_null.o bf_buff.o b_print.o b_dump.o b_addr.o \
b_sock.o b_sock2.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o \
- bss_dgram.o
+ bss_dgram.o bio_meth.o
# bf_lbuf.o
SRC= $(LIBSRC)
diff --git a/crypto/bio/bf_buff.c b/crypto/bio/bf_buff.c
index 6040c85..361d26a 100644
--- a/crypto/bio/bf_buff.c
+++ b/crypto/bio/bf_buff.c
@@ -57,8 +57,8 @@
#include <stdio.h>
#include <errno.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
-#include <openssl/bio.h>
static int buffer_write(BIO *h, const char *buf, int num);
static int buffer_read(BIO *h, char *buf, int size);
diff --git a/crypto/bio/bf_nbio.c b/crypto/bio/bf_nbio.c
index c8bf580..cefd35f 100644
--- a/crypto/bio/bf_nbio.c
+++ b/crypto/bio/bf_nbio.c
@@ -57,9 +57,9 @@
#include <stdio.h>
#include <errno.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
#include <openssl/rand.h>
-#include <openssl/bio.h>
/*
* BIO_put and BIO_get both add to the digest, BIO_gets returns the digest
diff --git a/crypto/bio/bf_null.c b/crypto/bio/bf_null.c
index e3b87d2..162e250 100644
--- a/crypto/bio/bf_null.c
+++ b/crypto/bio/bf_null.c
@@ -57,8 +57,8 @@
#include <stdio.h>
#include <errno.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
-#include <openssl/bio.h>
/*
* BIO_put and BIO_get both add to the digest, BIO_gets returns the digest
diff --git a/crypto/bio/bio_cb.c b/crypto/bio/bio_cb.c
index ec484b6..552b66e 100644
--- a/crypto/bio/bio_cb.c
+++ b/crypto/bio/bio_cb.c
@@ -58,8 +58,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
-#include <openssl/bio.h>
#include <openssl/err.h>
long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
diff --git a/crypto/bio/bio_lcl.h b/crypto/bio/bio_lcl.h
index 24f8b18..1e409f8 100644
--- a/crypto/bio/bio_lcl.h
+++ b/crypto/bio/bio_lcl.h
@@ -65,7 +65,50 @@ union bio_addr_st {
/* END BIO_ADDRINFO/BIO_ADDR stuff. */
#include "internal/cryptlib.h"
-#include <openssl/bio.h>
+#include <internal/bio.h>
+
+typedef struct bio_f_buffer_ctx_struct {
+ /*-
+ * Buffers are setup like this:
+ *
+ * <---------------------- size ----------------------->
+ * +---------------------------------------------------+
+ * | consumed | remaining | free space |
+ * +---------------------------------------------------+
+ * <-- off --><------- len ------->
+ */
+ /*- BIO *bio; *//*
+ * this is now in the BIO struct
+ */
+ int ibuf_size; /* how big is the input buffer */
+ int obuf_size; /* how big is the output buffer */
+ char *ibuf; /* the char array */
+ int ibuf_len; /* how many bytes are in it */
+ int ibuf_off; /* write/read offset */
+ char *obuf; /* the char array */
+ int obuf_len; /* how many bytes are in it */
+ int obuf_off; /* write/read offset */
+} BIO_F_BUFFER_CTX;
+
+struct bio_st {
+ const BIO_METHOD *method;
+ /* bio, mode, argp, argi, argl, ret */
+ long (*callback) (struct bio_st *, int, const char *, int, long, long);
+ char *cb_arg; /* first argument for the callback */
+ int init;
+ int shutdown;
+ int flags; /* extra storage */
+ int retry_reason;
+ int num;
+ void *ptr;
+ struct bio_st *next_bio; /* used by filter BIOs */
+ struct bio_st *prev_bio; /* used by filter BIOs */
+ int references;
+ uint64_t num_read;
+ uint64_t num_write;
+ CRYPTO_EX_DATA ex_data;
+ CRYPTO_RWLOCK *lock;
+};
#ifndef OPENSSL_NO_SOCK
# ifdef OPENSSL_SYS_VMS
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
index 9357553..ac98cf2 100644
--- a/crypto/bio/bio_lib.c
+++ b/crypto/bio/bio_lib.c
@@ -58,8 +58,8 @@
#include <stdio.h>
#include <errno.h>
#include <openssl/crypto.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
-#include <openssl/bio.h>
#include <openssl/stack.h>
BIO *BIO_new(const BIO_METHOD *method)
@@ -142,6 +142,36 @@ int BIO_free(BIO *a)
return 1;
}
+void BIO_set_data(BIO *a, void *ptr)
+{
+ a->ptr = ptr;
+}
+
+void *BIO_get_data(BIO *a)
+{
+ return a->ptr;
+}
+
+void BIO_set_init(BIO *a, int init)
+{
+ a->init = init;
+}
+
+int BIO_get_init(BIO *a)
+{
+ return a->init;
+}
+
+void BIO_set_shutdown(BIO *a, int shut)
+{
+ a->shutdown = shut;
+}
+
+int BIO_get_shutdown(BIO *a)
+{
+ return a->shutdown;
+}
+
void BIO_vfree(BIO *a)
{
BIO_free(a);
@@ -487,6 +517,11 @@ int BIO_get_retry_reason(BIO *bio)
return (bio->retry_reason);
}
+void BIO_set_retry_reason(BIO *bio, int reason)
+{
+ bio->retry_reason = reason;
+}
+
BIO *BIO_find_type(BIO *bio, int type)
{
int mt, mask;
@@ -516,6 +551,11 @@ BIO *BIO_next(BIO *b)
return b->next_bio;
}
+void BIO_set_next(BIO *b, BIO *next)
+{
+ b->next_bio = next;
+}
+
void BIO_free_all(BIO *bio)
{
BIO *b;
diff --git a/crypto/engine/tb_digest.c b/crypto/bio/bio_meth.c
similarity index 53%
copy from crypto/engine/tb_digest.c
copy to crypto/bio/bio_meth.c
index 03096b3..134c448 100644
--- a/crypto/engine/tb_digest.c
+++ b/crypto/bio/bio_meth.c
@@ -1,5 +1,5 @@
/* ====================================================================
- * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 2016 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -21,7 +21,7 @@
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
- * licensing at OpenSSL.org.
+ * openssl-core at OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
@@ -52,85 +52,115 @@
*
*/
-#include "eng_int.h"
+#include "bio_lcl.h"
-static ENGINE_TABLE *digest_table = NULL;
+BIO_METHOD *BIO_meth_new(int type, const char *name)
+{
+ BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD));
-void ENGINE_unregister_digests(ENGINE *e)
+ if (biom != NULL) {
+ biom->type = type;
+ biom->name = name;
+ }
+ return biom;
+}
+
+void BIO_meth_free(BIO_METHOD *biom)
{
- engine_table_unregister(&digest_table, e);
+ OPENSSL_free(biom);
}
-static void engine_unregister_all_digests(void)
+int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int)
{
- engine_table_cleanup(&digest_table);
+ return biom->bwrite;
}
-int ENGINE_register_digests(ENGINE *e)
+int BIO_meth_set_write(BIO_METHOD *biom,
+ int (*write) (BIO *, const char *, int))
{
- if (e->digests) {
- const int *nids;
- int num_nids = e->digests(e, NULL, &nids, 0);
- if (num_nids > 0)
- return engine_table_register(&digest_table,
- engine_unregister_all_digests, e,
- nids, num_nids, 0);
- }
+ biom->bwrite = write;
return 1;
}
-void ENGINE_register_all_digests()
+int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int)
{
- ENGINE *e;
+ return biom->bread;
+}
- for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
- ENGINE_register_digests(e);
+int BIO_meth_set_read(BIO_METHOD *biom,
+ int (*read) (BIO *, char *, int))
+{
+ biom->bread = read;
+ return 1;
}
-int ENGINE_set_default_digests(ENGINE *e)
+int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *)
{
- if (e->digests) {
- const int *nids;
- int num_nids = e->digests(e, NULL, &nids, 0);
- if (num_nids > 0)
- return engine_table_register(&digest_table,
- engine_unregister_all_digests, e,
- nids, num_nids, 1);
- }
+ return biom->bputs;
+}
+
+int BIO_meth_set_puts(BIO_METHOD *biom,
+ int (*puts) (BIO *, const char *))
+{
+ biom->bputs = puts;
return 1;
}
-/*
- * Exposed API function to get a functional reference from the implementation
- * table (ie. try to get a functional reference from the tabled structural
- * references) for a given digest 'nid'
- */
-ENGINE *ENGINE_get_digest_engine(int nid)
+int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int)
{
- return engine_table_select(&digest_table, nid);
+ return biom->bgets;
}
-/* Obtains a digest implementation from an ENGINE functional reference */
-const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid)
+int BIO_meth_set_gets(BIO_METHOD *biom,
+ int (*gets) (BIO *, char *, int))
{
- const EVP_MD *ret;
- ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e);
- if (!fn || !fn(e, &ret, NULL, nid)) {
- ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST, ENGINE_R_UNIMPLEMENTED_DIGEST);
- return NULL;
- }
- return ret;
+ biom->bgets = gets;
+ return 1;
+}
+
+long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *)
+{
+ return biom->ctrl;
+}
+
+int BIO_meth_set_ctrl(BIO_METHOD *biom,
+ long (*ctrl) (BIO *, int, long, void *))
+{
+ biom->ctrl = ctrl;
+ return 1;
+}
+
+int (*BIO_meth_get_create(BIO_METHOD *biom)) (BIO *)
+{
+ return biom->create;
+}
+
+int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
+{
+ biom->create = create;
+ return 1;
+}
+
+int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *)
+{
+ return biom->destroy;
+}
+
+int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
+{
+ biom->destroy = destroy;
+ return 1;
}
-/* Gets the digest callback from an ENGINE structure */
-ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e)
+long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) (BIO *, int, bio_info_cb *)
{
- return e->digests;
+ return biom->callback_ctrl;
}
-/* Sets the digest callback in an ENGINE structure */
-int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f)
+int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
+ long (*callback_ctrl) (BIO *, int,
+ bio_info_cb *))
{
- e->digests = f;
+ biom->callback_ctrl = callback_ctrl;
return 1;
}
diff --git a/crypto/bio/bss_bio.c b/crypto/bio/bss_bio.c
index 518fa35..2991c3a 100644
--- a/crypto/bio/bss_bio.c
+++ b/crypto/bio/bss_bio.c
@@ -65,7 +65,7 @@
#include <stdlib.h>
#include <string.h>
-#include <openssl/bio.h>
+#include "bio_lcl.h"
#include <openssl/err.h>
#include <openssl/crypto.h>
diff --git a/crypto/bio/bss_log.c b/crypto/bio/bss_log.c
index a6bc0e7..c2c8c79 100644
--- a/crypto/bio/bss_log.c
+++ b/crypto/bio/bss_log.c
@@ -64,6 +64,7 @@
#include <stdio.h>
#include <errno.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
#if defined(OPENSSL_SYS_WINCE)
diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c
index 68ac90d..460e070 100644
--- a/crypto/bio/bss_mem.c
+++ b/crypto/bio/bss_mem.c
@@ -57,8 +57,8 @@
#include <stdio.h>
#include <errno.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
-#include <openssl/bio.h>
static int mem_write(BIO *h, const char *buf, int num);
static int mem_read(BIO *h, char *buf, int size);
diff --git a/crypto/bio/bss_null.c b/crypto/bio/bss_null.c
index c5e2484..29561c7 100644
--- a/crypto/bio/bss_null.c
+++ b/crypto/bio/bss_null.c
@@ -57,8 +57,8 @@
#include <stdio.h>
#include <errno.h>
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
-#include <openssl/bio.h>
static int null_write(BIO *h, const char *buf, int num);
static int null_read(BIO *h, char *buf, int size);
diff --git a/crypto/bio/bss_sock.c b/crypto/bio/bss_sock.c
index 85d7d66..c1f76a2 100644
--- a/crypto/bio/bss_sock.c
+++ b/crypto/bio/bss_sock.c
@@ -58,6 +58,7 @@
#include <stdio.h>
#include <errno.h>
#define USE_SOCKETS
+#include "bio_lcl.h"
#include "internal/cryptlib.h"
#ifndef OPENSSL_NO_SOCK
diff --git a/crypto/bio/build.info b/crypto/bio/build.info
index d976c6c..f462c50 100644
--- a/crypto/bio/build.info
+++ b/crypto/bio/build.info
@@ -5,5 +5,5 @@ SOURCE[../../libcrypto]=\
bss_file.c bss_sock.c bss_conn.c \
bf_null.c bf_buff.c b_print.c b_dump.c b_addr.c \
b_sock.c b_sock2.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c \
- bss_dgram.c \
+ bss_dgram.c bio_meth.c \
{- $config{target} =~ /^VMS/i ? "bf_lbuf.c" : "" -}
diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c
index ac6b81f..0f7d40c 100644
--- a/crypto/err/err_prn.c
+++ b/crypto/err/err_prn.c
@@ -92,23 +92,6 @@ void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
}
}
-#ifndef OPENSSL_NO_STDIO
-static int print_fp(const char *str, size_t len, void *fp)
-{
- BIO bio;
-
- BIO_set(&bio, BIO_s_file());
- BIO_set_fp(&bio, fp, BIO_NOCLOSE);
-
- return BIO_printf(&bio, "%s", str);
-}
-
-void ERR_print_errors_fp(FILE *fp)
-{
- ERR_print_errors_cb(print_fp, fp);
-}
-#endif
-
static int print_bio(const char *str, size_t len, void *bp)
{
return BIO_write((BIO *)bp, str, len);
@@ -118,3 +101,15 @@ void ERR_print_errors(BIO *bp)
{
ERR_print_errors_cb(print_bio, bp);
}
+
+#ifndef OPENSSL_NO_STDIO
+void ERR_print_errors_fp(FILE *fp)
+{
+ BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
+ if (bio == NULL)
+ return;
+
+ ERR_print_errors_cb(print_bio, bio);
+ BIO_free(bio);
+}
+#endif
diff --git a/crypto/evp/bio_b64.c b/crypto/evp/bio_b64.c
index 93e4166..cdb50b4 100644
--- a/crypto/evp/bio_b64.c
+++ b/crypto/evp/bio_b64.c
@@ -60,6 +60,7 @@
#include "internal/cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/evp.h>
+#include "internal/bio.h"
static int b64_write(BIO *h, const char *buf, int num);
static int b64_read(BIO *h, char *buf, int size);
@@ -105,9 +106,10 @@ static const BIO_METHOD methods_b64 = {
b64_callback_ctrl,
};
+
const BIO_METHOD *BIO_f_base64(void)
{
- return (&methods_b64);
+ return &methods_b64;
}
static int b64_new(BIO *bi)
@@ -121,23 +123,28 @@ static int b64_new(BIO *bi)
ctx->cont = 1;
ctx->start = 1;
ctx->base64 = EVP_ENCODE_CTX_new();
- bi->init = 1;
- bi->ptr = (char *)ctx;
- bi->flags = 0;
- bi->num = 0;
- return (1);
+ BIO_set_data(bi, ctx);
+ BIO_set_init(bi, 1);
+
+ return 1;
}
static int b64_free(BIO *a)
{
+ BIO_B64_CTX *ctx;
if (a == NULL)
- return (0);
- EVP_ENCODE_CTX_free(((BIO_B64_CTX *)a->ptr)->base64);
- OPENSSL_free(a->ptr);
- a->ptr = NULL;
- a->init = 0;
- a->flags = 0;
- return (1);
+ return 0;
+
+ ctx = BIO_get_data(a);
+ if (ctx == NULL)
+ return 0;
+
+ EVP_ENCODE_CTX_free(ctx->base64);
+ OPENSSL_free(ctx);
+ BIO_set_data(a, NULL);
+ BIO_set_init(a, 0);
+
+ return 1;
}
static int b64_read(BIO *b, char *out, int outl)
@@ -145,13 +152,15 @@ static int b64_read(BIO *b, char *out, int outl)
int ret = 0, i, ii, j, k, x, n, num, ret_code = 0;
BIO_B64_CTX *ctx;
unsigned char *p, *q;
+ BIO *next;
if (out == NULL)
return (0);
- ctx = (BIO_B64_CTX *)b->ptr;
+ ctx = (BIO_B64_CTX *)BIO_get_data(b);
- if ((ctx == NULL) || (b->next_bio == NULL))
- return (0);
+ next = BIO_next(b);
+ if ((ctx == NULL) || (next == NULL))
+ return 0;
BIO_clear_retry_flags(b);
@@ -191,14 +200,14 @@ static int b64_read(BIO *b, char *out, int outl)
if (ctx->cont <= 0)
break;
- i = BIO_read(b->next_bio, &(ctx->tmp[ctx->tmp_len]),
+ i = BIO_read(next, &(ctx->tmp[ctx->tmp_len]),
B64_BLOCK_SIZE - ctx->tmp_len);
if (i <= 0) {
ret_code = i;
/* Should we continue next time we are called? */
- if (!BIO_should_retry(b->next_bio)) {
+ if (!BIO_should_retry(next)) {
ctx->cont = i;
/* If buffer empty break */
if (ctx->tmp_len == 0)
@@ -354,8 +363,13 @@ static int b64_write(BIO *b, const char *in, int inl)
int n;
int i;
BIO_B64_CTX *ctx;
+ BIO *next;
+
+ ctx = (BIO_B64_CTX *)BIO_get_data(b);
+ next = BIO_next(b);
+ if ((ctx == NULL) || (next == NULL))
+ return 0;
- ctx = (BIO_B64_CTX *)b->ptr;
BIO_clear_retry_flags(b);
if (ctx->encode != B64_ENCODE) {
@@ -371,7 +385,7 @@ static int b64_write(BIO *b, const char *in, int inl)
OPENSSL_assert(ctx->buf_len >= ctx->buf_off);
n = ctx->buf_len - ctx->buf_off;
while (n > 0) {
- i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n);
+ i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);
if (i <= 0) {
BIO_copy_next_retry(b);
return (i);
@@ -445,7 +459,7 @@ static int b64_write(BIO *b, const char *in, int inl)
ctx->buf_off = 0;
n = ctx->buf_len;
while (n > 0) {
- i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n);
+ i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);
if (i <= 0) {
BIO_copy_next_retry(b);
return ((ret == 0) ? i : ret);
@@ -467,21 +481,25 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
BIO_B64_CTX *ctx;
long ret = 1;
int i;
+ BIO *next;
- ctx = (BIO_B64_CTX *)b->ptr;
+ ctx = (BIO_B64_CTX *)BIO_get_data(b);
+ next = BIO_next(b);
+ if ((ctx == NULL) || (next == NULL))
+ return 0;
switch (cmd) {
case BIO_CTRL_RESET:
ctx->cont = 1;
ctx->start = 1;
ctx->encode = B64_NONE;
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_EOF: /* More to read */
if (ctx->cont <= 0)
ret = 1;
else
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_WPENDING: /* More to write in buffer */
OPENSSL_assert(ctx->buf_len >= ctx->buf_off);
@@ -490,13 +508,13 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
&& (EVP_ENCODE_CTX_num(ctx->base64) != 0))
ret = 1;
else if (ret <= 0)
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_PENDING: /* More to read in buffer */
OPENSSL_assert(ctx->buf_len >= ctx->buf_off);
ret = ctx->buf_len - ctx->buf_off;
if (ret <= 0)
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_FLUSH:
/* do a final write */
@@ -524,12 +542,12 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
goto again;
}
/* Finally flush the underlying BIO */
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
@@ -539,21 +557,22 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_GET:
case BIO_CTRL_SET:
default:
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
}
- return (ret);
+ return ret;
}
static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret = 1;
+ BIO *next = BIO_next(b);
- if (b->next_bio == NULL)
- return (0);
+ if (next == NULL)
+ return 0;
switch (cmd) {
default:
- ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
+ ret = BIO_callback_ctrl(next, cmd, fp);
break;
}
return (ret);
diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c
index e89c1df..ad94ba4 100644
--- a/crypto/evp/bio_enc.c
+++ b/crypto/evp/bio_enc.c
@@ -60,6 +60,7 @@
#include "internal/cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/evp.h>
+#include "internal/bio.h"
static int enc_write(BIO *h, const char *buf, int num);
static int enc_read(BIO *h, char *buf, int size);
@@ -122,9 +123,9 @@ static int enc_new(BIO *bi)
}
ctx->cont = 1;
ctx->ok = 1;
- bi->init = 0;
- bi->ptr = (char *)ctx;
- bi->flags = 0;
+ BIO_set_data(bi, ctx);
+ BIO_set_init(bi, 1);
+
return 1;
}
@@ -133,27 +134,33 @@ static int enc_free(BIO *a)
BIO_ENC_CTX *b;
if (a == NULL)
- return (0);
- b = (BIO_ENC_CTX *)a->ptr;
+ return 0;
+
+ b = BIO_get_data(a);
+ if (b == NULL)
+ return 0;
+
EVP_CIPHER_CTX_free(b->cipher);
- OPENSSL_clear_free(a->ptr, sizeof(BIO_ENC_CTX));
- a->ptr = NULL;
- a->init = 0;
- a->flags = 0;
- return (1);
+ OPENSSL_clear_free(b, sizeof(BIO_ENC_CTX));
+ BIO_set_data(a, NULL);
+ BIO_set_init(a, 0);
+
+ return 1;
}
static int enc_read(BIO *b, char *out, int outl)
{
int ret = 0, i;
BIO_ENC_CTX *ctx;
+ BIO *next;
if (out == NULL)
return (0);
- ctx = (BIO_ENC_CTX *)b->ptr;
+ ctx = BIO_get_data(b);
- if ((ctx == NULL) || (b->next_bio == NULL))
- return (0);
+ next = BIO_next(b);
+ if ((ctx == NULL) || (next == NULL))
+ return 0;
/* First check if there are bytes decoded/encoded */
if (ctx->buf_len > 0) {
@@ -183,11 +190,11 @@ static int enc_read(BIO *b, char *out, int outl)
/*
* read in at IV offset, read the EVP_Cipher documentation about why
*/
- i = BIO_read(b->next_bio, &(ctx->buf[BUF_OFFSET]), ENC_BLOCK_SIZE);
+ i = BIO_read(next, &(ctx->buf[BUF_OFFSET]), ENC_BLOCK_SIZE);
if (i <= 0) {
/* Should be continue next time we are called? */
- if (!BIO_should_retry(b->next_bio)) {
+ if (!BIO_should_retry(next)) {
ctx->cont = i;
i = EVP_CipherFinal_ex(ctx->cipher,
(unsigned char *)ctx->buf,
@@ -239,14 +246,19 @@ static int enc_write(BIO *b, const char *in, int inl)
{
int ret = 0, n, i;
BIO_ENC_CTX *ctx;
+ BIO *next;
+
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
+ if ((ctx == NULL) || (next == NULL))
+ return 0;
- ctx = (BIO_ENC_CTX *)b->ptr;
ret = inl;
BIO_clear_retry_flags(b);
n = ctx->buf_len - ctx->buf_off;
while (n > 0) {
- i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n);
+ i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);
if (i <= 0) {
BIO_copy_next_retry(b);
return (i);
@@ -274,7 +286,7 @@ static int enc_write(BIO *b, const char *in, int inl)
ctx->buf_off = 0;
n = ctx->buf_len;
while (n > 0) {
- i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n);
+ i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);
if (i <= 0) {
BIO_copy_next_retry(b);
return (ret == inl) ? i : ret - inl;
@@ -296,8 +308,12 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
long ret = 1;
int i;
EVP_CIPHER_CTX **c_ctx;
+ BIO *next;
- ctx = (BIO_ENC_CTX *)b->ptr;
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
+ if (ctx == NULL)
+ return 0;
switch (cmd) {
case BIO_CTRL_RESET:
@@ -306,23 +322,23 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
if (!EVP_CipherInit_ex(ctx->cipher, NULL, NULL, NULL, NULL,
EVP_CIPHER_CTX_encrypting(ctx->cipher)))
return 0;
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_EOF: /* More to read */
if (ctx->cont <= 0)
ret = 1;
else
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_WPENDING:
ret = ctx->buf_len - ctx->buf_off;
if (ret <= 0)
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_PENDING: /* More to read in buffer */
ret = ctx->buf_len - ctx->buf_off;
if (ret <= 0)
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_FLUSH:
/* do a final write */
@@ -348,33 +364,33 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
}
/* Finally flush the underlying BIO */
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_C_GET_CIPHER_STATUS:
ret = (long)ctx->ok;
break;
case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_C_GET_CIPHER_CTX:
c_ctx = (EVP_CIPHER_CTX **)ptr;
*c_ctx = ctx->cipher;
- b->init = 1;
+ BIO_set_init(b, 1);
break;
case BIO_CTRL_DUP:
dbio = (BIO *)ptr;
- dctx = (BIO_ENC_CTX *)dbio->ptr;
+ dctx = BIO_get_data(dbio);
dctx->cipher = EVP_CIPHER_CTX_new();
if (dctx->cipher == NULL)
return 0;
ret = EVP_CIPHER_CTX_copy(dctx->cipher, ctx->cipher);
if (ret)
- dbio->init = 1;
+ BIO_set_init(dbio, 1);
break;
default:
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
}
return (ret);
@@ -383,12 +399,13 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
static long enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret = 1;
+ BIO *next = BIO_next(b);
- if (b->next_bio == NULL)
+ if (next == NULL)
return (0);
switch (cmd) {
default:
- ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
+ ret = BIO_callback_ctrl(next, cmd, fp);
break;
}
return (ret);
@@ -418,22 +435,25 @@ int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,
const unsigned char *i, int e)
{
BIO_ENC_CTX *ctx;
+ long (*callback) (struct bio_st *, int, const char *, int, long, long);
- if (b == NULL)
+ ctx = BIO_get_data(b);
+ if (ctx == NULL)
return 0;
- if ((b->callback != NULL) &&
- (b->callback(b, BIO_CB_CTRL, (const char *)c, BIO_CTRL_SET, e, 0L) <=
- 0))
+ callback = BIO_get_callback(b);
+
+ if ((callback != NULL) &&
+ (callback(b, BIO_CB_CTRL, (const char *)c, BIO_CTRL_SET, e,
+ 0L) <= 0))
return 0;
- b->init = 1;
- ctx = (BIO_ENC_CTX *)b->ptr;
+ BIO_set_init(b, 1);
+
if (!EVP_CipherInit_ex(ctx->cipher, c, NULL, k, i, e))
return 0;
- if (b->callback != NULL)
- return b->callback(b, BIO_CB_CTRL, (const char *)c, BIO_CTRL_SET, e,
- 1L);
+ if (callback != NULL)
+ return callback(b, BIO_CB_CTRL, (const char *)c, BIO_CTRL_SET, e, 1L);
return 1;
}
diff --git a/crypto/evp/bio_md.c b/crypto/evp/bio_md.c
index 90dffa1..46c5583 100644
--- a/crypto/evp/bio_md.c
+++ b/crypto/evp/bio_md.c
@@ -62,6 +62,7 @@
#include <openssl/evp.h>
#include "internal/evp_int.h"
#include "evp_locl.h"
+#include "internal/bio.h"
/*
* BIO_put and BIO_get both add to the digest, BIO_gets returns the digest
@@ -103,37 +104,40 @@ static int md_new(BIO *bi)
if (ctx == NULL)
return (0);
- bi->init = 0;
- bi->ptr = (char *)ctx;
- bi->flags = 0;
- return (1);
+ BIO_set_init(bi, 1);
+ BIO_set_data(bi, ctx);
+
+ return 1;
}
static int md_free(BIO *a)
{
if (a == NULL)
return (0);
- EVP_MD_CTX_free(a->ptr);
- a->ptr = NULL;
- a->init = 0;
- a->flags = 0;
- return (1);
+ EVP_MD_CTX_free(BIO_get_data(a));
+ BIO_set_data(a, NULL);
+ BIO_set_init(a, 0);
+
+ return 1;
}
static int md_read(BIO *b, char *out, int outl)
{
int ret = 0;
EVP_MD_CTX *ctx;
+ BIO *next;
if (out == NULL)
return (0);
- ctx = b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL))
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
+
+ if ((ctx == NULL) || (next == NULL))
return (0);
- ret = BIO_read(b->next_bio, out, outl);
- if (b->init) {
+ ret = BIO_read(next, out, outl);
+ if (BIO_get_init(b)) {
if (ret > 0) {
if (EVP_DigestUpdate(ctx, (unsigned char *)out,
(unsigned int)ret) <= 0)
@@ -149,14 +153,17 @@ static int md_write(BIO *b, const char *in, int inl)
{
int ret = 0;
EVP_MD_CTX *ctx;
+ BIO *next;
if ((in == NULL) || (inl <= 0))
- return (0);
- ctx = b->ptr;
+ return 0;
- if ((ctx != NULL) && (b->next_bio != NULL))
- ret = BIO_write(b->next_bio, in, inl);
- if (b->init) {
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
+ if ((ctx != NULL) && (next != NULL))
+ ret = BIO_write(next, in, inl);
+
+ if (BIO_get_init(b)) {
if (ret > 0) {
if (!EVP_DigestUpdate(ctx, (const unsigned char *)in,
(unsigned int)ret)) {
@@ -165,11 +172,11 @@ static int md_write(BIO *b, const char *in, int inl)
}
}
}
- if (b->next_bio != NULL) {
+ if (next != NULL) {
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
}
- return (ret);
+ return ret;
}
static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
@@ -178,21 +185,23 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
const EVP_MD **ppmd;
EVP_MD *md;
long ret = 1;
- BIO *dbio;
+ BIO *dbio, *next;
- ctx = b->ptr;
+
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
switch (cmd) {
case BIO_CTRL_RESET:
- if (b->init)
+ if (BIO_get_init(b))
ret = EVP_DigestInit_ex(ctx, ctx->digest, NULL);
else
ret = 0;
if (ret > 0)
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_C_GET_MD:
- if (b->init) {
+ if (BIO_get_init(b)) {
ppmd = ptr;
*ppmd = ctx->digest;
} else
@@ -201,17 +210,17 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_C_GET_MD_CTX:
pctx = ptr;
*pctx = ctx;
- b->init = 1;
+ BIO_set_init(b, 1);
break;
case BIO_C_SET_MD_CTX:
- if (b->init)
- b->ptr = ptr;
+ if (BIO_get_init(b))
+ BIO_set_data(b, ptr);
else
ret = 0;
break;
case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
@@ -219,17 +228,17 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
md = ptr;
ret = EVP_DigestInit_ex(ctx, md, NULL);
if (ret > 0)
- b->init = 1;
+ BIO_set_init(b, 1);
break;
case BIO_CTRL_DUP:
dbio = ptr;
- dctx = dbio->ptr;
+ dctx = BIO_get_data(dbio);
if (!EVP_MD_CTX_copy_ex(dctx, ctx))
return 0;
- b->init = 1;
+ BIO_set_init(b, 1);
break;
default:
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
}
return (ret);
@@ -238,12 +247,16 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret = 1;
+ BIO *next;
+
+ next = BIO_next(b);
+
+ if (next == NULL)
+ return 0;
- if (b->next_bio == NULL)
- return (0);
switch (cmd) {
default:
- ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
+ ret = BIO_callback_ctrl(next, cmd, fp);
break;
}
return (ret);
@@ -254,20 +267,13 @@ static int md_gets(BIO *bp, char *buf, int size)
EVP_MD_CTX *ctx;
unsigned int ret;
- ctx = bp->ptr;
+ ctx = BIO_get_data(bp);
+
if (size < ctx->digest->md_size)
- return (0);
+ return 0;
+
if (EVP_DigestFinal_ex(ctx, (unsigned char *)buf, &ret) <= 0)
return -1;
return ((int)ret);
}
-
-/*-
-static int md_puts(bp,str)
-BIO *bp;
-char *str;
- {
- return(-1);
- }
-*/
diff --git a/crypto/evp/bio_ok.c b/crypto/evp/bio_ok.c
index a29777c..0ac1a31 100644
--- a/crypto/evp/bio_ok.c
+++ b/crypto/evp/bio_ok.c
@@ -121,7 +121,7 @@
#include <assert.h>
#include "internal/cryptlib.h"
#include <openssl/buffer.h>
-#include <openssl/bio.h>
+#include "internal/bio.h"
#include <openssl/evp.h>
#include <openssl/rand.h>
#include "internal/evp_int.h"
@@ -178,40 +178,48 @@ static int ok_new(BIO *bi)
ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx == NULL)
- return (0);
+ return 0;
ctx->cont = 1;
ctx->sigio = 1;
ctx->md = EVP_MD_CTX_new();
- bi->init = 0;
- bi->ptr = (char *)ctx;
- bi->flags = 0;
- return (1);
+ BIO_set_init(bi, 0);
+ BIO_set_data(bi, ctx);
+
+ return 1;
}
static int ok_free(BIO *a)
{
+ BIO_OK_CTX *ctx;
+
if (a == NULL)
- return (0);
- EVP_MD_CTX_free(((BIO_OK_CTX *)a->ptr)->md);
- OPENSSL_clear_free(a->ptr, sizeof(BIO_OK_CTX));
- a->ptr = NULL;
- a->init = 0;
- a->flags = 0;
- return (1);
+ return 0;
+
+ ctx = BIO_get_data(a);
+
+ EVP_MD_CTX_free(ctx->md);
+ OPENSSL_clear_free(ctx, sizeof(BIO_OK_CTX));
+ BIO_set_data(a, NULL);
+ BIO_set_init(a, 0);
+
+ return 1;
}
static int ok_read(BIO *b, char *out, int outl)
{
int ret = 0, i, n;
BIO_OK_CTX *ctx;
+ BIO *next;
if (out == NULL)
- return (0);
- ctx = (BIO_OK_CTX *)b->ptr;
+ return 0;
- if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0))
- return (0);
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
+
+ if ((ctx == NULL) || (next == NULL) || (BIO_get_init(b) == 0))
+ return 0;
while (outl > 0) {
@@ -250,7 +258,7 @@ static int ok_read(BIO *b, char *out, int outl)
/* no clean bytes in buffer -- fill it */
n = IOBS - ctx->buf_len;
- i = BIO_read(b->next_bio, &(ctx->buf[ctx->buf_len]), n);
+ i = BIO_read(next, &(ctx->buf[ctx->buf_len]), n);
if (i <= 0)
break; /* nothing new */
@@ -281,21 +289,23 @@ static int ok_read(BIO *b, char *out, int outl)
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
- return (ret);
+ return ret;
}
static int ok_write(BIO *b, const char *in, int inl)
{
int ret = 0, n, i;
BIO_OK_CTX *ctx;
+ BIO *next;
if (inl <= 0)
return inl;
- ctx = (BIO_OK_CTX *)b->ptr;
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
ret = inl;
- if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0))
+ if ((ctx == NULL) || (next == NULL) || (BIO_get_init(b) == 0))
return (0);
if (ctx->sigio && !sig_out(b))
@@ -305,7 +315,7 @@ static int ok_write(BIO *b, const char *in, int inl)
BIO_clear_retry_flags(b);
n = ctx->buf_len - ctx->buf_off;
while (ctx->blockout && n > 0) {
- i = BIO_write(b->next_bio, &(ctx->buf[ctx->buf_off]), n);
+ i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);
if (i <= 0) {
BIO_copy_next_retry(b);
if (!BIO_should_retry(b))
@@ -354,8 +364,10 @@ static long ok_ctrl(BIO *b, int cmd, long num, void *ptr)
const EVP_MD **ppmd;
long ret = 1;
int i;
+ BIO *next;
- ctx = b->ptr;
+ ctx = BIO_get_data(b);
+ next = BIO_next(b);
switch (cmd) {
case BIO_CTRL_RESET:
@@ -367,19 +379,19 @@ static long ok_ctrl(BIO *b, int cmd, long num, void *ptr)
ctx->finished = 0;
ctx->blockout = 0;
ctx->sigio = 1;
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_EOF: /* More to read */
if (ctx->cont <= 0)
ret = 1;
else
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_PENDING: /* More to read in buffer */
case BIO_CTRL_WPENDING: /* More to read in buffer */
ret = ctx->blockout ? ctx->buf_len - ctx->buf_off : 0;
if (ret <= 0)
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_CTRL_FLUSH:
/* do a final write */
@@ -400,11 +412,11 @@ static long ok_ctrl(BIO *b, int cmd, long num, void *ptr)
ctx->cont = (int)ret;
/* Finally flush the underlying BIO */
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_INFO:
@@ -414,34 +426,39 @@ static long ok_ctrl(BIO *b, int cmd, long num, void *ptr)
md = ptr;
if (!EVP_DigestInit_ex(ctx->md, md, NULL))
return 0;
- b->init = 1;
+ BIO_set_init(b, 1);
break;
case BIO_C_GET_MD:
- if (b->init) {
+ if (BIO_get_init(b)) {
ppmd = ptr;
*ppmd = EVP_MD_CTX_md(ctx->md);
} else
ret = 0;
break;
default:
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ ret = BIO_ctrl(next, cmd, num, ptr);
break;
}
- return (ret);
+ return ret;
}
static long ok_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
{
long ret = 1;
+ BIO *next;
+
+ next = BIO_next(b);
+
+ if (next == NULL)
+ return 0;
- if (b->next_bio == NULL)
- return (0);
switch (cmd) {
default:
- ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
+ ret = BIO_callback_ctrl(next, cmd, fp);
break;
}
- return (ret);
+
+ return ret;
}
static void longswap(void *_ptr, size_t len)
@@ -472,7 +489,7 @@ static int sig_out(BIO *b)
int md_size;
void *md_data;
- ctx = b->ptr;
+ ctx = BIO_get_data(b);
md = ctx->md;
digest = EVP_MD_CTX_md(md);
md_size = EVP_MD_size(digest);
@@ -516,7 +533,7 @@ static int sig_in(BIO *b)
int md_size;
void *md_data;
- ctx = b->ptr;
+ ctx = BIO_get_data(b);
md = ctx->md;
digest = EVP_MD_CTX_md(md);
md_size = EVP_MD_size(digest);
@@ -562,7 +579,7 @@ static int block_out(BIO *b)
const EVP_MD *digest;
int md_size;
- ctx = b->ptr;
+ ctx = BIO_get_data(b);
md = ctx->md;
digest = EVP_MD_CTX_md(md);
md_size = EVP_MD_size(digest);
@@ -593,7 +610,7 @@ static int block_in(BIO *b)
unsigned char tmp[EVP_MAX_MD_SIZE];
int md_size;
- ctx = b->ptr;
+ ctx = BIO_get_data(b);
md = ctx->md;
md_size = EVP_MD_size(EVP_MD_CTX_md(md));
diff --git a/doc/crypto/BIO_get_data.pod b/doc/crypto/BIO_get_data.pod
new file mode 100644
index 0000000..73f8ea5
--- /dev/null
+++ b/doc/crypto/BIO_get_data.pod
@@ -0,0 +1,56 @@
+=pod
+
+=head1 NAME
+
+BIO_set_data, BIO_get_data, BIO_set_init, BIO_get_init, BIO_set_shutdown,
+BIO_get_shutdown - functions for managing BIO state information
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ void BIO_set_data(BIO *a, void *ptr);
+ void *BIO_get_data(BIO *a);
+ void BIO_set_init(BIO *a, int init);
+ int BIO_get_init(BIO *a);
+ void BIO_set_shutdown(BIO *a, int shut);
+ int BIO_get_shutdown(BIO *a);
+
+=head1 DESCRIPTION
+
+These functions are mainly useful when implementing a custom BIO.
+
+The BIO_set_data() function associates the custom data pointed to by B<ptr> with
+the BIO. This data can subsequently be retrieved via a call to BIO_get_data().
+This can be used by custom BIOs for storing implementation specific information.
+
+The BIO_set_init() function sets the value of the BIO's "init" flag to indicate
+whether initialisation has been completed for this BIO or not. A non-zero value
+indicates that initialisation is complete, whilst zero indicates that it is not.
+Often initialisation will complete during initial construction of the BIO. For
+some BIOs however, initialisation may not complete until after additional steps
+have occurred (for example through calling custom ctrls). The BIO_get_init()
+function returns the value of the "init" flag.
+
+The BIO_set_shutdown() and BIO_get_shutdown() functions set and get the state of
+this BIO's shutdown (i.e. BIO_CLOSE) flag. If set then the underlying resource
+is also closed when the BIO is freed.
+
+=head1 RETURN VALUES
+
+BIO_get_data() returns a pointer to the implementation specific custom data
+associated with this BIO, or NULL if none has been set.
+
+BIO_get_init() returns the state of the BIO's init flag.
+
+BIO_get_shutdown() returns the stat of the BIO's shutdown (i.e. BIO_CLOSE) flag.
+
+=head1 SEE ALSO
+
+L<bio>, L<BIO_meth_new>
+
+=head1 HISTORY
+
+The functions described here were added in OpenSSL version 1.1.0.
+
+=cut
diff --git a/doc/crypto/BIO_meth_new.pod b/doc/crypto/BIO_meth_new.pod
new file mode 100644
index 0000000..de6ce66
--- /dev/null
+++ b/doc/crypto/BIO_meth_new.pod
@@ -0,0 +1,117 @@
+=pod
+
+=head1 NAME
+
+BIO_meth_new, BIO_meth_free, BIO_meth_get_write, BIO_meth_set_write,
+BIO_meth_get_read, BIO_meth_set_read, BIO_meth_get_puts, BIO_meth_set_puts,
+BIO_meth_get_gets, BIO_meth_set_gets, BIO_meth_get_ctrl, BIO_meth_set_ctrl,
+BIO_meth_get_create, BIO_meth_set_create, BIO_meth_get_destroy,
+BIO_meth_set_destroy, BIO_meth_get_callback_ctrl,
+BIO_meth_set_callback_ctrl - Routines to build up BIO methods
+
+=head1 SYNOPSIS
+
+ #include <openssl/bio.h>
+
+ BIO_METHOD *BIO_meth_new(int type, const char *name);
+ void BIO_meth_free(BIO_METHOD *biom);
+ int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int);
+ int BIO_meth_set_write(BIO_METHOD *biom,
+ int (*write) (BIO *, const char *, int));
+ int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int);
+ int BIO_meth_set_read(BIO_METHOD *biom,
+ int (*read) (BIO *, char *, int));
+ int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *);
+ int BIO_meth_set_puts(BIO_METHOD *biom,
+ int (*puts) (BIO *, const char *));
+ int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int);
+ int BIO_meth_set_gets(BIO_METHOD *biom,
+ int (*gets) (BIO *, char *, int));
+ long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *);
+ int BIO_meth_set_ctrl(BIO_METHOD *biom,
+ long (*ctrl) (BIO *, int, long, void *));
+ int (*BIO_meth_get_create(BIO_METHOD *bion)) (BIO *);
+ int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *));
+ int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *);
+ int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *));
+ long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom))
+ (BIO *, int, bio_info_cb *);
+ int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
+ long (*callback_ctrl) (BIO *, int,
+ bio_info_cb *));
+
+=head1 DESCRIPTION
+
+The B<BIO_METHOD> type is a structure used for the implementation of new BIO
+types. It provides a set of of functions used by OpenSSL for the implementation
+of the various BIO capabilities. See the L<bio> page for more information.
+
+BIO_meth_new() creates a new B<BIO_METHOD> structure. It should be given a
+unique integer B<type> and a string that represents its B<name>. The set of
+standard OpenSSL provided BIO types is provided in B<bio.h>. Some examples
+include B<BIO_TYPE_BUFFER> and B<BIO_TYPE_CIPHER>. Filter BIOs should have a
+type which have the "filter" bit set (B<BIO_TYPE_FILTER>). Source/sink BIOs
+should have the "source/sink" bit set (B<BIO_TYPE_SOURCE_SINK>). File descriptor
+based BIOs (e.g. socket, fd, connect, accept etc) should additionally have the
+"descriptor" bit set (B<BIO_TYPE_DESCRIPTOR>). See the L<BIO_find_type> page for
+more information.
+
+BIO_meth_free() destroys a B<BIO_METHOD> structure and frees up any memory
+associated with it.
+
+BIO_meth_get_write() and BIO_meth_set_write() get and set the function used for
+writing arbitrary length data to the BIO respectively. This function will be
+called in response to the application calling BIO_write(). The parameters for
+the function have the same meaning as for BIO_write().
+
+BIO_meth_get_read() and BIO_meth_set_read() get and set the function used for
+reading arbitrary length data from the BIO respectively. This function will be
+called in response to the application calling BIO_read(). The parameters for the
+function have the same meaning as for BIO_read().
+
+BIO_meth_get_puts() and BIO_meth_set_puts() get and set the function used for
+writing a NULL terminated string to the BIO respectively. This function will be
+called in response to the application calling BIO_puts(). The parameters for
+the function have the same meaning as for BIO_puts().
+
+BIO_meth_get_gets() and BIO_meth_set_gets() get and set the function typically
+used for reading a line of data from the BIO respectively (see the L<BIO_gets>
+page for more information). This function will be called in response to the
+application calling BIO_gets(). The parameters for the function have the same
+meaning as for BIO_gets().
+
+BIO_meth_get_ctrl() and BIO_meth_set_ctrl() get and set the function used for
+processing ctrl messages in the BIO respectively. See the L<BIO_ctrl> page for
+more information. This function will be called in response to the application
+calling BIO_ctrl(). The parameters for the function have the same meaning as for
+BIO_ctrl().
+
+BIO_meth_get_create() and BIO_meth_set_create() get and set the function used
+for creating a new instance of the BIO respectively. This function will be
+called in response to the application calling BIO_new() or BIO_set() and passing
+in a pointer to the current BIO_METHOD. The BIO_new() function will allocate the
+memory for the new BIO, and a pointer to this newly allocated structure will
+be passed as a parameter to the function.
+
+BIO_meth_get_destroy() and BIO_meth_set_destroy() get and set the function used
+for destroying an instance of a BIO respectively. This function will be
+called in response to the application calling BIO_free(). A pointer to the BIO
+to be destroyed is passed as a parameter. The destroy function should be used
+for BIO specific clean up. The memory for the BIO itself should not be freed by
+this function.
+
+BIO_meth_get_callback_ctrl() and BIO_meth_set_callback_ctrl() get and set the
+function used for processing callback ctrl messages in the BIO respectively. See
+the L<BIO_callback_ctrl> page for more information. This function will be called
+in response to the application calling BIO_callback_ctrl(). The parameters for
+the function have the same meaning as for BIO_callback_ctrl().
+
+=head1 SEE ALSO
+
+L<bio>, L<BIO_find_type>, L<BIO_ctrl>, L<BIO_read>, L<BIO_new>
+
+=head1 HISTORY
+
+The functions described here were added in OpenSSL version 1.1.0.
+
+=cut
diff --git a/doc/crypto/BIO_push.pod b/doc/crypto/BIO_push.pod
index 8a2657c..1523e5b 100644
--- a/doc/crypto/BIO_push.pod
+++ b/doc/crypto/BIO_push.pod
@@ -2,14 +2,15 @@
=head1 NAME
-BIO_push, BIO_pop - add and remove BIOs from a chain.
+BIO_push, BIO_pop, BIO_set_next - add and remove BIOs from a chain.
=head1 SYNOPSIS
#include <openssl/bio.h>
- BIO * BIO_push(BIO *b,BIO *append);
- BIO * BIO_pop(BIO *b);
+ BIO *BIO_push(BIO *b,BIO *append);
+ BIO *BIO_pop(BIO *b);
+ void BIO_set_next(BIO *b, BIO *next);
=head1 DESCRIPTION
@@ -21,6 +22,10 @@ in the chain, or NULL if there is no next BIO. The removed BIO then
becomes a single BIO with no association with the original chain,
it can thus be freed or attached to a different chain.
+BIO_set_next() replaces the existing next BIO in a chain with the BIO pointed to
+by B<next>. The new chain may include some of the same BIOs from the old chain
+or it may be completely different.
+
=head1 NOTES
The names of these functions are perhaps a little misleading. BIO_push()
@@ -66,4 +71,10 @@ BIO.
=head1 SEE ALSO
-TBA
+L<bio>
+
+=head1 HISTORY
+
+The BIO_set_next() function was added in OpenSSL version 1.1.0.
+
+=cut
diff --git a/doc/crypto/BIO_should_retry.pod b/doc/crypto/BIO_should_retry.pod
index b6d51f7..f5b47b3 100644
--- a/doc/crypto/BIO_should_retry.pod
+++ b/doc/crypto/BIO_should_retry.pod
@@ -4,7 +4,8 @@
BIO_should_retry, BIO_should_read, BIO_should_write,
BIO_should_io_special, BIO_retry_type, BIO_should_retry,
-BIO_get_retry_BIO, BIO_get_retry_reason - BIO retry functions
+BIO_get_retry_BIO, BIO_get_retry_reason, BIO_set_retry_reason - BIO retry
+functions
=head1 SYNOPSIS
@@ -22,8 +23,9 @@ BIO_get_retry_BIO, BIO_get_retry_reason - BIO retry functions
#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
#define BIO_FLAGS_SHOULD_RETRY 0x08
- BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
- int BIO_get_retry_reason(BIO *bio);
+ BIO *BIO_get_retry_BIO(BIO *bio, int *reason);
+ int BIO_get_retry_reason(BIO *bio);
+ void BIO_set_retry_reason(BIO *bio, int reason);
=head1 DESCRIPTION
@@ -59,6 +61,9 @@ the type of BIO that resulted in this condition.
BIO_get_retry_reason() returns the reason for a special condition if
passed the relevant BIO, for example as returned by BIO_get_retry_BIO().
+BIO_set_retry_reason() sets the retry reason for a special condition for a given
+BIO. This would usually only be called by BIO implementations.
+
=head1 NOTES
If BIO_should_retry() returns false then the precise "error condition"
@@ -111,4 +116,11 @@ the entire structure can be read or written.
=head1 SEE ALSO
-TBA
+L<bio>
+
+=head1 HISTORY
+
+The BIO_get_retry_reason() and BIO_set_retry_reason() functions were added in
+OpenSSL version 1.1.0.
+
+=cut
diff --git a/crypto/include/internal/async.h b/include/internal/bio.h
similarity index 86%
copy from crypto/include/internal/async.h
copy to include/internal/bio.h
index 76fe4d1..b3352ce 100644
--- a/crypto/include/internal/async.h
+++ b/include/internal/bio.h
@@ -1,6 +1,3 @@
-/*
- * Written by Matt Caswell for the OpenSSL project
- */
/* ====================================================================
* Copyright (c) 2016 The OpenSSL Project. All rights reserved.
*
@@ -55,8 +52,20 @@
*
*/
-#include <openssl/async.h>
+#include <openssl/bio.h>
+
+struct bio_method_st {
+ int type;
+ const char *name;
+ int (*bwrite) (BIO *, const char *, int);
+ int (*bread) (BIO *, char *, int);
+ int (*bputs) (BIO *, const char *);
+ int (*bgets) (BIO *, char *, int);
+ long (*ctrl) (BIO *, int, long, void *);
+ int (*create) (BIO *);
+ int (*destroy) (BIO *);
+ long (*callback_ctrl) (BIO *, int, bio_info_cb *);
+};
+
-int async_init(void);
-void async_deinit(void);
diff --git a/include/openssl/bio.h b/include/openssl/bio.h
index 5389770..09aeea1 100644
--- a/include/openssl/bio.h
+++ b/include/openssl/bio.h
@@ -290,70 +290,16 @@ void BIO_set_callback(BIO *b,
char *BIO_get_callback_arg(const BIO *b);
void BIO_set_callback_arg(BIO *b, char *arg);
+typedef struct bio_method_st BIO_METHOD;
+
const char *BIO_method_name(const BIO *b);
int BIO_method_type(const BIO *b);
typedef void bio_info_cb (struct bio_st *, int, const char *, int, long,
long);
-typedef struct bio_method_st {
- int type;
- const char *name;
- int (*bwrite) (BIO *, const char *, int);
- int (*bread) (BIO *, char *, int);
- int (*bputs) (BIO *, const char *);
- int (*bgets) (BIO *, char *, int);
- long (*ctrl) (BIO *, int, long, void *);
- int (*create) (BIO *);
- int (*destroy) (BIO *);
- long (*callback_ctrl) (BIO *, int, bio_info_cb *);
-} BIO_METHOD;
-
-struct bio_st {
- const BIO_METHOD *method;
- /* bio, mode, argp, argi, argl, ret */
- long (*callback) (struct bio_st *, int, const char *, int, long, long);
- char *cb_arg; /* first argument for the callback */
- int init;
- int shutdown;
- int flags; /* extra storage */
- int retry_reason;
- int num;
- void *ptr;
- struct bio_st *next_bio; /* used by filter BIOs */
- struct bio_st *prev_bio; /* used by filter BIOs */
- int references;
- uint64_t num_read;
- uint64_t num_write;
- CRYPTO_EX_DATA ex_data;
- CRYPTO_RWLOCK *lock;
-};
-
DEFINE_STACK_OF(BIO)
-typedef struct bio_f_buffer_ctx_struct {
- /*-
- * Buffers are setup like this:
- *
- * <---------------------- size ----------------------->
- * +---------------------------------------------------+
- * | consumed | remaining | free space |
- * +---------------------------------------------------+
- * <-- off --><------- len ------->
- */
- /*- BIO *bio; *//*
- * this is now in the BIO struct
- */
- int ibuf_size; /* how big is the input buffer */
- int obuf_size; /* how big is the output buffer */
- char *ibuf; /* the char array */
- int ibuf_len; /* how many bytes are in it */
- int ibuf_off; /* write/read offset */
- char *obuf; /* the char array */
- int obuf_len; /* how many bytes are in it */
- int obuf_off; /* write/read offset */
-} BIO_F_BUFFER_CTX;
-
/* Prefix and suffix callback in ASN1 BIO */
typedef int asn1_ps_func (BIO *b, unsigned char **pbuf, int *plen,
void *parg);
@@ -635,6 +581,12 @@ BIO *BIO_new_fp(FILE *stream, int close_flag);
BIO *BIO_new(const BIO_METHOD *type);
int BIO_set(BIO *a, const BIO_METHOD *type);
int BIO_free(BIO *a);
+void BIO_set_data(BIO *a, void *ptr);
+void *BIO_get_data(BIO *a);
+void BIO_set_init(BIO *a, int init);
+int BIO_get_init(BIO *a);
+void BIO_set_shutdown(BIO *a, int shut);
+int BIO_get_shutdown(BIO *a);
void BIO_vfree(BIO *a);
int BIO_up_ref(BIO *a);
int BIO_read(BIO *b, void *data, int len);
@@ -653,8 +605,10 @@ BIO *BIO_pop(BIO *b);
void BIO_free_all(BIO *a);
BIO *BIO_find_type(BIO *b, int bio_type);
BIO *BIO_next(BIO *b);
+void BIO_set_next(BIO *b, BIO *next);
BIO *BIO_get_retry_BIO(BIO *bio, int *reason);
int BIO_get_retry_reason(BIO *bio);
+void BIO_set_retry_reason(BIO *bio, int reason);
BIO *BIO_dup_chain(BIO *in);
int BIO_nread0(BIO *bio, char **buf);
@@ -818,6 +772,34 @@ int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
__bio_h__attr__((__format__(__printf__, 3, 0)));
# undef __bio_h__attr__
+
+BIO_METHOD *BIO_meth_new(int type, const char *name);
+void BIO_meth_free(BIO_METHOD *biom);
+int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int);
+int BIO_meth_set_write(BIO_METHOD *biom,
+ int (*write) (BIO *, const char *, int));
+int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int);
+int BIO_meth_set_read(BIO_METHOD *biom,
+ int (*read) (BIO *, char *, int));
+int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *);
+int BIO_meth_set_puts(BIO_METHOD *biom,
+ int (*puts) (BIO *, const char *));
+int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int);
+int BIO_meth_set_gets(BIO_METHOD *biom,
+ int (*gets) (BIO *, char *, int));
+long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *);
+int BIO_meth_set_ctrl(BIO_METHOD *biom,
+ long (*ctrl) (BIO *, int, long, void *));
+int (*BIO_meth_get_create(BIO_METHOD *bion)) (BIO *);
+int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *));
+int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *);
+int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *));
+long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom))
+ (BIO *, int, bio_info_cb *);
+int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
+ long (*callback_ctrl) (BIO *, int,
+ bio_info_cb *));
+
/* BEGIN ERROR CODES */
/*
* The following lines are auto generated by the script mkerr.pl. Any changes
diff --git a/ssl/bio_ssl.c b/ssl/bio_ssl.c
index c3afc57..e3deebc 100644
--- a/ssl/bio_ssl.c
+++ b/ssl/bio_ssl.c
@@ -60,7 +60,7 @@
#include <string.h>
#include <errno.h>
#include <openssl/crypto.h>
-#include <openssl/bio.h>
+#include "internal/bio.h"
#include <openssl/err.h>
#include "ssl_locl.h"
@@ -106,10 +106,12 @@ static int ssl_new(BIO *bi)
BIOerr(BIO_F_SSL_NEW, ERR_R_MALLOC_FAILURE);
return (0);
}
- bi->init = 0;
- bi->ptr = (char *)bs;
- bi->flags = 0;
- return (1);
+ BIO_set_init(bi, 0);
+ BIO_set_data(bi, bs);
+ /* Clear all flags */
+ BIO_clear_flags(bi, ~0);
+
+ return 1;
}
static int ssl_free(BIO *a)
@@ -118,17 +120,18 @@ static int ssl_free(BIO *a)
if (a == NULL)
return (0);
- bs = (BIO_SSL *)a->ptr;
+ bs = BIO_get_data(a);
if (bs->ssl != NULL)
SSL_shutdown(bs->ssl);
- if (a->shutdown) {
- if (a->init)
+ if (BIO_get_shutdown(a)) {
+ if (BIO_get_init(a))
SSL_free(bs->ssl);
- a->init = 0;
- a->flags = 0;
+ /* Clear all flags */
+ BIO_clear_flags(a, ~0);
+ BIO_set_init(a, 0);
}
- OPENSSL_free(a->ptr);
- return (1);
+ OPENSSL_free(bs);
+ return 1;
}
static int ssl_read(BIO *b, char *out, int outl)
@@ -141,7 +144,7 @@ static int ssl_read(BIO *b, char *out, int outl)
if (out == NULL)
return (0);
- sb = (BIO_SSL *)b->ptr;
+ sb = BIO_get_data(b);
ssl = sb->ssl;
BIO_clear_retry_flags(b);
@@ -198,7 +201,7 @@ static int ssl_read(BIO *b, char *out, int outl)
break;
}
- b->retry_reason = retry_reason;
+ BIO_set_retry_reason(b, retry_reason);
return (ret);
}
@@ -211,7 +214,7 @@ static int ssl_write(BIO *b, const char *out, int outl)
if (out == NULL)
return (0);
- bs = (BIO_SSL *)b->ptr;
+ bs = BIO_get_data(b);
ssl = bs->ssl;
BIO_clear_retry_flags(b);
@@ -264,18 +267,20 @@ static int ssl_write(BIO *b, const char *out, int outl)
break;
}
- b->retry_reason = retry_reason;
- return (ret);
+ BIO_set_retry_reason(b, retry_reason);
+ return ret;
}
static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
{
SSL **sslp, *ssl;
- BIO_SSL *bs;
+ BIO_SSL *bs, *dbs;
BIO *dbio, *bio;
long ret = 1;
+ BIO *next;
- bs = (BIO_SSL *)b->ptr;
+ bs = BIO_get_data(b);
+ next = BIO_next(b);
ssl = bs->ssl;
if ((ssl == NULL) && (cmd != BIO_C_SET_SSL))
return (0);
@@ -293,8 +298,8 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
}
- if (b->next_bio != NULL)
- ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ if (next != NULL)
+ ret = BIO_ctrl(next, cmd, num, ptr);
else if (ssl->rbio != NULL)
ret = BIO_ctrl(ssl->rbio, cmd, num, ptr);
else
@@ -330,17 +335,17 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
if (!ssl_new(b))
return 0;
}
- b->shutdown = (int)num;
+ BIO_set_shutdown(b, num);
ssl = (SSL *)ptr;
- ((BIO_SSL *)b->ptr)->ssl = ssl;
+ bs->ssl = ssl;
bio = SSL_get_rbio(ssl);
if (bio != NULL) {
- if (b->next_bio != NULL)
- BIO_push(bio, b->next_bio);
- b->next_bio = bio;
+ if (next != NULL)
+ BIO_push(bio, next);
+ BIO_set_next(b, bio);
BIO_up_ref(bio);
}
- b->init = 1;
+ BIO_set_init(b, 1);
break;
case BIO_C_GET_SSL:
if (ptr != NULL) {
@@ -350,10 +355,10 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
ret = 0;
break;
case BIO_CTRL_GET_CLOSE:
- ret = b->shutdown;
+ ret = BIO_get_shutdown(b);
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown = (int)num;
+ BIO_set_shutdown(b, (int)num);
break;
case BIO_CTRL_WPENDING:
ret = BIO_ctrl(ssl->wbio, cmd, num, ptr);
@@ -369,8 +374,8 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
BIO_copy_next_retry(b);
break;
case BIO_CTRL_PUSH:
- if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio)) {
- SSL_set_bio(ssl, b->next_bio, b->next_bio);
+ if ((next != NULL) && (next != ssl->rbio)) {
+ SSL_set_bio(ssl, next, next);
BIO_up_ref(b);
}
break;
@@ -383,8 +388,8 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
*/
if (ssl->rbio != ssl->wbio)
BIO_free_all(ssl->wbio);
- if (b->next_bio != NULL)
- BIO_free(b->next_bio);
+ if (next != NULL)
+ BIO_free(next);
ssl->wbio = NULL;
ssl->rbio = NULL;
}
@@ -392,7 +397,7 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- b->retry_reason = 0;
+ BIO_set_retry_reason(b, 0);
ret = (int)SSL_do_handshake(ssl);
switch (SSL_get_error(ssl, (int)ret)) {
@@ -404,11 +409,11 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
case SSL_ERROR_WANT_CONNECT:
BIO_set_flags(b, BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY);
- b->retry_reason = b->next_bio->retry_reason;
+ BIO_set_retry_reason(b, BIO_get_retry_reason(next));
break;
case SSL_ERROR_WANT_X509_LOOKUP:
BIO_set_retry_special(b);
- b->retry_reason = BIO_RR_SSL_X509_LOOKUP;
+ BIO_set_retry_reason(b, BIO_RR_SSL_X509_LOOKUP);
break;
default:
break;
@@ -416,15 +421,14 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
case BIO_CTRL_DUP:
dbio = (BIO *)ptr;
- SSL_free(((BIO_SSL *)dbio->ptr)->ssl);
- ((BIO_SSL *)dbio->ptr)->ssl = SSL_dup(ssl);
- ((BIO_SSL *)dbio->ptr)->renegotiate_count =
- ((BIO_SSL *)b->ptr)->renegotiate_count;
- ((BIO_SSL *)dbio->ptr)->byte_count = ((BIO_SSL *)b->ptr)->byte_count;
- ((BIO_SSL *)dbio->ptr)->renegotiate_timeout =
- ((BIO_SSL *)b->ptr)->renegotiate_timeout;
- ((BIO_SSL *)dbio->ptr)->last_time = ((BIO_SSL *)b->ptr)->last_time;
- ret = (((BIO_SSL *)dbio->ptr)->ssl != NULL);
+ dbs = BIO_get_data(dbio);
+ SSL_free(dbs->ssl);
+ dbs->ssl = SSL_dup(ssl);
+ dbs->renegotiate_count = dbs->renegotiate_count;
+ dbs->byte_count = dbs->byte_count;
+ dbs->renegotiate_timeout = dbs->renegotiate_timeout;
+ dbs->last_time = dbs->last_time;
+ ret = (dbs->ssl != NULL);
break;
case BIO_C_GET_FD:
ret = BIO_ctrl(ssl->rbio, cmd, num, ptr);
@@ -461,7 +465,7 @@ static long ssl_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
BIO_SSL *bs;
long ret = 1;
- bs = (BIO_SSL *)b->ptr;
+ bs = BIO_get_data(b);
ssl = bs->ssl;
switch (cmd) {
case BIO_CTRL_SET_CALLBACK:
@@ -548,14 +552,16 @@ BIO *BIO_new_ssl(SSL_CTX *ctx, int client)
int BIO_ssl_copy_session_id(BIO *t, BIO *f)
{
+ BIO_SSL *tdata, *fdata;
t = BIO_find_type(t, BIO_TYPE_SSL);
f = BIO_find_type(f, BIO_TYPE_SSL);
if ((t == NULL) || (f == NULL))
+ return 0;
+ tdata = BIO_get_data(t);
+ fdata = BIO_get_data(f);
+ if ((tdata->ssl == NULL) || (fdata->ssl == NULL))
return (0);
- if ((((BIO_SSL *)t->ptr)->ssl == NULL) ||
- (((BIO_SSL *)f->ptr)->ssl == NULL))
- return (0);
- if (!SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl, ((BIO_SSL *)f->ptr)->ssl))
+ if (!SSL_copy_session_id(tdata->ssl, (fdata->ssl)))
return 0;
return (1);
}
@@ -564,12 +570,10 @@ void BIO_ssl_shutdown(BIO *b)
{
SSL *s;
- while (b != NULL) {
- if (b->method->type == BIO_TYPE_SSL) {
- s = ((BIO_SSL *)b->ptr)->ssl;
- SSL_shutdown(s);
- break;
- }
- b = b->next_bio;
- }
+ b = BIO_find_type(b, BIO_TYPE_SSL);
+ if (b == NULL)
+ return;
+
+ s = BIO_get_data(b);
+ SSL_shutdown(s);
}
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index 3385bc1..e651189 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -1105,8 +1105,8 @@ void SSL_set_wbio(SSL *s, BIO *wbio)
*/
if (s->bbio != NULL) {
if (s->wbio == s->bbio) {
- s->wbio = s->wbio->next_bio;
- s->bbio->next_bio = NULL;
+ s->wbio = BIO_next(s->wbio);
+ BIO_set_next(s->bbio, NULL);
}
}
if (s->wbio != wbio && s->rbio != s->wbio)
diff --git a/util/libcrypto.num b/util/libcrypto.num
index 8a2e4ea..e43c854 100644
--- a/util/libcrypto.num
+++ b/util/libcrypto.num
@@ -4060,3 +4060,29 @@ DHparams_it 3925 1_1_0 EXIST:EXPORT_VAR_AS_FUNCTION:
EVP_blake2s256 3926 1_1_0 EXIST::FUNCTION:BLAKE2
EVP_blake2b512 3927 1_1_0 EXIST::FUNCTION:BLAKE2
X509_SIG_get0 3928 1_1_0 EXIST::FUNCTION:
+BIO_meth_new 3929 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_puts 3930 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_ctrl 3931 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_gets 3932 1_1_0 EXIST::FUNCTION:
+BIO_get_data 3933 1_1_0 EXIST::FUNCTION:
+BIO_set_init 3934 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_puts 3935 1_1_0 EXIST::FUNCTION:
+BIO_get_shutdown 3936 1_1_0 EXIST::FUNCTION:
+BIO_get_init 3937 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_ctrl 3938 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_read 3939 1_1_0 EXIST::FUNCTION:
+BIO_set_shutdown 3940 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_create 3941 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_write 3942 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_callback_ctrl 3943 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_create 3944 1_1_0 EXIST::FUNCTION:
+BIO_set_next 3945 1_1_0 EXIST::FUNCTION:
+BIO_set_data 3946 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_write 3947 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_destroy 3948 1_1_0 EXIST::FUNCTION:
+BIO_meth_set_gets 3949 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_callback_ctrl 3950 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_destroy 3951 1_1_0 EXIST::FUNCTION:
+BIO_meth_get_read 3952 1_1_0 EXIST::FUNCTION:
+BIO_set_retry_reason 3953 1_1_0 EXIST::FUNCTION:
+BIO_meth_free 3954 1_1_0 EXIST::FUNCTION:
More information about the openssl-commits
mailing list