summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2018-02-20 17:15:27 +0000
committerjsing <jsing@openbsd.org>2018-02-20 17:15:27 +0000
commit1a6921092423f2ba215c73fdc7f87a5abc189a76 (patch)
tree797ae8ed04fe01ee3e5daf40582033787d5a74f4
parentProvide BN_GENCB_new(), BN_GENCB_free() and BN_GENCB_get_arg() (diff)
downloadwireguard-openbsd-1a6921092423f2ba215c73fdc7f87a5abc189a76.tar.xz
wireguard-openbsd-1a6921092423f2ba215c73fdc7f87a5abc189a76.zip
Provide BIO_get_new_index().
Based on BoringSSL.
-rw-r--r--lib/libcrypto/Symbols.list1
-rw-r--r--lib/libcrypto/bio/bio.h9
-rw-r--r--lib/libcrypto/bio/bio_lib.c16
3 files changed, 24 insertions, 2 deletions
diff --git a/lib/libcrypto/Symbols.list b/lib/libcrypto/Symbols.list
index 23030bdb155..2252220278c 100644
--- a/lib/libcrypto/Symbols.list
+++ b/lib/libcrypto/Symbols.list
@@ -280,6 +280,7 @@ BIO_get_data
BIO_get_ex_data
BIO_get_ex_new_index
BIO_get_host_ip
+BIO_get_new_index
BIO_get_port
BIO_get_retry_BIO
BIO_get_retry_reason
diff --git a/lib/libcrypto/bio/bio.h b/lib/libcrypto/bio/bio.h
index 8efeba20053..1d34f082eec 100644
--- a/lib/libcrypto/bio/bio.h
+++ b/lib/libcrypto/bio/bio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bio.h,v 1.33 2018/02/18 12:59:06 tb Exp $ */
+/* $OpenBSD: bio.h,v 1.34 2018/02/20 17:15:27 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -103,6 +103,12 @@ extern "C" {
#define BIO_TYPE_FILTER 0x0200
#define BIO_TYPE_SOURCE_SINK 0x0400
+/*
+ * BIO_TYPE_START is the first user-allocated BIO type. No pre-defined type,
+ * flag bits aside, may exceed this value.
+ */
+#define BIO_TYPE_START 128
+
/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
* BIO_set_fp(in,stdin,BIO_NOCLOSE); */
#define BIO_NOCLOSE 0x00
@@ -580,6 +586,7 @@ int
BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
asn1_ps_func **psuffix_free);
+int BIO_get_new_index(void);
BIO_METHOD *BIO_s_file(void );
BIO *BIO_new_file(const char *filename, const char *mode);
BIO *BIO_new_fp(FILE *stream, int close_flag);
diff --git a/lib/libcrypto/bio/bio_lib.c b/lib/libcrypto/bio/bio_lib.c
index 4e5405d6afb..b2acd01342a 100644
--- a/lib/libcrypto/bio/bio_lib.c
+++ b/lib/libcrypto/bio/bio_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bio_lib.c,v 1.24 2018/02/18 12:58:25 tb Exp $ */
+/* $OpenBSD: bio_lib.c,v 1.25 2018/02/20 17:15:27 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -64,6 +64,20 @@
#include <openssl/err.h>
#include <openssl/stack.h>
+int
+BIO_get_new_index(void)
+{
+ static int bio_type_index = BIO_TYPE_START;
+ int index;
+
+ /* The index will collide with the BIO flag bits if it exceeds 255. */
+ index = CRYPTO_add(&bio_type_index, 1, CRYPTO_LOCK_BIO);
+ if (index > 255)
+ return -1;
+
+ return index;
+}
+
BIO *
BIO_new(BIO_METHOD *method)
{