[openssl-commits] [openssl] master update

Rich Salz rsalz at openssl.org
Thu Jan 7 20:24:57 UTC 2016


The branch master has been updated
       via  bbd86bf5424a611cb6b77a3a17fc522931c4dcb8 (commit)
      from  3cb8c3265f639f8eebf32053457ae6a6d61e2413 (commit)


- Log -----------------------------------------------------------------
commit bbd86bf5424a611cb6b77a3a17fc522931c4dcb8
Author: Rich Salz <rsalz at openssl.org>
Date:   Thu Jan 7 15:06:38 2016 -0500

    mem functions cleanup
    
    Only two macros CRYPTO_MDEBUG and CRYPTO_MDEBUG_ABORT to control this.
    If CRYPTO_MDEBUG is not set, #ifdef out the whole debug machinery.
            (Thanks to Jakob Bohm for the suggestion!)
    Make the "change wrapper functions" be the only paradigm.
    Wrote documentation!
    Format the 'set func' functions so their paramlists are legible.
    Format some multi-line comments.
    Remove ability to get/set the "memory debug" functions at runtme.
    Remove MemCheck_* and CRYPTO_malloc_debug_init macros.
    Add CRYPTO_mem_debug(int flag) function.
    Add test/memleaktest.
    Rename CRYPTO_malloc_init to OPENSSL_malloc_init; remove needless calls.
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>

-----------------------------------------------------------------------

Summary of changes:
 CHANGES                              |   6 +
 Configurations/10-main.conf          |   4 +-
 Configure                            |   2 +-
 apps/openssl.c                       |  14 +-
 crypto/cms/Makefile                  |  42 ++---
 crypto/ct/Makefile                   |   3 +-
 crypto/dh/Makefile                   |  35 ++--
 crypto/dsa/Makefile                  |  15 +-
 crypto/ec/Makefile                   |  16 +-
 crypto/engine/eng_dyn.c              |   2 -
 crypto/mem.c                         | 336 ++++++++++-------------------------
 crypto/mem_dbg.c                     | 237 +++++++++---------------
 crypto/mem_sec.c                     |   9 +
 crypto/objects/Makefile              |   2 +-
 crypto/objects/o_names.c             |  16 +-
 crypto/rsa/Makefile                  |  14 +-
 crypto/x509/Makefile                 |  19 +-
 demos/selfsign.c                     |   1 +
 doc/apps/dhparam.pod                 |   2 +-
 doc/crypto/OPENSSL_malloc.pod        | 162 +++++++++++++++++
 doc/crypto/OPENSSL_secure_malloc.pod |  28 ++-
 doc/ssl/ssl.pod                      |   4 +-
 engines/ccgost/Makefile              |  15 +-
 include/openssl/crypto.h             | 203 +++++++++------------
 include/openssl/engine.h             |  12 --
 ssl/Makefile                         | 146 +++++++++------
 ssl/ssl_ciph.c                       |  20 +--
 ssl/ssl_err.c                        |  78 +++-----
 test/Makefile                        |  36 ++--
 test/{Makefile => Makefile.orig}     |   0
 test/asynctest.c                     |   3 +-
 test/clienthellotest.c               |   5 +-
 test/danetest.c                      |  45 +++--
 test/dhtest.c                        |   7 +-
 test/dsatest.c                       |   5 +-
 test/ecdhtest.c                      |   9 +-
 test/ecdsatest.c                     |  17 +-
 test/ectest.c                        |  15 +-
 test/enginetest.c                    |  17 +-
 test/evp_extra_test.c                |   5 +-
 test/jpaketest.c                     |   3 +-
 test/{nptest.c => memleaktest.c}     |  34 +++-
 test/p5_crpt2_test.c                 |   5 +-
 test/recipes/90-test_memleak.t       |   7 +
 test/rsa_test.c                      |   5 +-
 test/srptest.c                       |   5 +-
 test/ssltest.c                       |  15 +-
 test/verify_extra_test.c             |   5 +-
 util/libeay.num                      |  46 ++---
 49 files changed, 839 insertions(+), 893 deletions(-)
 create mode 100644 doc/crypto/OPENSSL_malloc.pod
 copy test/{Makefile => Makefile.orig} (100%)
 copy test/{nptest.c => memleaktest.c} (79%)
 create mode 100644 test/recipes/90-test_memleak.t

diff --git a/CHANGES b/CHANGES
index b4cc2d4..31fe88a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -152,6 +152,12 @@
 
      [Richard Levitte]
 
+  *) Revamped memory debug; only -DCRYPTO_MDEBUG and -DCRYPTO_MDEBUG_ABORT
+     are used; the latter aborts on memory leaks (usually checked on exit).
+     Some undocumented "set malloc, etc., hooks" functions were removed
+     and others were changed.  All are now documented.
+     [Rich Salz]
+
   *) In DSA_generate_parameters_ex, if the provided seed is too short,
      return an error
      [Rich Salz and Ismo Puustinen <ismo.puustinen at intel.com>]
diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf
index a82b95d..4bd4366 100644
--- a/Configurations/10-main.conf
+++ b/Configurations/10-main.conf
@@ -132,7 +132,7 @@
         # -mcpu=ultrasparc
         inherit_from     => [ "solaris-sparcv7-gcc", asm("sparcv9_asm") ],
         cflags           => sub { join(" ","-m32 -mcpu=ultrasparc", at _); },
-        debug_cflags     => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL -DPEDANTIC -O -g -pedantic -ansi -Wshadow -Wno-long-long -D__EXTENSIONS__",
+        debug_cflags     => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG -DPEDANTIC -O -g -pedantic -ansi -Wshadow -Wno-long-long -D__EXTENSIONS__",
     },
     "solaris64-sparcv9-gcc" => {
         inherit_from     => [ "solaris-sparcv9-gcc" ],
@@ -150,7 +150,7 @@
         inherit_from     => [ "solaris-common" ],
         cc               => "cc",
         cflags           => sub { join(" ","-xstrconst -Xa -DB_ENDIAN -DBN_DIV2W", at _) },
-        debug_cflags     => "-g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG_ALL",
+        debug_cflags     => "-g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCRYPTO_MDEBUG",
         release_cflags   => "-xO5 -xdepend",
         thread_cflag     => "-D_REENTRANT",
         lflags           => sub { join(" ", at _,"-mt -lpthread") },
diff --git a/Configure b/Configure
index ee8987e..07bb98b 100755
--- a/Configure
+++ b/Configure
@@ -97,7 +97,7 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta
 # Minimum warning options... any contributions to OpenSSL should at least get
 # past these.
 
-my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DCRYPTO_MDEBUG_ALL -DCRYPTO_MDEBUG_ABORT -DREF_CHECK -DDEBUG_UNUSED";
+my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DCRYPTO_MDEBUG -DCRYPTO_MDEBUG_ABORT -DREF_CHECK -DDEBUG_UNUSED";
 
 # These are used in addition to $gcc_devteam_warn when the compiler is clang.
 # TODO(openssl-team): fix problems and investigate if (at least) the
diff --git a/apps/openssl.c b/apps/openssl.c
index f2c7ccf..d21988e 100644
--- a/apps/openssl.c
+++ b/apps/openssl.c
@@ -171,7 +171,6 @@ static int apps_startup()
 #ifdef SIGPIPE
     signal(SIGPIPE, SIG_IGN);
 #endif
-    CRYPTO_malloc_init();
     ERR_load_crypto_strings();
     ERR_load_SSL_strings();
 
@@ -311,15 +310,8 @@ int main(int argc, char *argv[])
 #endif
 
     p = getenv("OPENSSL_DEBUG_MEMORY");
-    if (p == NULL)
-        /* if not set, use compiled-in default */
-        ;
-    else if (strcmp(p, "off") != 0) {
-        CRYPTO_malloc_debug_init();
-        CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-    } else {
-        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-    }
+    if (p != NULL && strcmp(p, "on") == 0)
+        CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
     CRYPTO_set_locking_callback(lock_dbg_cb);
 
@@ -437,7 +429,9 @@ int main(int argc, char *argv[])
     BIO_free(bio_in);
     BIO_free_all(bio_out);
     apps_shutdown();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks(bio_err);
+#endif
     BIO_free(bio_err);
     return (ret);
 }
diff --git a/crypto/cms/Makefile b/crypto/cms/Makefile
index 832c731..e18e9ad 100644
--- a/crypto/cms/Makefile
+++ b/crypto/cms/Makefile
@@ -160,15 +160,16 @@ cms_env.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h
 cms_env.o: cms_env.c cms_lcl.h
 cms_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 cms_err.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
-cms_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
-cms_err.o: ../../include/openssl/ec.h ../../include/openssl/err.h
-cms_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
-cms_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-cms_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-cms_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-cms_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-cms_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-cms_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+cms_err.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+cms_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
+cms_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+cms_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+cms_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+cms_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+cms_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+cms_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+cms_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+cms_err.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
 cms_err.o: cms_err.c
 cms_ess.o: ../../e_os.h ../../include/openssl/asn1.h
 cms_ess.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
@@ -188,17 +189,18 @@ cms_ess.o: ../../include/openssl/x509v3.h ../include/internal/cryptlib.h
 cms_ess.o: cms_ess.c cms_lcl.h
 cms_io.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 cms_io.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-cms_io.o: ../../include/openssl/cms.h ../../include/openssl/crypto.h
-cms_io.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-cms_io.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-cms_io.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-cms_io.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
-cms_io.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-cms_io.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
-cms_io.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
-cms_io.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
-cms_io.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-cms_io.o: ../../include/openssl/x509_vfy.h cms_io.c cms_lcl.h
+cms_io.o: ../../include/openssl/cms.h ../../include/openssl/conf.h
+cms_io.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+cms_io.o: ../../include/openssl/ec.h ../../include/openssl/err.h
+cms_io.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+cms_io.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+cms_io.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+cms_io.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
+cms_io.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
+cms_io.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
+cms_io.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+cms_io.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+cms_io.o: ../../include/openssl/x509v3.h cms_io.c cms_lcl.h
 cms_kari.o: ../../e_os.h ../../include/openssl/aes.h
 cms_kari.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 cms_kari.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
diff --git a/crypto/ct/Makefile b/crypto/ct/Makefile
index 49771d9..e4fb65b 100644
--- a/crypto/ct/Makefile
+++ b/crypto/ct/Makefile
@@ -70,7 +70,8 @@ ct_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ct_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 ct_err.o: ../../include/openssl/symhacks.h ../include/internal/ct_int.h
 ct_err.o: ct_err.c
-ct_lib.o: ../../e_os.h ../../include/openssl/asn1.h
+ct_lib.o: ../../e_os.h ../../include/internal/dane.h
+ct_lib.o: ../../include/internal/numbers.h ../../include/openssl/asn1.h
 ct_lib.o: ../../include/openssl/async.h ../../include/openssl/bio.h
 ct_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
 ct_lib.o: ../../include/openssl/comp.h ../../include/openssl/crypto.h
diff --git a/crypto/dh/Makefile b/crypto/dh/Makefile
index 757ccf0..86e3c2c 100644
--- a/crypto/dh/Makefile
+++ b/crypto/dh/Makefile
@@ -65,17 +65,19 @@ clean:
 dh_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
 dh_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 dh_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
-dh_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-dh_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-dh_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-dh_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-dh_ameth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+dh_ameth.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+dh_ameth.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
+dh_ameth.o: ../../include/openssl/ec.h ../../include/openssl/err.h
+dh_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+dh_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+dh_ameth.o: ../../include/openssl/opensslconf.h
 dh_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 dh_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 dh_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 dh_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-dh_ameth.o: ../../include/openssl/x509_vfy.h ../include/internal/asn1_int.h
-dh_ameth.o: ../include/internal/cryptlib.h dh_ameth.c
+dh_ameth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+dh_ameth.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h
+dh_ameth.o: dh_ameth.c
 dh_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 dh_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 dh_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
@@ -121,15 +123,16 @@ dh_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 dh_gen.o: ../include/internal/cryptlib.h dh_gen.c
 dh_kdf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
 dh_kdf.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
-dh_kdf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
-dh_kdf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-dh_kdf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
-dh_kdf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
-dh_kdf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
-dh_kdf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
-dh_kdf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
-dh_kdf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-dh_kdf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
+dh_kdf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+dh_kdf.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
+dh_kdf.o: ../../include/openssl/ec.h ../../include/openssl/evp.h
+dh_kdf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+dh_kdf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+dh_kdf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
+dh_kdf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+dh_kdf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+dh_kdf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+dh_kdf.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
 dh_kdf.o: dh_kdf.c
 dh_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
 dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
diff --git a/crypto/dsa/Makefile b/crypto/dsa/Makefile
index 5f4fb52..796d8a3 100644
--- a/crypto/dsa/Makefile
+++ b/crypto/dsa/Makefile
@@ -65,18 +65,19 @@ clean:
 dsa_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
 dsa_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 dsa_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
-dsa_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
-dsa_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-dsa_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-dsa_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-dsa_ameth.o: ../../include/openssl/objects.h
+dsa_ameth.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+dsa_ameth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+dsa_ameth.o: ../../include/openssl/ec.h ../../include/openssl/err.h
+dsa_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+dsa_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 dsa_ameth.o: ../../include/openssl/opensslconf.h
 dsa_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 dsa_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 dsa_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 dsa_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-dsa_ameth.o: ../../include/openssl/x509_vfy.h ../include/internal/asn1_int.h
-dsa_ameth.o: ../include/internal/cryptlib.h dsa_ameth.c
+dsa_ameth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+dsa_ameth.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h
+dsa_ameth.o: dsa_ameth.c
 dsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 dsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
diff --git a/crypto/ec/Makefile b/crypto/ec/Makefile
index 7933898..5abe958 100644
--- a/crypto/ec/Makefile
+++ b/crypto/ec/Makefile
@@ -118,17 +118,19 @@ ec2_smpl.o: ec2_smpl.c ec_lcl.h
 ec_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
 ec_ameth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 ec_ameth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-ec_ameth.o: ../../include/openssl/cms.h ../../include/openssl/crypto.h
-ec_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-ec_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-ec_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-ec_ameth.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+ec_ameth.o: ../../include/openssl/cms.h ../../include/openssl/conf.h
+ec_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+ec_ameth.o: ../../include/openssl/ec.h ../../include/openssl/err.h
+ec_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+ec_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+ec_ameth.o: ../../include/openssl/opensslconf.h
 ec_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ec_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 ec_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 ec_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-ec_ameth.o: ../../include/openssl/x509_vfy.h ../include/internal/asn1_int.h
-ec_ameth.o: ../include/internal/cryptlib.h ec_ameth.c
+ec_ameth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+ec_ameth.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h
+ec_ameth.o: ec_ameth.c
 ec_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 ec_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 ec_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
diff --git a/crypto/engine/eng_dyn.c b/crypto/engine/eng_dyn.c
index 23f01cf..d19cab2 100644
--- a/crypto/engine/eng_dyn.c
+++ b/crypto/engine/eng_dyn.c
@@ -506,8 +506,6 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
      * would also increase opaqueness.
      */
     fns.static_state = ENGINE_get_static_state();
-    CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
-                             &fns.mem_fns.realloc_cb, &fns.mem_fns.free_cb);
     fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback();
     fns.lock_fns.lock_add_lock_cb = CRYPTO_get_add_lock_callback();
     fns.lock_fns.dynlock_create_cb = CRYPTO_get_dynlock_create_callback();
diff --git a/crypto/mem.c b/crypto/mem.c
index 939ad69..ec9efea 100644
--- a/crypto/mem.c
+++ b/crypto/mem.c
@@ -58,222 +58,63 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <openssl/crypto.h>
 #include "internal/cryptlib.h"
 
-static int allow_customize = 1; /* we provide flexible functions for */
-static int allow_customize_debug = 1; /* exchanging memory-related functions
-                                       * at run-time, but this must be done
-                                       * before any blocks are actually
-                                       * allocated; or we'll run into huge
-                                       * problems when malloc/free pairs
-                                       * don't match etc. */
-
 /*
  * the following pointers may be changed as long as 'allow_customize' is set
  */
+static int allow_customize = 1;
 
-static void *(*malloc_func) (size_t) = malloc;
-static void *default_malloc_ex(size_t num, const char *file, int line)
-{
-    return malloc_func(num);
-}
-
-static void *(*malloc_ex_func) (size_t, const char *file, int line)
-    = default_malloc_ex;
-
-static void *(*realloc_func) (void *, size_t) = realloc;
-static void *default_realloc_ex(void *str, size_t num,
-                                const char *file, int line)
-{
-    return realloc_func(str, num);
-}
-
-static void *(*realloc_ex_func) (void *, size_t, const char *file, int line)
-    = default_realloc_ex;
-
-static void (*free_func) (void *) = free;
-
-static void *(*malloc_secure_func)(size_t) = malloc;
-static void *default_malloc_secure_ex(size_t num, const char *file, int line)
-{
-    return malloc_secure_func(num);
-}
-static void *(*malloc_secure_ex_func)(size_t, const char *file, int line)
-    = default_malloc_secure_ex;
-static void (*free_secure_func)(void *) = free;
+static void *(*malloc_wrapper)(size_t, const char *, int)
+    = CRYPTO_malloc;
+static void *(*realloc_wrapper)(void *, size_t, const char *, int)
+    = CRYPTO_realloc;
+static void (*free_wrapper)(void *)
+    = CRYPTO_free;
 
-/* may be changed as long as 'allow_customize_debug' is set */
-/* XXX use correct function pointer types */
 #ifdef CRYPTO_MDEBUG
-/* use default functions from mem_dbg.c */
-static void (*malloc_debug_func) (void *, size_t, const char *, int, int)
-    = CRYPTO_dbg_malloc;
-static void (*realloc_debug_func) (void *, void *, size_t, const char *, int,
-                                   int)
-    = CRYPTO_dbg_realloc;
-static void (*free_debug_func) (void *, int) = CRYPTO_dbg_free;
-static void (*set_debug_options_func) (long) = CRYPTO_dbg_set_options;
-static long (*get_debug_options_func) (void) = CRYPTO_dbg_get_options;
+static int call_malloc_debug = 1;
 #else
-/*
- * applications can use CRYPTO_malloc_debug_init() to select above case at
- * run-time
- */
-static void (*malloc_debug_func) (void *, size_t, const char *, int, int) = NULL;
-static void (*realloc_debug_func) (void *, void *, size_t, const char *, int,
-                                   int)
-    = NULL;
-static void (*free_debug_func) (void *, int) = NULL;
-static void (*set_debug_options_func) (long) = NULL;
-static long (*get_debug_options_func) (void) = NULL;
+static int call_malloc_debug = 0;
 #endif
 
-int CRYPTO_set_mem_functions(void *(*m) (size_t), void *(*r) (void *, size_t),
-                             void (*f) (void *))
-{
-    /* Dummy call just to ensure OPENSSL_init() gets linked in */
-    OPENSSL_init();
-    if (!allow_customize)
-        return 0;
-    if ((m == 0) || (r == 0) || (f == 0))
-        return 0;
-    malloc_func = m;
-    malloc_ex_func = default_malloc_ex;
-    realloc_func = r;
-    realloc_ex_func = default_realloc_ex;
-    free_func = f;
-    /* If user wants to intercept the secure or locked functions, do it
-     * after the basic functions. */
-    malloc_secure_func = m;
-    malloc_secure_ex_func = default_malloc_secure_ex;
-    free_secure_func = f;
-    return 1;
-}
-
-int CRYPTO_set_mem_ex_functions(void *(*m) (size_t, const char *, int),
-                                void *(*r) (void *, size_t, const char *,
-                                            int), void (*f) (void *))
-{
-    if (!allow_customize)
-        return 0;
-    if ((m == 0) || (r == 0) || (f == 0))
-        return 0;
-    malloc_func = 0;
-    malloc_ex_func = m;
-    realloc_func = 0;
-    realloc_ex_func = r;
-    free_func = f;
-    malloc_secure_func = 0;
-    malloc_secure_ex_func = m;
-    free_secure_func = f;
-    return 1;
-}
-
-int CRYPTO_set_secure_mem_functions(void *(*m)(size_t), void (*f)(void *))
+int CRYPTO_set_mem_functions(
+        void *(*m)(size_t, const char *, int),
+        void *(*r)(void *, size_t, const char *, int),
+        void (*f)(void *))
 {
-    /* Dummy call just to ensure OPENSSL_init() gets linked in */
-    OPENSSL_init();
     if (!allow_customize)
         return 0;
-    if ((m == 0) || (f == 0))
-        return 0;
-    malloc_secure_func = m;
-    malloc_secure_ex_func = default_malloc_secure_ex;
-    free_secure_func = f;
+    if (m)
+        malloc_wrapper = m;
+    if (r)
+        realloc_wrapper = r;
+    if (f)
+        free_wrapper = f;
     return 1;
 }
 
-int CRYPTO_set_secure_mem_ex_functions(void *(*m)(size_t, const char *, int),
-                                       void (*f)(void *))
+int CRYPTO_set_mem_debug(int flag)
 {
     if (!allow_customize)
         return 0;
-    if ((m == NULL) || (f == NULL))
-        return 0;
-    malloc_secure_func = 0;
-    malloc_secure_ex_func = m;
-    free_secure_func = f;
-    return 1;
-}
-
-int CRYPTO_set_mem_debug_functions(void (*m) (void *, size_t,
-                                              const char *, int, int),
-                                   void (*r) (void *, void *, size_t,
-                                              const char *, int, int),
-                                   void (*f) (void *, int), void (*so) (long),
-                                   long (*go) (void))
-{
-    if (!allow_customize_debug)
-        return 0;
-    malloc_debug_func = m;
-    realloc_debug_func = r;
-    free_debug_func = f;
-    set_debug_options_func = so;
-    get_debug_options_func = go;
+    call_malloc_debug = flag;
     return 1;
 }
 
-void CRYPTO_get_mem_functions(void *(**m) (size_t),
-                              void *(**r) (void *, size_t),
-                              void (**f) (void *))
+void CRYPTO_get_mem_functions(
+        void *(**m)(size_t, const char *, int),
+        void *(**r)(void *, size_t, const char *, int),
+        void (**f)(void *))
 {
     if (m != NULL)
-        *m = (malloc_ex_func == default_malloc_ex) ? malloc_func : 0;
+        *m = malloc_wrapper;
     if (r != NULL)
-        *r = (realloc_ex_func == default_realloc_ex) ? realloc_func : 0;
-    if (f != NULL)
-        *f = free_func;
-}
-
-void CRYPTO_get_mem_ex_functions(void *(**m) (size_t, const char *, int),
-                                 void *(**r) (void *, size_t, const char *,
-                                              int), void (**f) (void *))
-{
-    if (m != NULL)
-        *m = (malloc_ex_func != default_malloc_ex) ? malloc_ex_func : 0;
-    if (r != NULL)
-        *r = (realloc_ex_func != default_realloc_ex) ? realloc_ex_func : 0;
-    if (f != NULL)
-        *f = free_func;
-}
-
-void CRYPTO_get_secure_mem_functions(void *(**m)(size_t), void (**f)(void *))
-{
-    if (m != NULL)
-        *m = (malloc_secure_ex_func == default_malloc_secure_ex) ?
-            malloc_secure_func : 0;
+        *r = realloc_wrapper;
     if (f != NULL)
-        *f=free_secure_func;
-}
-
-void CRYPTO_get_secure_mem_ex_functions(void *(**m)(size_t,const char *,int),
-                                        void (**f)(void *))
-{
-    if (m != NULL)
-        *m = (malloc_secure_ex_func != default_malloc_secure_ex) ?
-            malloc_secure_ex_func : 0;
-    if (f != NULL)
-        *f=free_secure_func;
-}
-
-void CRYPTO_get_mem_debug_functions(void (**m) (void *, size_t,
-                                                const char *, int, int),
-                                    void (**r) (void *, void *, size_t,
-                                                const char *, int, int),
-                                    void (**f) (void *, int),
-                                    void (**so) (long), long (**go) (void))
-{
-    if (m != NULL)
-        *m = malloc_debug_func;
-    if (r != NULL)
-        *r = realloc_debug_func;
-    if (f != NULL)
-        *f = free_debug_func;
-    if (so != NULL)
-        *so = set_debug_options_func;
-    if (go != NULL)
-        *go = get_debug_options_func;
+        *f = free_wrapper;
 }
 
 void *CRYPTO_malloc(size_t num, const char *file, int line)
@@ -283,16 +124,20 @@ void *CRYPTO_malloc(size_t num, const char *file, int line)
     if (num <= 0)
         return NULL;
 
-    if (allow_customize)
-        allow_customize = 0;
-    if (malloc_debug_func != NULL) {
-        if (allow_customize_debug)
-            allow_customize_debug = 0;
-        malloc_debug_func(NULL, num, file, line, 0);
+    allow_customize = 0;
+#ifdef CRYPTO_MDEBUG
+    if (call_malloc_debug) {
+        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);
+        ret = malloc(num);
+        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);
+    } else {
+        ret = malloc(num);
     }
-    ret = malloc_ex_func(num, file, line);
-    if (malloc_debug_func != NULL)
-        malloc_debug_func(ret, num, file, line, 1);
+#else
+    (void)file;
+    (void)line;
+    ret = malloc(num);
+#endif
 
 #ifndef OPENSSL_CPUID_OBJ
     /*
@@ -320,21 +165,29 @@ void *CRYPTO_zalloc(size_t num, const char *file, int line)
 
 void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
 {
-    void *ret = NULL;
-
     if (str == NULL)
         return CRYPTO_malloc(num, file, line);
 
-    if (num <= 0)
+    if (num == 0) {
+        CRYPTO_free(str);
         return NULL;
+    }
 
-    if (realloc_debug_func != NULL)
-        realloc_debug_func(str, NULL, num, file, line, 0);
-    ret = realloc_ex_func(str, num, file, line);
-    if (realloc_debug_func != NULL)
-        realloc_debug_func(str, ret, num, file, line, 1);
+    allow_customize = 0;
+#ifdef CRYPTO_MDEBUG
+    if (call_malloc_debug) {
+        void *ret;
+        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);
+        ret = realloc(str, num);
+        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);
+        return ret;
+    }
+#else
+    (void)file;
+    (void)line;
+#endif
+    return realloc(str, num);
 
-    return ret;
 }
 
 void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
@@ -345,56 +198,59 @@ void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
     if (str == NULL)
         return CRYPTO_malloc(num, file, line);
 
-    if (num <= 0)
+    if (num == 0) {
+        CRYPTO_clear_free(str, old_len);
         return NULL;
+    }
 
-    /*
-     * We don't support shrinking the buffer. Note the memcpy that copies
-     * |old_len| bytes to the new buffer, below.
-     */
-    if (num < old_len)
-        return NULL;
+    /* Can't shrink the buffer since memcpy below copies |old_len| bytes. */
+    if (num < old_len) {
+        memset((char*)str + num, 0, old_len - num);
+        return str;
+    }
 
-    if (realloc_debug_func != NULL)
-        realloc_debug_func(str, NULL, num, file, line, 0);
-    ret = malloc_ex_func(num, file, line);
-    if (ret) {
-        memcpy(ret, str, old_len);
-        OPENSSL_clear_free(str, old_len);
+    /* Allocate new memory.  Call malloc and do a copy, so that we can
+     * cleanse the old buffer. */
+#ifdef CRYPTO_MDEBUG
+    if (call_malloc_debug) {
+        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);
+        ret = malloc(num);
+        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);
+    } else {
+        ret = malloc(num);
     }
-    if (realloc_debug_func != NULL)
-        realloc_debug_func(str, ret, num, file, line, 1);
+#else
+    (void)file;
+    (void)line;
+    ret = malloc(num);
+#endif
 
+    if (ret)
+        memcpy(ret, str, old_len);
+    CRYPTO_clear_free(str, old_len);
     return ret;
 }
 
 void CRYPTO_free(void *str)
 {
-    if (free_debug_func != NULL)
-        free_debug_func(str, 0);
-    free_func(str);
-    if (free_debug_func != NULL)
-        free_debug_func(NULL, 1);
+#ifdef CRYPTO_MDEBUG
+    if (call_malloc_debug) {
+        CRYPTO_mem_debug_free(str, 0);
+        free(str);
+        CRYPTO_mem_debug_free(str, 1);
+    } else {
+        free(str);
+    }
+#else
+    free(str);
+#endif
 }
 
 void CRYPTO_clear_free(void *str, size_t num)
 {
-    if (!str)
+    if (str == NULL)
         return;
     if (num)
         OPENSSL_cleanse(str, num);
     CRYPTO_free(str);
 }
-
-void CRYPTO_set_mem_debug_options(long bits)
-{
-    if (set_debug_options_func != NULL)
-        set_debug_options_func(bits);
-}
-
-long CRYPTO_get_mem_debug_options(void)
-{
-    if (get_debug_options_func != NULL)
-        return get_debug_options_func();
-    return 0;
-}
diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c
index 924652a..2132b7d 100644
--- a/crypto/mem_dbg.c
+++ b/crypto/mem_dbg.c
@@ -121,7 +121,6 @@
 # include <execinfo.h>
 #endif
 
-static int mh_mode = CRYPTO_MEM_CHECK_OFF;
 /*
  * The state changes to CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE when
  * the application asks for it (usually after library initialisation for
@@ -133,14 +132,15 @@ static int mh_mode = CRYPTO_MEM_CHECK_OFF;
  * checking temporarily. State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes
  * no sense whatsoever.
  */
+static int mh_mode = CRYPTO_MEM_CHECK_OFF;
 
+#ifdef CRYPTO_MDEBUG
 static unsigned long order = 0; /* number of memory requests */
 
 DECLARE_LHASH_OF(MEM);
 static LHASH_OF(MEM) *mh = NULL; /* hash-table of memory requests (address as
                                   * key); access requires MALLOC2 lock */
 
-typedef struct app_mem_info_st
 /*-
  * For application-defined information (static C-string `info')
  * to be displayed in memory leak list.
@@ -148,7 +148,7 @@ typedef struct app_mem_info_st
  *   OPENSSL_mem_debug_push("...")     to push an entry,
  *   OPENSSL_mem_debug_pop()     to pop an entry,
  */
-{
+typedef struct app_mem_info_st {
     CRYPTO_THREADID threadid;
     const char *file;
     int line;
@@ -157,18 +157,16 @@ typedef struct app_mem_info_st
     int references;
 } APP_INFO;
 
-static void app_info_free(APP_INFO *);
-
+/*
+ * hash-table with those app_mem_info_st's that are at the
+ * top of their thread's stack (with `thread' as key); access requires
+ * MALLOC2 lock
+ */
 DECLARE_LHASH_OF(APP_INFO);
-static LHASH_OF(APP_INFO) *amih = NULL; /* hash-table with those
-                                         * app_mem_info_st's that are at the
-                                         * top of their thread's stack (with
-                                         * `thread' as key); access requires
-                                         * MALLOC2 lock */
+static LHASH_OF(APP_INFO) *amih = NULL;
 
-typedef struct mem_st
 /* memory-block description */
-{
+typedef struct mem_st {
     void *addr;
     int num;
     const char *file;
@@ -183,17 +181,8 @@ typedef struct mem_st
 #endif
 } MEM;
 
-static long options =           /* extra information to be recorded */
-#if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
-    V_CRYPTO_MDEBUG_TIME |
-#endif
-#if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
-    V_CRYPTO_MDEBUG_THREAD |
-#endif
-    0;
-
-static unsigned int num_disable = 0; /* num_disable > 0 iff mh_mode ==
-                                      * CRYPTO_MEM_CHECK_ON (w/o ..._ENABLE) */
+/* num_disable > 0 iff mh_mode == CRYPTO_MEM_CHECK_ON (w/o ..._ENABLE) */
+static unsigned int num_disable = 0;
 
 /*
  * Valid iff num_disable > 0.  CRYPTO_LOCK_MALLOC2 is locked exactly in this
@@ -210,29 +199,32 @@ static void app_info_free(APP_INFO *inf)
         OPENSSL_free(inf);
     }
 }
+#endif
 
 int CRYPTO_mem_ctrl(int mode)
 {
+#ifndef CRYPTO_MDEBUG
+    return mode - mode;
+#else
     int ret = mh_mode;
 
     CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
     switch (mode) {
-        /*
-         * for applications (not to be called while multiple threads use the
-         * library):
-         */
-    case CRYPTO_MEM_CHECK_ON:  /* aka MemCheck_start() */
+    default:
+        break;
+
+    case CRYPTO_MEM_CHECK_ON:
         mh_mode = CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE;
         num_disable = 0;
         break;
-    case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
+
+    case CRYPTO_MEM_CHECK_OFF:
         mh_mode = 0;
-        num_disable = 0;        /* should be true *before* MemCheck_stop is
-                                 * used, or there'll be a lot of confusion */
+        num_disable = 0;
         break;
 
-        /* switch off temporarily (for library-internal use): */
-    case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
+    /* switch off temporarily (for library-internal use): */
+    case CRYPTO_MEM_CHECK_DISABLE:
         if (mh_mode & CRYPTO_MEM_CHECK_ON) {
             CRYPTO_THREADID cur;
             CRYPTO_THREADID_current(&cur);
@@ -262,7 +254,8 @@ int CRYPTO_mem_ctrl(int mode)
             num_disable++;
         }
         break;
-    case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
+
+    case CRYPTO_MEM_CHECK_ENABLE:
         if (mh_mode & CRYPTO_MEM_CHECK_ON) {
             if (num_disable) {  /* always true, or something is going wrong */
                 num_disable--;
@@ -273,15 +266,15 @@ int CRYPTO_mem_ctrl(int mode)
             }
         }
         break;
-
-    default:
-        break;
     }
     CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
     return (ret);
+#endif
 }
 
-int CRYPTO_is_mem_check_on(void)
+#ifdef CRYPTO_MDEBUG
+
+static int mem_check_on(void)
 {
     int ret = 0;
 
@@ -298,16 +291,6 @@ int CRYPTO_is_mem_check_on(void)
     return (ret);
 }
 
-void CRYPTO_dbg_set_options(long bits)
-{
-    options = bits;
-}
-
-long CRYPTO_dbg_get_options(void)
-{
-    return options;
-}
-
 static int mem_cmp(const MEM *a, const MEM *b)
 {
 #ifdef _WIN64
@@ -388,17 +371,14 @@ int CRYPTO_mem_debug_push(const char *info, const char *file, int line)
     APP_INFO *ami, *amim;
     int ret = 0;
 
-    if (is_MemCheck_on()) {
-        MemCheck_off();         /* obtain MALLOC2 lock */
+    if (mem_check_on()) {
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
 
-        if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL) {
-            ret = 0;
+        if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL)
             goto err;
-        }
         if (amih == NULL) {
             if ((amih = lh_APP_INFO_new()) == NULL) {
                 OPENSSL_free(ami);
-                ret = 0;
                 goto err;
             }
         }
@@ -412,8 +392,9 @@ int CRYPTO_mem_debug_push(const char *info, const char *file, int line)
 
         if ((amim = lh_APP_INFO_insert(amih, ami)) != NULL)
             ami->next = amim;
+        ret = 1;
  err:
-        MemCheck_on();          /* release MALLOC2 lock */
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     }
 
     return (ret);
@@ -423,20 +404,18 @@ int CRYPTO_mem_debug_pop(void)
 {
     int ret = 0;
 
-    if (is_MemCheck_on()) {     /* _must_ be true, or something went severely
-                                 * wrong */
-        MemCheck_off();         /* obtain MALLOC2 lock */
-
+    if (mem_check_on()) {
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
         ret = (pop_info() != NULL);
-
-        MemCheck_on();          /* release MALLOC2 lock */
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     }
     return (ret);
 }
 
 static unsigned long break_order_num = 0;
-void CRYPTO_dbg_malloc(void *addr, size_t num, const char *file, int line,
-                       int before_p)
+
+void CRYPTO_mem_debug_malloc(void *addr, size_t num, int before_p,
+                             const char *file, int line)
 {
     MEM *m, *mm;
     APP_INFO tmp, *amim;
@@ -448,12 +427,11 @@ void CRYPTO_dbg_malloc(void *addr, size_t num, const char *file, int line,
         if (addr == NULL)
             break;
 
-        if (is_MemCheck_on()) {
-            MemCheck_off();     /* make sure we hold MALLOC2 lock */
+        if (mem_check_on()) {
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
             if ((m = OPENSSL_malloc(sizeof(*m))) == NULL) {
                 OPENSSL_free(addr);
-                MemCheck_on();  /* release MALLOC2 lock if num_disabled drops
-                                 * to 0 */
+                CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
                 return;
             }
             if (mh == NULL) {
@@ -469,23 +447,17 @@ void CRYPTO_dbg_malloc(void *addr, size_t num, const char *file, int line,
             m->file = file;
             m->line = line;
             m->num = num;
-            if (options & V_CRYPTO_MDEBUG_THREAD)
-                CRYPTO_THREADID_current(&m->threadid);
-            else
-                memset(&m->threadid, 0, sizeof(m->threadid));
+            CRYPTO_THREADID_current(&m->threadid);
 
             if (order == break_order_num) {
                 /* BREAK HERE */
                 m->order = order;
             }
             m->order = order++;
-            if (options & V_CRYPTO_MDEBUG_TIME)
-                m->time = time(NULL);
-            else
-                m->time = 0;
-#if defined(CRYPTO_MDEBUG_BACKTRACE) && defined(__GNUC__)
+# if defined(CRYPTO_MDEBUG_BACKTRACE) && defined(__GNUC__)
             m->array_siz = backtrace(m->array, OSSL_NELEM(m->array));
-#endif
+# endif
+            m->time = time(NULL);
 
             CRYPTO_THREADID_current(&tmp.threadid);
             m->app_info = NULL;
@@ -503,15 +475,14 @@ void CRYPTO_dbg_malloc(void *addr, size_t num, const char *file, int line,
                 OPENSSL_free(mm);
             }
  err:
-            MemCheck_on();      /* release MALLOC2 lock if num_disabled drops
-                                 * to 0 */
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         }
         break;
     }
     return;
 }
 
-void CRYPTO_dbg_free(void *addr, int before_p)
+void CRYPTO_mem_debug_free(void *addr, int before_p)
 {
     MEM m, *mp;
 
@@ -520,8 +491,8 @@ void CRYPTO_dbg_free(void *addr, int before_p)
         if (addr == NULL)
             break;
 
-        if (is_MemCheck_on() && (mh != NULL)) {
-            MemCheck_off();     /* make sure we hold MALLOC2 lock */
+        if (mem_check_on() && (mh != NULL)) {
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
 
             m.addr = addr;
             mp = lh_MEM_delete(mh, &m);
@@ -530,8 +501,7 @@ void CRYPTO_dbg_free(void *addr, int before_p)
                 OPENSSL_free(mp);
             }
 
-            MemCheck_on();      /* release MALLOC2 lock if num_disabled drops
-                                 * to 0 */
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         }
         break;
     case 1:
@@ -539,8 +509,8 @@ void CRYPTO_dbg_free(void *addr, int before_p)
     }
 }
 
-void CRYPTO_dbg_realloc(void *addr1, void *addr2, size_t num,
-                        const char *file, int line, int before_p)
+void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, size_t num,
+                              int before_p, const char *file, int line)
 {
     MEM m, *mp;
 
@@ -552,12 +522,12 @@ void CRYPTO_dbg_realloc(void *addr1, void *addr2, size_t num,
             break;
 
         if (addr1 == NULL) {
-            CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);
+            CRYPTO_mem_debug_malloc(addr2, num, 128 | before_p, file, line);
             break;
         }
 
-        if (is_MemCheck_on()) {
-            MemCheck_off();     /* make sure we hold MALLOC2 lock */
+        if (mem_check_on()) {
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
 
             m.addr = addr1;
             mp = lh_MEM_delete(mh, &m);
@@ -570,8 +540,7 @@ void CRYPTO_dbg_realloc(void *addr1, void *addr2, size_t num,
                 (void)lh_MEM_insert(mh, mp);
             }
 
-            MemCheck_on();      /* release MALLOC2 lock if num_disabled drops
-                                 * to 0 */
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         }
         break;
     }
@@ -602,23 +571,18 @@ static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
         return;
     }
 
-    if (options & V_CRYPTO_MDEBUG_TIME) {
-        lcl = localtime(&m->time);
-
-        BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ",
-                     lcl->tm_hour, lcl->tm_min, lcl->tm_sec);
-        bufp += strlen(bufp);
-    }
+    lcl = localtime(&m->time);
+    BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ",
+                 lcl->tm_hour, lcl->tm_min, lcl->tm_sec);
+    bufp += strlen(bufp);
 
     BIO_snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ",
                  m->order, m->file, m->line);
     bufp += strlen(bufp);
 
-    if (options & V_CRYPTO_MDEBUG_THREAD) {
-        BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ",
-                     CRYPTO_THREADID_hash(&m->threadid));
-        bufp += strlen(bufp);
-    }
+    BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ",
+                 CRYPTO_THREADID_hash(&m->threadid));
+    bufp += strlen(bufp);
 
     BIO_snprintf(bufp, BUF_REMAIN, "number=%d, address=%p\n",
                  m->num, m->addr);
@@ -631,6 +595,7 @@ static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
 
     amip = m->app_info;
     ami_cnt = 0;
+
     if (amip) {
         CRYPTO_THREADID_cpy(&ti, &amip->threadid);
 
@@ -666,9 +631,9 @@ static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
     {
         size_t i;
         char **strings = backtrace_symbols(m->array, m->array_siz);
+
         for (i = 0; i < m->array_siz; i++)
             fprintf(stderr, "##> %s\n", strings[i]);
-
         free(strings);
     }
 #endif
@@ -683,7 +648,7 @@ void CRYPTO_mem_leaks(BIO *b)
     if (mh == NULL && amih == NULL)
         return;
 
-    MemCheck_off();             /* obtain MALLOC2 lock */
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
 
     ml.bio = b;
     ml.bytes = 0;
@@ -698,29 +663,23 @@ void CRYPTO_mem_leaks(BIO *b)
     }
     if (ml.chunks != 0) {
         BIO_printf(b, "%ld bytes leaked in %d chunks\n", ml.bytes, ml.chunks);
-#ifdef CRYPTO_MDEBUG_ABORT
+# ifdef CRYPTO_MDEBUG_ABORT
         abort();
-#endif
+# endif
     } else {
         /*
          * Make sure that, if we found no leaks, memory-leak debugging itself
          * does not introduce memory leaks (which might irritate external
          * debugging tools). (When someone enables leak checking, but does not
-         * call this function, we declare it to be their fault.) XXX This
-         * should be in CRYPTO_mem_leaks_cb, and CRYPTO_mem_leaks should be
-         * implemented by using CRYPTO_mem_leaks_cb. (Also there should be a
-         * variant of lh_doall_arg that takes a function pointer instead of a
-         * void *; this would obviate the ugly and illegal void_fn_to_char
-         * kludge in CRYPTO_mem_leaks_cb. Otherwise the code police will come
-         * and get us.)
+         * call this function, we declare it to be their fault.)
          */
         int old_mh_mode;
 
         CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
 
         /*
-         * avoid deadlock when lh_free() uses CRYPTO_dbg_free(), which uses
-         * CRYPTO_is_mem_check_on
+         * avoid deadlock when lh_free() uses CRYPTO_mem_debug_free(), which uses
+         * mem_check_on
          */
         old_mh_mode = mh_mode;
         mh_mode = CRYPTO_MEM_CHECK_OFF;
@@ -737,10 +696,10 @@ void CRYPTO_mem_leaks(BIO *b)
         mh_mode = old_mh_mode;
         CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
     }
-    MemCheck_on();              /* release MALLOC2 lock */
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
 }
 
-#ifndef OPENSSL_NO_STDIO
+# ifndef OPENSSL_NO_STDIO
 void CRYPTO_mem_leaks_fp(FILE *fp)
 {
     BIO *b;
@@ -752,49 +711,15 @@ void CRYPTO_mem_leaks_fp(FILE *fp)
      * we're creating them at a time when we're trying to check we've not
      * left anything un-free()'d!!
      */
-    MemCheck_off();
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
     b = BIO_new(BIO_s_file());
-    MemCheck_on();
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     if (b == NULL)
         return;
     BIO_set_fp(b, fp, BIO_NOCLOSE);
     CRYPTO_mem_leaks(b);
     BIO_free(b);
 }
-#endif
-
-/*
- * FIXME: We really don't allow much to the callback.  For example, it has no
- * chance of reaching the info stack for the item it processes.  Should it
- * really be this way? -- Richard Levitte
- */
-/*
- * NB: The prototypes have been typedef'd to CRYPTO_MEM_LEAK_CB inside
- * crypto.h If this code is restructured, remove the callback type if it is
- * no longer needed. -- Geoff Thorpe
- */
-
-/*
- * Can't pass CRYPTO_MEM_LEAK_CB directly to lh_MEM_doall_arg because it is a
- * function pointer and conversion to void * is prohibited. Instead pass its
- * address
- */
-
-typedef CRYPTO_MEM_LEAK_CB *PCRYPTO_MEM_LEAK_CB;
-
-static void cb_leak_doall_arg(const MEM *m, PCRYPTO_MEM_LEAK_CB *cb)
-{
-    (*cb) (m->order, m->file, m->line, m->num, m->addr);
-}
+# endif
 
-static IMPLEMENT_LHASH_DOALL_ARG_FN(cb_leak, const MEM, PCRYPTO_MEM_LEAK_CB)
-
-void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb)
-{
-    if (mh == NULL)
-        return;
-    CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
-    lh_MEM_doall_arg(mh, LHASH_DOALL_ARG_FN(cb_leak), PCRYPTO_MEM_LEAK_CB,
-                     &cb);
-    CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
-}
+#endif
diff --git a/crypto/mem_sec.c b/crypto/mem_sec.c
index 4ef8300..5f4f733 100644
--- a/crypto/mem_sec.c
+++ b/crypto/mem_sec.c
@@ -148,6 +148,15 @@ int CRYPTO_secure_allocated(const void *ptr)
 #endif /* IMPLEMENTED */
 }
 
+size_t CRYPTO_secure_used()
+{
+#ifdef IMPLEMENTED
+    return secure_mem_used;
+#else
+    return 0;
+#endif /* IMPLEMENTED */
+}
+
 /* END OF PAGE ...
 
    ... START OF PAGE */
diff --git a/crypto/objects/Makefile b/crypto/objects/Makefile
index d6ccb8a..f413b0f 100644
--- a/crypto/objects/Makefile
+++ b/crypto/objects/Makefile
@@ -80,7 +80,7 @@ o_names.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 o_names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
 o_names.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
 o_names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
-o_names.o: o_names.c
+o_names.o: o_names.c o_names.h
 obj_dat.o: ../../e_os.h ../../include/openssl/asn1.h
 obj_dat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 obj_dat.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
diff --git a/crypto/objects/o_names.c b/crypto/objects/o_names.c
index aa9b400..476c377 100644
--- a/crypto/objects/o_names.c
+++ b/crypto/objects/o_names.c
@@ -55,9 +55,9 @@ int OBJ_NAME_init(void)
 {
     if (names_lh != NULL)
         return (1);
-    MemCheck_off();
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
     names_lh = lh_OBJ_NAME_new();
-    MemCheck_on();
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     return (names_lh != NULL);
 }
 
@@ -70,9 +70,9 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
     NAME_FUNCS *name_funcs;
 
     if (name_funcs_stack == NULL) {
-        MemCheck_off();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
         name_funcs_stack = sk_NAME_FUNCS_new_null();
-        MemCheck_on();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     }
     if (name_funcs_stack == NULL) {
         /* ERROR */
@@ -81,18 +81,18 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
     ret = names_type_num;
     names_type_num++;
     for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {
-        MemCheck_off();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
         name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));
-        MemCheck_on();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         if (name_funcs == NULL) {
             OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
             return (0);
         }
         name_funcs->hash_func = lh_strhash;
         name_funcs->cmp_func = OPENSSL_strcmp;
-        MemCheck_off();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
         sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
-        MemCheck_on();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     }
     name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
     if (hash_func != NULL)
diff --git a/crypto/rsa/Makefile b/crypto/rsa/Makefile
index d5a4c96..9c36b86 100644
--- a/crypto/rsa/Makefile
+++ b/crypto/rsa/Makefile
@@ -69,19 +69,19 @@ clean:
 rsa_ameth.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_ameth.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 rsa_ameth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
-rsa_ameth.o: ../../include/openssl/cms.h ../../include/openssl/crypto.h
-rsa_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-rsa_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-rsa_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-rsa_ameth.o: ../../include/openssl/objects.h
+rsa_ameth.o: ../../include/openssl/cms.h ../../include/openssl/conf.h
+rsa_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+rsa_ameth.o: ../../include/openssl/ec.h ../../include/openssl/err.h
+rsa_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+rsa_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
 rsa_ameth.o: ../../include/openssl/opensslconf.h
 rsa_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 rsa_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
 rsa_ameth.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
 rsa_ameth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 rsa_ameth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
-rsa_ameth.o: ../include/internal/asn1_int.h ../include/internal/cryptlib.h
-rsa_ameth.o: rsa_ameth.c
+rsa_ameth.o: ../../include/openssl/x509v3.h ../include/internal/asn1_int.h
+rsa_ameth.o: ../include/internal/cryptlib.h rsa_ameth.c
 rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
 rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
diff --git a/crypto/x509/Makefile b/crypto/x509/Makefile
index 766c72a..402112b 100644
--- a/crypto/x509/Makefile
+++ b/crypto/x509/Makefile
@@ -85,7 +85,7 @@ by_dir.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 by_dir.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 by_dir.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 by_dir.o: ../../include/openssl/x509_vfy.h ../include/internal/cryptlib.h
-by_dir.o: ../include/internal/x509_int.h by_dir.c
+by_dir.o: ../include/internal/x509_int.h by_dir.c x509_lcl.h
 by_file.o: ../../e_os.h ../../include/openssl/asn1.h
 by_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
 by_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
@@ -325,13 +325,14 @@ x509_v3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 x509_v3.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 x509_v3.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
 x509_v3.o: ../include/internal/cryptlib.h x509_lcl.h x509_v3.c
-x509_vfy.o: ../../e_os.h ../../include/openssl/asn1.h
-x509_vfy.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
-x509_vfy.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
-x509_vfy.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-x509_vfy.o: ../../include/openssl/err.h ../../include/openssl/evp.h
-x509_vfy.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
-x509_vfy.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
+x509_vfy.o: ../../e_os.h ../../include/internal/dane.h
+x509_vfy.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
+x509_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
+x509_vfy.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+x509_vfy.o: ../../include/openssl/ec.h ../../include/openssl/err.h
+x509_vfy.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
+x509_vfy.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+x509_vfy.o: ../../include/openssl/opensslconf.h
 x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 x509_vfy.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 x509_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -482,7 +483,7 @@ x_name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 x_name.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
 x_name.o: ../../include/openssl/x509_vfy.h ../include/internal/asn1_int.h
 x_name.o: ../include/internal/cryptlib.h ../include/internal/x509_int.h
-x_name.o: x_name.c
+x_name.o: x509_lcl.h x_name.c
 x_req.o: ../../e_os.h ../../include/openssl/asn1.h
 x_req.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
 x_req.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
diff --git a/demos/selfsign.c b/demos/selfsign.c
index 0cc265c..f0adba5 100644
--- a/demos/selfsign.c
+++ b/demos/selfsign.c
@@ -16,6 +16,7 @@ int main()
     X509 *x509 = NULL;
     EVP_PKEY *pkey = NULL;
 
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
diff --git a/doc/apps/dhparam.pod b/doc/apps/dhparam.pod
index 5919935..71c61ea 100644
--- a/doc/apps/dhparam.pod
+++ b/doc/apps/dhparam.pod
@@ -103,7 +103,7 @@ this option prints out the DH parameters in human readable form.
 =item B<-C>
 
 this option converts the parameters into C code. The parameters can then
-be loaded by calling the B<get_dh>I<numbits>B<()> function.
+be loaded by calling the get_dhNNNN() function.
 
 =item B<-engine id>
 
diff --git a/doc/crypto/OPENSSL_malloc.pod b/doc/crypto/OPENSSL_malloc.pod
new file mode 100644
index 0000000..bf7c3ab
--- /dev/null
+++ b/doc/crypto/OPENSSL_malloc.pod
@@ -0,0 +1,162 @@
+=pod
+
+=head1 NAME
+
+OPENSSL_malloc_init,
+OPENSSL_malloc, OPENSSL_zalloc, OPENSSL_realloc, OPENSSL_free,
+OPENSSL_clear_realloc, OPENSSL_clear_free,
+CRYPTO_malloc, CRYPTO_zalloc, CRYPTO_realloc, CRYPTO_free,
+OPENSSL_strdup, OPENSSL_strndup,
+OPENSSL_memdup, OPENSSL_strlcpy, OPENSSL_strlcat,
+CRYPTO_clear_realloc, CRYPTO_clear_free,
+CRYPTO_get_mem_functions, CRYPTO_set_mem_functions,
+CRYPTO_set_mem_debug, CRYPTO_mem_ctrl,
+OPENSSL_mem_debug_push, OPENSSL_mem_debug_pop,
+CRYPTO_mem_debug_push, CRYPTO_mem_debug_pop,
+CRYPTO_mem_leaks, CRYPTO_mem_leaks_fp - Memory allocation functions
+
+=head1 SYNOPSIS
+
+ #include <openssl/crypto.h>
+
+ int OPENSSL_malloc_init(void)
+
+ void *OPENSSL_malloc(size_t num)
+ void *OPENSSL_zalloc(size_t num)
+ void *OPENSSL_realloc(void *addr, size_t num)
+ void OPENSSL_free(void *addr)
+ char *OPENSSL_strdup(const char *str)
+ char *OPENSSL_strndup(const char *str, size_t s)
+ void *OPENSSL_clear_realloc(void *p, size_t old_len, size_t num)
+ void OPENSSL_clear_free(void *str, size_t num)
+ void OPENSSL_cleanse(void *ptr, size_t len);
+
+ void *CRYPTO_malloc(size_t num, const char *file, int line)
+ void *CRYPTO_zalloc(size_t num, const char *file, int line)
+ void *CRYPTO_realloc(void *p, size_t num, const char *file, int line)
+ void CRYPTO_free(void *str)
+ char *CRYPTO_strdup(const char *p, const char *file, int line)
+ char *CRYPTO_strndup(const char *p, size_t num, const char *file, int line)
+ void *CRYPTO_clear_realloc(void *p, size_t old_len, size_t num, const char *file, int line)
+ void CRYPTO_clear_free(void *str, size_t num)
+
+ void CRYPTO_get_mem_functions(
+         void *(**m)(size_t, const char *, int),
+         void *(**r)(void *, size_t, const char *, int),
+         void (**f)(void *))
+ int CRYPTO_set_mem_functions(
+         void *(*m)(size_t, const char *, int),
+         void *(*r)(void *, size_t, const char *, int),
+         void (*f)(void *))
+
+ int CRYPTO_set_mem_debug(int onoff)
+
+ #define CRYPTO_MEM_CHECK_OFF
+ #define CRYPTO_MEM_CHECK_ON
+ #define CRYPTO_MEM_CHECK_DISABLE
+ #define CRYPTO_MEM_CHECK_ENABLE
+
+ int CRYPTO_mem_ctrl(int flags);
+
+ int OPENSSL_mem_debug_push(const char *info)
+ int OPENSLS_mem_debug_pop)(void)
+
+ int CRYPTO_mem_debug_push(const char *info, const char *file, int line);
+
+ void CRYPTO_mem_leaks(BIO *b);
+ void CRYPTO_mem_leaks(FILE *fp);
+
+=head1 DESCRIPTION
+
+OpenSSL memory allocation is handled by the B<OPENSSL_xxx> API. These are
+generally macro's that add the standard C B<__FILE__> and B<__LINE__>
+parameters and call a lower-level B<CRYPTO_xxx> API.
+Some functions do not add those parameters, but exist for consistency.
+
+OPENSSL_malloc_init() sets the lower-level memory allocation functions
+to their default implementation.
+It is generally not necessary to call this, except perhaps in certain
+shared-library situations.
+
+OPENSSL_malloc(), OPENSSL_realloc(), and OPENSSL_free() are like the
+C malloc(), realloc(), and free() functions.
+OPENSSL_zalloc() calls memset() to zero the memory before returning.
+
+OPENSSL_clear_realloc() and OPENSSL_clear_free() should be used
+when the buffer at B<addr> holds sensitive information.
+The old buffer is filled with arbitrary data by calling OPENSSL_cleanse()
+before ultimately calling OPENSSL_free().
+
+OPENSSL_strdup(), OPENSSL_strndup() and OPENSSL_memdup() are like the
+equivalent C functions, except that memory is allocated by calling the
+OPENSSL_malloc() and should be releaed by calling OPENSSL_free().
+
+OPENSSL_strlcpy(),
+OPENSSL_strlcat() and OPENSSL_strnlen() are equivalents of the common C
+library functions and are provided for portability.
+
+If no allocations have been done, it is possible to "swap out" the default
+implementations and replace them with alternate versions, or wrappers that
+do some additional housekeeping and then defer to the OpenSSL implementation.
+The CRYPTO_get_mem_functions() function fills in the function pointers for
+with the current functions (normally, and by default,
+CRYPTO_malloc(), CRYPTO_realloc(), and CRYPTO_free()).
+The CRYPTO_set_mem_functions() specifies a different set of functions.
+If any of B<m>, B<r>, or B<f> are NULL, then the function is not changed.
+
+The default implementation can include some debugging capability (if enabled
+at build-time).
+This adds some overhead by keeping a list of all memory allocations, and
+removes items from the list when they are free'd.
+This is most useful for identifying memory leaks.
+CRYPTO_set_mem_debug() turns this tracking on and off.  It is normally
+called at startup, but can be called at any time.
+
+Finer-grain control of the tracking can be done with CRYPTO_mem_ctrl().
+The most common case is to enable tracking, which is done by using
+the B<CRYPTO_MEM_CHECK_ON> constant; it can be turned off by using
+the B<CRYPTO_MEM_CHECK_OFF> value.  The disable and enable values are
+most commonly used within OpenSSL to termporarily suspend and restore
+tracking of library internals.
+
+While checking memory, it can be useful to store additional context
+about what is being done.
+For example, identifying the field names when parsing a complicated
+data structure.
+OPENSSL_mem_debug_push() (which calls CRYPTO_mem_debug_push())
+attachs an identifying string to the allocation stack.
+This must be a global or other static string; it is not copied.
+OPENSSL_mem_debug_pop() removes identifying state from the stack.
+
+At the end of the program, calling CRYPTO_mem_leaks() or
+CRYPTO_mem_leaks_fp() will
+report all "leaked" memory, writing it to the specified BIO B<b>
+or FILE B<fp>.
+Depending on how OpenSSL is built, it may then abort if there
+are any unfree'd allocations, for debugging.
+
+=head1 RETURN VALUES
+
+OPENSSL_malloc_init(), OPENSSL_free(), OPENSSL_clear_free()
+CRYPTO_free(), CRYPTO_clear_free(),
+CRYPTO_get_mem_functions(), and
+CRYPTO_mem_leaks()
+return no value.
+
+OPENSSL_malloc(), OPENSSL_zalloc(), OPENSSL_realloc(),
+OPENSSL_clear_realloc(),
+CRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_realloc(),
+CRYPTO_clear_realloc(),
+OPENSSL_strdup(), and OPENSSL_strndup()
+return a pointer to allocated memory or NULL on error.
+
+CRYPTO_set_mem_functions() and CRYPTO_set_mem_debug()
+return 1 on success or 0 on failure (almost
+always because allocations have already happened).
+
+CRYPTO_mem_ctrl() return the previous value of the flag.
+
+OPENSSL_mem_debug_push() and OPENSSL_mem_debug_pop()
+return 1 on success or 0 on failure.
+
+=cut
diff --git a/doc/crypto/OPENSSL_secure_malloc.pod b/doc/crypto/OPENSSL_secure_malloc.pod
index 588c4b1..5e221e9 100644
--- a/doc/crypto/OPENSSL_secure_malloc.pod
+++ b/doc/crypto/OPENSSL_secure_malloc.pod
@@ -2,7 +2,8 @@
 
 =head1 NAME
 
-CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, OPENSSL_secure_free, OPENSSL_secure_allocated - use secure heap storage
+CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_done, OPENSSL_secure_malloc,
+OPENSSL_secure_free, OPENSSL_secure_allocated - secure heap storage
 
 =head1 SYNOPSIS
 
@@ -15,10 +16,15 @@ CRYPTO_secure_malloc_init, CRYPTO_secure_malloc_done, OPENSSL_secure_malloc, OPE
  void CRYPTO_secure_malloc_done();
 
  void *OPENSSL_secure_malloc(int num);
+ void *CRYPTO_secure_malloc(int num, const char *file, int line);
 
  void OPENSSL_secure_free(void* ptr);
+ void CRYPTO_secure_free(void *ptr);
 
- int OPENSSL_secure_allocated(const void* ptr);
+ size_t OPENSSL_secure_actual_size(const void *ptr);
+ int OPENSSL_secure_allocated(const void *ptr);
+
+ size_t CYRPTO_secure_malloc_used();
 
 =head1 DESCRIPTION
 
@@ -49,15 +55,25 @@ to the process. It can take noticeably long to complete.
 B<OPENSSL_secure_malloc> allocates C<num> bytes from the heap.
 If B<CRYPTO_secure_malloc_init> is not called, this is equivalent to
 calling B<OPENSSL_malloc>.
+It is a macro that expands to
+B<CRYPTO_secure_malloc> and adds the B<__FILE__> and B<__LINE__> parameters.
 
 B<OPENSSL_secure_free> releases the memory at C<ptr> back to the heap.
 It must be called with a value previously obtained from
 B<OPENSSL_secure_malloc>.
 If B<CRYPTO_secure_malloc_init> is not called, this is equivalent to
 calling B<OPENSSL_free>.
+It exists for consistency with B<OPENSSL_secure_malloc> , and
+is a macro that expands to B<CRYPTO_secure_free>.
 
 B<OPENSSL_secure_allocated> tells whether or not a pointer is within
 the secure heap.
+B<OPENSSL_secure_actual_size> tells the actual size allocated to the
+pointer; implementations may allocate more space than initially
+requested, in order to "round up" and reduce secure heap fragmentation.
+
+B<CRYPTO_secure_malloc_used> returns the number of bytes allocated in the
+secure heap.
 
 =head1 RETURN VALUES
 
@@ -78,9 +94,15 @@ the secure heap, or 0 if not.
 B<CRYPTO_secure_malloc_done> and B<OPENSSL_secure_free>
 return no values.
 
+=head1 BUGS
+
+The size parameters should be B<size_t> not B<int> and will be changed
+in a future release.
+
 =head1 SEE ALSO
 
+L<OPENSSL_malloc(3)>,
 L<BN_new(3)>,
-L<bn_internal(3)>
+L<bn_internal(3)>.
 
 =cut
diff --git a/doc/ssl/ssl.pod b/doc/ssl/ssl.pod
index bb3bc94..0d29b54 100644
--- a/doc/ssl/ssl.pod
+++ b/doc/ssl/ssl.pod
@@ -679,6 +679,7 @@ Returns the current handshake state.
 =head1 SEE ALSO
 
 L<openssl(1)>, L<crypto(3)>,
+L<CRYPTO_get_ex_new_index(3)>,
 L<SSL_accept(3)>, L<SSL_clear(3)>,
 L<SSL_connect(3)>,
 L<SSL_CIPHER_get_name(3)>,
@@ -687,7 +688,6 @@ L<SSL_CTX_add_extra_chain_cert(3)>,
 L<SSL_CTX_add_session(3)>,
 L<SSL_CTX_ctrl(3)>,
 L<SSL_CTX_flush_sessions(3)>,
-L<SSL_CTX_get_ex_new_index(3)>,
 L<SSL_CTX_get_verify_mode(3)>,
 L<SSL_CTX_load_verify_locations(3)>
 L<SSL_CTX_new(3)>,
@@ -724,7 +724,6 @@ L<SSL_get_client_CA_list(3)>,
 L<SSL_get_default_timeout(3)>,
 L<SSL_get_error(3)>,
 L<SSL_get_ex_data_X509_STORE_CTX_idx(3)>,
-L<SSL_get_ex_new_index(3)>,
 L<SSL_get_fd(3)>,
 L<SSL_get_peer_cert_chain(3)>,
 L<SSL_get_rbio(3)>,
@@ -748,7 +747,6 @@ L<SSL_state_string(3)>,
 L<SSL_want(3)>,
 L<SSL_write(3)>,
 L<SSL_SESSION_free(3)>,
-L<SSL_SESSION_get_ex_new_index(3)>,
 L<SSL_SESSION_get_time(3)>,
 L<d2i_SSL_SESSION(3)>,
 L<SSL_CTX_set_psk_client_callback(3)>,
diff --git a/engines/ccgost/Makefile b/engines/ccgost/Makefile
index eec407a..a0904cd 100644
--- a/engines/ccgost/Makefile
+++ b/engines/ccgost/Makefile
@@ -120,18 +120,19 @@ gost89.o: gost89.c gost89.h
 gost_ameth.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 gost_ameth.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 gost_ameth.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
-gost_ameth.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
-gost_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-gost_ameth.o: ../../include/openssl/engine.h ../../include/openssl/err.h
-gost_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
-gost_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
+gost_ameth.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
+gost_ameth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
+gost_ameth.o: ../../include/openssl/ec.h ../../include/openssl/engine.h
+gost_ameth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+gost_ameth.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+gost_ameth.o: ../../include/openssl/objects.h
 gost_ameth.o: ../../include/openssl/opensslconf.h
 gost_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 gost_ameth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
 gost_ameth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
 gost_ameth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
-gost_ameth.o: ../../include/openssl/x509_vfy.h e_gost_err.h gost89.h
-gost_ameth.o: gost_ameth.c gost_lcl.h gosthash.h
+gost_ameth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
+gost_ameth.o: e_gost_err.h gost89.h gost_ameth.c gost_lcl.h gosthash.h
 gost_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
 gost_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
 gost_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h
index a5e5b17..dccb4ff 100644
--- a/include/openssl/crypto.h
+++ b/include/openssl/crypto.h
@@ -222,34 +222,21 @@ extern "C" {
  * Some applications as well as some parts of OpenSSL need to allocate and
  * deallocate locks in a dynamic fashion.  The following typedef makes this
  * possible in a type-safe manner.
+ * struct CRYPTO_dynlock_value has to be defined by the application.
  */
-/* struct CRYPTO_dynlock_value has to be defined by the application. */
 typedef struct {
     int references;
     struct CRYPTO_dynlock_value *data;
 } CRYPTO_dynlock;
 
 /*
- * The following can be used to detect memory leaks in the OpenSSL library. It
+ * The following can be used to detect memory leaks in the library. If
  * used, it turns on malloc checking
  */
-
-# define CRYPTO_MEM_CHECK_OFF    0x0/* an enume */
-# define CRYPTO_MEM_CHECK_ON     0x1/* a bit */
-# define CRYPTO_MEM_CHECK_ENABLE 0x2/* a bit */
-# define CRYPTO_MEM_CHECK_DISABLE 0x3/* an enume */
-
-/*
- * The following are bit values to turn on or off options connected to the
- * malloc checking functionality
- */
-
-/* Adds time to the memory checking information */
-# define V_CRYPTO_MDEBUG_TIME    0x1/* a bit */
-/* Adds thread number to the memory checking information */
-# define V_CRYPTO_MDEBUG_THREAD  0x2/* a bit */
-
-# define V_CRYPTO_MDEBUG_ALL (V_CRYPTO_MDEBUG_TIME | V_CRYPTO_MDEBUG_THREAD)
+# define CRYPTO_MEM_CHECK_OFF     0x0
+# define CRYPTO_MEM_CHECK_ON      0x1
+# define CRYPTO_MEM_CHECK_ENABLE  0x2
+# define CRYPTO_MEM_CHECK_DISABLE 0x3
 
 /* predec of the BIO type */
 typedef struct bio_st BIO_dummy;
@@ -285,51 +272,69 @@ DEFINE_STACK_OF(void)
  * needed in Win32 where the application malloc and the library malloc may
  * not be the same.
  */
-# define CRYPTO_malloc_init()    CRYPTO_set_mem_functions(\
-        malloc, realloc, free)
-
-# if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
-#  ifndef CRYPTO_MDEBUG         /* avoid duplicate #define */
-#   define CRYPTO_MDEBUG
-#  endif
-# endif
+#define OPENSSL_malloc_init() \
+    CRYPTO_set_mem_functions(CRYPTO_malloc, CRYPTO_realloc, CRYPTO_free)
 
 /*
  * Set standard debugging functions (not done by default unless CRYPTO_MDEBUG
  * is defined)
  */
-# define CRYPTO_malloc_debug_init()      do {\
-        CRYPTO_set_mem_debug_functions(\
-                CRYPTO_dbg_malloc,\
-                CRYPTO_dbg_realloc,\
-                CRYPTO_dbg_free,\
-                CRYPTO_dbg_set_options,\
-                CRYPTO_dbg_get_options);\
-        } while(0)
+# if defined CRYPTO_MDEBUG_ABORT
+#  ifndef CRYPTO_MDEBUG
+#   define CRYPTO_MDEBUG
+#  endif
+# endif
 
 int CRYPTO_mem_ctrl(int mode);
-int CRYPTO_is_mem_check_on(void);
-
-/* for applications */
-# define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
-# define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
-
-/* for library-internal use */
-# define MemCheck_on()   CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
-# define MemCheck_off()  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
-# define is_MemCheck_on() CRYPTO_is_mem_check_on()
-
-# define OPENSSL_malloc(num)     CRYPTO_malloc((int)num, __FILE__, __LINE__)
-# define OPENSSL_zalloc(num)     CRYPTO_zalloc((int)num, __FILE__, __LINE__)
-# define OPENSSL_memdup(str, s)  CRYPTO_memdup((str), s, __FILE__, __LINE__)
-# define OPENSSL_strdup(str)     CRYPTO_strdup((str), __FILE__, __LINE__)
-# define OPENSSL_strndup(str, s) CRYPTO_strndup((str), (s), __FILE__, __LINE__)
-# define OPENSSL_realloc(addr,num) \
-        CRYPTO_realloc((char *)addr, (int)num, __FILE__, __LINE__)
-# define OPENSSL_clear_realloc(addr, old_num, num) \
+
+# ifdef CRYPTO_MDEBUG
+#  define OPENSSL_malloc(num) \
+        CRYPTO_malloc(num, __FILE__, __LINE__)
+#  define OPENSSL_zalloc(num) \
+        CRYPTO_zalloc(num, __FILE__, __LINE__)
+#  define OPENSSL_realloc(addr, num) \
+        CRYPTO_realloc(addr, num, __FILE__, __LINE__)
+#  define OPENSSL_clear_realloc(addr, old_num, num) \
         CRYPTO_clear_realloc(addr, old_num, num, __FILE__, __LINE__)
-# define OPENSSL_clear_free(addr, num) CRYPTO_clear_free(addr, num)
-# define OPENSSL_free(addr)      CRYPTO_free(addr)
+#  define OPENSSL_clear_free(addr, num) \
+        CRYPTO_clear_free(addr, num)
+#  define OPENSSL_free(addr) \
+        CRYPTO_free(addr)
+#  define OPENSSL_memdup(str, s) \
+        CRYPTO_memdup((str), s, __FILE__, __LINE__)
+#  define OPENSSL_strdup(str) \
+        CRYPTO_strdup(str, __FILE__, __LINE__)
+#  define OPENSSL_strndup(str, n) \
+        CRYPTO_strndup(str, n, __FILE__, __LINE__)
+#  define OPENSSL_secure_malloc(num) \
+        CRYPTO_secure_malloc(num, __FILE__, __LINE__)
+#  define OPENSSL_secure_free(addr) \
+        CRYPTO_secure_free(addr)
+# else
+#  define OPENSSL_malloc(num) \
+        CRYPTO_malloc(num, NULL, 0)
+#  define OPENSSL_zalloc(num) \
+        CRYPTO_zalloc(num, NULL, 0)
+#  define OPENSSL_realloc(addr, num) \
+        CRYPTO_realloc(addr, num, NULL, 0)
+#  define OPENSSL_clear_realloc(addr, old_num, num) \
+        CRYPTO_clear_realloc(addr, old_num, num, NULL, 0)
+#  define OPENSSL_clear_free(addr, num) \
+        CRYPTO_clear_free(addr, num)
+#  define OPENSSL_free(addr) \
+        CRYPTO_free(addr)
+#  define OPENSSL_memdup(str) \
+        CRYPTO_memdup(str, NULL, 0)
+#  define OPENSSL_strdup(str) \
+        CRYPTO_strdup(str, NULL, 0)
+#  define OPENSSL_strndup(str, s) \
+        CRYPTO_strndup(str, s, NULL, 0)
+#  define OPENSSL_secure_malloc(num) \
+        CRYPTO_secure_malloc(num, NULL, 0)
+#  define OPENSSL_secure_free(addr) \
+        CRYPTO_secure_free(addr)
+
+# endif
 
 size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz);
 size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz);
@@ -447,29 +452,15 @@ void (*CRYPTO_get_dynlock_destroy_callback(void)) (struct CRYPTO_dynlock_value
                                                    *l, const char *file,
                                                    int line);
 
-int CRYPTO_set_mem_functions(void *(*m) (size_t), void *(*r) (void *, size_t),
-                             void (*f) (void *));
-int CRYPTO_set_mem_ex_functions(void *(*m) (size_t, const char *, int),
-                                void *(*r) (void *, size_t, const char *,
-                                            int), void (*f) (void *));
-int CRYPTO_set_mem_debug_functions(void (*m) (void *, size_t,
-                                              const char *, int, int),
-                                   void (*r) (void *, void *, size_t,
-                                              const char *, int, int),
-                                   void (*f) (void *, int), void (*so) (long),
-                                   long (*go) (void));
-void CRYPTO_get_mem_functions(void *(**m) (size_t),
-                              void *(**r) (void *, size_t),
-                              void (**f) (void *));
-void CRYPTO_get_mem_ex_functions(void *(**m) (size_t, const char *, int),
-                                 void *(**r) (void *, size_t, const char *,
-                                              int), void (**f) (void *));
-void CRYPTO_get_mem_debug_functions(void (**m) (void *, size_t,
-                                                const char *, int, int),
-                                    void (**r) (void *, void *, size_t,
-                                                const char *, int, int),
-                                    void (**f) (void *, int),
-                                    void (**so) (long), long (**go) (void));
+int CRYPTO_set_mem_functions(
+        void *(*m) (size_t, const char *, int),
+        void *(*r) (void *, size_t, const char *, int),
+        void (*f) (void *));
+int CRYPTO_set_mem_debug(int flag);
+void CRYPTO_get_mem_functions(
+        void *(**m) (size_t, const char *, int),
+        void *(**r) (void *, size_t, const char *, int),
+        void (**f) (void *));
 
 void *CRYPTO_malloc(size_t num, const char *file, int line);
 void *CRYPTO_zalloc(size_t num, const char *file, int line);
@@ -482,30 +473,16 @@ void *CRYPTO_realloc(void *addr, size_t num, const char *file, int line);
 void *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num,
                            const char *file, int line);
 
-# define OPENSSL_secure_malloc(num) \
-        CRYPTO_secure_malloc((int)num,__FILE__,__LINE__)
-# define OPENSSL_secure_free(addr) \
-        CRYPTO_secure_free(addr)
-
 int CRYPTO_secure_malloc_init(size_t sz, int minsize);
 void CRYPTO_secure_malloc_done(void);
 void *CRYPTO_secure_malloc(size_t num, const char *file, int line);
 void CRYPTO_secure_free(void *ptr);
 int CRYPTO_secure_allocated(const void *ptr);
 int CRYPTO_secure_malloc_initialized(void);
-
-int CRYPTO_set_secure_mem_functions(void *(*m)(size_t), void (*f)(void *));
-int CRYPTO_set_secure_mem_ex_functions(void *(*m)(size_t,const char *,int),
-                                       void (*f)(void *));
-void CRYPTO_get_secure_mem_functions(void *(**m)(size_t), void (**f)(void *));
-void CRYPTO_get_secure_mem_ex_functions(void *(**m)(size_t,const char *,int),
-                                        void (**f)(void *));
+size_t CRYPTO_secure_used(void);
 
 void OPENSSL_cleanse(void *ptr, size_t len);
 
-void CRYPTO_set_mem_debug_options(long bits);
-long CRYPTO_get_mem_debug_options(void);
-
 # define OPENSSL_mem_debug_push(info) \
         CRYPTO_mem_debug_push(info, __FILE__, __LINE__)
 # define OPENSSL_mem_debug_pop() \
@@ -513,41 +490,22 @@ long CRYPTO_get_mem_debug_options(void);
 int CRYPTO_mem_debug_push(const char *info, const char *file, int line);
 int CRYPTO_mem_debug_pop(void);
 
-/*
- * Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro;
- * used as default in CRYPTO_MDEBUG compilations):
- */
 /*-
- * The last argument has the following significance:
- *
- * 0:   called before the actual memory allocation has taken place
- * 1:   called after the actual memory allocation has taken place
- */
-void CRYPTO_dbg_malloc(void *addr, size_t num, const char *file, int line,
-                       int before_p);
-void CRYPTO_dbg_realloc(void *addr1, void *addr2, size_t num, const char *file,
-                        int line, int before_p);
-void CRYPTO_dbg_free(void *addr, int before_p);
-/*-
- * Tell the debugging code about options.  By default, the following values
- * apply:
- *
- * 0:                           Clear all options.
- * V_CRYPTO_MDEBUG_TIME (1):    Set the "Show Time" option.
- * V_CRYPTO_MDEBUG_THREAD (2):  Set the "Show Thread Number" option.
- * V_CRYPTO_MDEBUG_ALL (3):     1 + 2
+ * Debugging functions (enabled by CRYPTO_set_mem_debug_functions(1))
+ * The flag argument has the following significance:
+ *   0:   called before the actual memory allocation has taken place
+ *   1:   called after the actual memory allocation has taken place
  */
-void CRYPTO_dbg_set_options(long bits);
-long CRYPTO_dbg_get_options(void);
+void CRYPTO_mem_debug_malloc(void *addr, size_t num, int flag,
+        const char *file, int line);
+void CRYPTO_mem_debug_realloc(void *addr1, void *addr2, size_t num, int flag,
+        const char *file, int line);
+void CRYPTO_mem_debug_free(void *addr, int flag);
 
 # ifndef OPENSSL_NO_STDIO
 void CRYPTO_mem_leaks_fp(FILE *);
 # endif
 void CRYPTO_mem_leaks(struct bio_st *bio);
-/* unsigned long order, char *file, int line, size_t num_bytes, char *addr */
-typedef void *CRYPTO_MEM_LEAK_CB (unsigned long, const char *, int, size_t,
-                                  void *);
-void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb);
 
 /* die if we have to */
 void OpenSSLDie(const char *file, int line, const char *assertion);
@@ -601,6 +559,7 @@ void ERR_load_CRYPTO_strings(void);
 # define CRYPTO_F_INT_DUP_EX_DATA                         106
 # define CRYPTO_F_INT_FREE_EX_DATA                        107
 # define CRYPTO_F_INT_NEW_EX_DATA                         108
+# define CRYPTO_F_OPENSSL_MEMDUP                          114
 
 /* Reason codes. */
 # define CRYPTO_R_FIPS_MODE_NOT_SUPPORTED                 101
diff --git a/include/openssl/engine.h b/include/openssl/engine.h
index ddc7e0f..34d7fed 100644
--- a/include/openssl/engine.h
+++ b/include/openssl/engine.h
@@ -733,14 +733,6 @@ void ENGINE_add_conf_module(void);
  * same static data as the calling application (or library), and thus whether
  * these callbacks need to be set or not.
  */
-typedef void *(*dyn_MEM_malloc_cb) (size_t);
-typedef void *(*dyn_MEM_realloc_cb) (void *, size_t);
-typedef void (*dyn_MEM_free_cb) (void *);
-typedef struct st_dynamic_MEM_fns {
-    dyn_MEM_malloc_cb malloc_cb;
-    dyn_MEM_realloc_cb realloc_cb;
-    dyn_MEM_free_cb free_cb;
-} dynamic_MEM_fns;
 /*
  * FIXME: Perhaps the memory and locking code (crypto.h) should declare and
  * use these types so we (and any other dependant code) can simplify a bit??
@@ -763,7 +755,6 @@ typedef struct st_dynamic_LOCK_fns {
 /* The top-level structure */
 typedef struct st_dynamic_fns {
     void *static_state;
-    dynamic_MEM_fns mem_fns;
     dynamic_LOCK_fns lock_fns;
 } dynamic_fns;
 
@@ -812,9 +803,6 @@ typedef int (*dynamic_bind_engine) (ENGINE *e, const char *id,
         OPENSSL_EXPORT \
         int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
                 if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \
-                if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
-                        fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
-                        return 0; \
                 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
                 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
                 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
diff --git a/ssl/Makefile b/ssl/Makefile
index f398c9a..bb61875 100644
--- a/ssl/Makefile
+++ b/ssl/Makefile
@@ -98,7 +98,8 @@ clean:
 	
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-bio_ssl.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+bio_ssl.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+bio_ssl.o: ../include/openssl/asn1.h ../include/openssl/async.h
 bio_ssl.o: ../include/openssl/bio.h ../include/openssl/bn.h
 bio_ssl.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 bio_ssl.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -117,7 +118,8 @@ bio_ssl.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 bio_ssl.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 bio_ssl.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h bio_ssl.c
 bio_ssl.o: packet_locl.h record/record.h ssl_locl.h statem/statem.h
-d1_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+d1_lib.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+d1_lib.o: ../include/openssl/asn1.h ../include/openssl/async.h
 d1_lib.o: ../include/openssl/bio.h ../include/openssl/bn.h
 d1_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 d1_lib.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -137,7 +139,8 @@ d1_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 d1_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 d1_lib.o: ../include/openssl/x509_vfy.h d1_lib.c packet_locl.h record/record.h
 d1_lib.o: ssl_locl.h statem/statem.h
-d1_msg.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+d1_msg.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+d1_msg.o: ../include/openssl/asn1.h ../include/openssl/async.h
 d1_msg.o: ../include/openssl/bio.h ../include/openssl/bn.h
 d1_msg.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 d1_msg.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -156,7 +159,8 @@ d1_msg.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 d1_msg.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 d1_msg.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h d1_msg.c
 d1_msg.o: packet_locl.h record/record.h ssl_locl.h statem/statem.h
-d1_srtp.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+d1_srtp.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+d1_srtp.o: ../include/openssl/asn1.h ../include/openssl/async.h
 d1_srtp.o: ../include/openssl/bio.h ../include/openssl/bn.h
 d1_srtp.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 d1_srtp.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -175,7 +179,8 @@ d1_srtp.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 d1_srtp.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 d1_srtp.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h d1_srtp.c
 d1_srtp.o: packet_locl.h record/record.h ssl_locl.h statem/statem.h
-methods.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+methods.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+methods.o: ../include/openssl/asn1.h ../include/openssl/async.h
 methods.o: ../include/openssl/bio.h ../include/openssl/bn.h
 methods.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 methods.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -194,7 +199,8 @@ methods.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 methods.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 methods.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h methods.c
 methods.o: packet_locl.h record/record.h ssl_locl.h statem/statem.h
-record/dtls1_bitmap.o: ../e_os.h ../include/openssl/asn1.h
+record/dtls1_bitmap.o: ../e_os.h ../include/internal/dane.h
+record/dtls1_bitmap.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 record/dtls1_bitmap.o: ../include/openssl/async.h ../include/openssl/bio.h
 record/dtls1_bitmap.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 record/dtls1_bitmap.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -218,7 +224,8 @@ record/dtls1_bitmap.o: ../include/openssl/x509_vfy.h record/../packet_locl.h
 record/dtls1_bitmap.o: record/../record/record.h record/../ssl_locl.h
 record/dtls1_bitmap.o: record/../statem/statem.h record/dtls1_bitmap.c
 record/dtls1_bitmap.o: record/record_locl.h
-record/rec_layer_d1.o: ../e_os.h ../include/openssl/asn1.h
+record/rec_layer_d1.o: ../e_os.h ../include/internal/dane.h
+record/rec_layer_d1.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 record/rec_layer_d1.o: ../include/openssl/async.h ../include/openssl/bio.h
 record/rec_layer_d1.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 record/rec_layer_d1.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -242,7 +249,8 @@ record/rec_layer_d1.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 record/rec_layer_d1.o: record/../packet_locl.h record/../record/record.h
 record/rec_layer_d1.o: record/../ssl_locl.h record/../statem/statem.h
 record/rec_layer_d1.o: record/rec_layer_d1.c record/record_locl.h
-record/rec_layer_s3.o: ../e_os.h ../include/openssl/asn1.h
+record/rec_layer_s3.o: ../e_os.h ../include/internal/dane.h
+record/rec_layer_s3.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 record/rec_layer_s3.o: ../include/openssl/async.h ../include/openssl/bio.h
 record/rec_layer_s3.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 record/rec_layer_s3.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -266,7 +274,8 @@ record/rec_layer_s3.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 record/rec_layer_s3.o: record/../packet_locl.h record/../record/record.h
 record/rec_layer_s3.o: record/../ssl_locl.h record/../statem/statem.h
 record/rec_layer_s3.o: record/rec_layer_s3.c record/record_locl.h
-record/ssl3_buffer.o: ../e_os.h ../include/openssl/asn1.h
+record/ssl3_buffer.o: ../e_os.h ../include/internal/dane.h
+record/ssl3_buffer.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 record/ssl3_buffer.o: ../include/openssl/async.h ../include/openssl/bio.h
 record/ssl3_buffer.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 record/ssl3_buffer.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -290,6 +299,7 @@ record/ssl3_buffer.o: record/../record/record.h record/../ssl_locl.h
 record/ssl3_buffer.o: record/../statem/statem.h record/record_locl.h
 record/ssl3_buffer.o: record/ssl3_buffer.c
 record/ssl3_record.o: ../e_os.h ../include/internal/constant_time_locl.h
+record/ssl3_record.o: ../include/internal/dane.h ../include/internal/numbers.h
 record/ssl3_record.o: ../include/openssl/asn1.h ../include/openssl/async.h
 record/ssl3_record.o: ../include/openssl/bio.h ../include/openssl/bn.h
 record/ssl3_record.o: ../include/openssl/buffer.h ../include/openssl/comp.h
@@ -314,6 +324,7 @@ record/ssl3_record.o: record/../packet_locl.h record/../record/record.h
 record/ssl3_record.o: record/../ssl_locl.h record/../statem/statem.h
 record/ssl3_record.o: record/record_locl.h record/ssl3_record.c
 s3_cbc.o: ../e_os.h ../include/internal/constant_time_locl.h
+s3_cbc.o: ../include/internal/dane.h ../include/internal/numbers.h
 s3_cbc.o: ../include/openssl/asn1.h ../include/openssl/async.h
 s3_cbc.o: ../include/openssl/bio.h ../include/openssl/bn.h
 s3_cbc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
@@ -334,7 +345,8 @@ s3_cbc.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 s3_cbc.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 s3_cbc.o: ../include/openssl/x509_vfy.h packet_locl.h record/record.h s3_cbc.c
 s3_cbc.o: ssl_locl.h statem/statem.h
-s3_enc.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+s3_enc.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+s3_enc.o: ../include/openssl/asn1.h ../include/openssl/async.h
 s3_enc.o: ../include/openssl/bio.h ../include/openssl/bn.h
 s3_enc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 s3_enc.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -354,7 +366,8 @@ s3_enc.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 s3_enc.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 s3_enc.o: ../include/openssl/x509_vfy.h packet_locl.h record/record.h s3_enc.c
 s3_enc.o: ssl_locl.h statem/statem.h
-s3_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+s3_lib.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+s3_lib.o: ../include/openssl/asn1.h ../include/openssl/async.h
 s3_lib.o: ../include/openssl/bio.h ../include/openssl/bn.h
 s3_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 s3_lib.o: ../include/openssl/crypto.h ../include/openssl/dh.h
@@ -375,7 +388,8 @@ s3_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 s3_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 s3_lib.o: ../include/openssl/x509_vfy.h packet_locl.h record/record.h s3_lib.c
 s3_lib.o: ssl_locl.h statem/statem.h
-s3_msg.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+s3_msg.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+s3_msg.o: ../include/openssl/asn1.h ../include/openssl/async.h
 s3_msg.o: ../include/openssl/bio.h ../include/openssl/bn.h
 s3_msg.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 s3_msg.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -394,7 +408,8 @@ s3_msg.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 s3_msg.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 s3_msg.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h packet_locl.h
 s3_msg.o: record/record.h s3_msg.c ssl_locl.h statem/statem.h
-ssl_algs.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_algs.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_algs.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_algs.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_algs.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_algs.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -413,7 +428,8 @@ ssl_algs.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 ssl_algs.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 ssl_algs.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 ssl_algs.o: packet_locl.h record/record.h ssl_algs.c ssl_locl.h statem/statem.h
-ssl_asn1.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/asn1t.h
+ssl_asn1.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_asn1.o: ../include/openssl/asn1.h ../include/openssl/asn1t.h
 ssl_asn1.o: ../include/openssl/async.h ../include/openssl/bio.h
 ssl_asn1.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 ssl_asn1.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -433,7 +449,8 @@ ssl_asn1.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 ssl_asn1.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 ssl_asn1.o: ../include/openssl/x509_vfy.h packet_locl.h record/record.h
 ssl_asn1.o: ssl_asn1.c ssl_locl.h statem/statem.h
-ssl_cert.o: ../e_os.h ../include/internal/o_dir.h ../include/openssl/asn1.h
+ssl_cert.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_cert.o: ../include/internal/o_dir.h ../include/openssl/asn1.h
 ssl_cert.o: ../include/openssl/async.h ../include/openssl/bio.h
 ssl_cert.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 ssl_cert.o: ../include/openssl/comp.h ../include/openssl/conf.h
@@ -454,7 +471,8 @@ ssl_cert.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 ssl_cert.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 ssl_cert.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h
 ssl_cert.o: packet_locl.h record/record.h ssl_cert.c ssl_locl.h statem/statem.h
-ssl_ciph.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_ciph.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_ciph.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_ciph.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_ciph.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_ciph.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -474,7 +492,8 @@ ssl_ciph.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 ssl_ciph.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 ssl_ciph.o: ../include/openssl/x509_vfy.h packet_locl.h record/record.h
 ssl_ciph.o: ssl_ciph.c ssl_locl.h statem/statem.h
-ssl_conf.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_conf.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_conf.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_conf.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_conf.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_conf.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -526,7 +545,8 @@ ssl_err2.o: ../include/openssl/ssl2.h ../include/openssl/ssl3.h
 ssl_err2.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 ssl_err2.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 ssl_err2.o: ../include/openssl/x509_vfy.h ssl_err2.c
-ssl_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_lib.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_lib.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_lib.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_lib.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -548,7 +568,8 @@ ssl_lib.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 ssl_lib.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 ssl_lib.o: ../include/openssl/x509_vfy.h ../include/openssl/x509v3.h
 ssl_lib.o: packet_locl.h record/record.h ssl_lib.c ssl_locl.h statem/statem.h
-ssl_mcnf.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_mcnf.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_mcnf.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_mcnf.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_mcnf.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_mcnf.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -568,7 +589,8 @@ ssl_mcnf.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
 ssl_mcnf.o: ../include/openssl/tls1.h ../include/openssl/x509.h
 ssl_mcnf.o: ../include/openssl/x509_vfy.h packet_locl.h record/record.h
 ssl_mcnf.o: ssl_locl.h ssl_mcnf.c statem/statem.h
-ssl_rsa.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_rsa.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_rsa.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_rsa.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_rsa.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_rsa.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -587,7 +609,8 @@ ssl_rsa.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 ssl_rsa.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 ssl_rsa.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 ssl_rsa.o: packet_locl.h record/record.h ssl_locl.h ssl_rsa.c statem/statem.h
-ssl_sess.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_sess.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_sess.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_sess.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_sess.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_sess.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -607,7 +630,8 @@ ssl_sess.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 ssl_sess.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 ssl_sess.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 ssl_sess.o: packet_locl.h record/record.h ssl_locl.h ssl_sess.c statem/statem.h
-ssl_stat.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_stat.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_stat.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_stat.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_stat.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_stat.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -626,7 +650,8 @@ ssl_stat.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 ssl_stat.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 ssl_stat.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 ssl_stat.o: packet_locl.h record/record.h ssl_locl.h ssl_stat.c statem/statem.h
-ssl_txt.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_txt.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_txt.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_txt.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_txt.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_txt.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -645,7 +670,8 @@ ssl_txt.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 ssl_txt.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 ssl_txt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 ssl_txt.o: packet_locl.h record/record.h ssl_locl.h ssl_txt.c statem/statem.h
-ssl_utst.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssl_utst.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssl_utst.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssl_utst.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssl_utst.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssl_utst.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -664,28 +690,31 @@ ssl_utst.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 ssl_utst.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 ssl_utst.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 ssl_utst.o: packet_locl.h record/record.h ssl_locl.h ssl_utst.c statem/statem.h
-statem/statem.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
-statem/statem.o: ../include/openssl/bio.h ../include/openssl/bn.h
-statem/statem.o: ../include/openssl/buffer.h ../include/openssl/comp.h
-statem/statem.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
-statem/statem.o: ../include/openssl/dtls1.h ../include/openssl/e_os2.h
-statem/statem.o: ../include/openssl/ec.h ../include/openssl/err.h
-statem/statem.o: ../include/openssl/evp.h ../include/openssl/hmac.h
-statem/statem.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-statem/statem.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
-statem/statem.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
-statem/statem.o: ../include/openssl/pem.h ../include/openssl/pem2.h
-statem/statem.o: ../include/openssl/pkcs7.h ../include/openssl/pqueue.h
-statem/statem.o: ../include/openssl/rand.h ../include/openssl/rsa.h
-statem/statem.o: ../include/openssl/safestack.h ../include/openssl/sha.h
-statem/statem.o: ../include/openssl/srtp.h ../include/openssl/ssl.h
-statem/statem.o: ../include/openssl/ssl2.h ../include/openssl/ssl3.h
-statem/statem.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-statem/statem.o: ../include/openssl/tls1.h ../include/openssl/x509.h
-statem/statem.o: ../include/openssl/x509_vfy.h statem/../packet_locl.h
-statem/statem.o: statem/../record/record.h statem/../ssl_locl.h
-statem/statem.o: statem/../statem/statem.h statem/statem.c statem/statem_locl.h
-statem/statem_clnt.o: ../e_os.h ../include/openssl/asn1.h
+statem/statem.o: ../e_os.h ../include/internal/dane.h
+statem/statem.o: ../include/internal/numbers.h ../include/openssl/asn1.h
+statem/statem.o: ../include/openssl/async.h ../include/openssl/bio.h
+statem/statem.o: ../include/openssl/bn.h ../include/openssl/buffer.h
+statem/statem.o: ../include/openssl/comp.h ../include/openssl/crypto.h
+statem/statem.o: ../include/openssl/dsa.h ../include/openssl/dtls1.h
+statem/statem.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
+statem/statem.o: ../include/openssl/err.h ../include/openssl/evp.h
+statem/statem.o: ../include/openssl/hmac.h ../include/openssl/lhash.h
+statem/statem.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
+statem/statem.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
+statem/statem.o: ../include/openssl/ossl_typ.h ../include/openssl/pem.h
+statem/statem.o: ../include/openssl/pem2.h ../include/openssl/pkcs7.h
+statem/statem.o: ../include/openssl/pqueue.h ../include/openssl/rand.h
+statem/statem.o: ../include/openssl/rsa.h ../include/openssl/safestack.h
+statem/statem.o: ../include/openssl/sha.h ../include/openssl/srtp.h
+statem/statem.o: ../include/openssl/ssl.h ../include/openssl/ssl2.h
+statem/statem.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
+statem/statem.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
+statem/statem.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
+statem/statem.o: statem/../packet_locl.h statem/../record/record.h
+statem/statem.o: statem/../ssl_locl.h statem/../statem/statem.h statem/statem.c
+statem/statem.o: statem/statem_locl.h
+statem/statem_clnt.o: ../e_os.h ../include/internal/dane.h
+statem/statem_clnt.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 statem/statem_clnt.o: ../include/openssl/async.h ../include/openssl/bio.h
 statem/statem_clnt.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 statem/statem_clnt.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -710,7 +739,8 @@ statem/statem_clnt.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 statem/statem_clnt.o: statem/../packet_locl.h statem/../record/record.h
 statem/statem_clnt.o: statem/../ssl_locl.h statem/../statem/statem.h
 statem/statem_clnt.o: statem/statem_clnt.c statem/statem_locl.h
-statem/statem_dtls.o: ../e_os.h ../include/openssl/asn1.h
+statem/statem_dtls.o: ../e_os.h ../include/internal/dane.h
+statem/statem_dtls.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 statem/statem_dtls.o: ../include/openssl/async.h ../include/openssl/bio.h
 statem/statem_dtls.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 statem/statem_dtls.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -733,7 +763,8 @@ statem/statem_dtls.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 statem/statem_dtls.o: statem/../packet_locl.h statem/../record/record.h
 statem/statem_dtls.o: statem/../ssl_locl.h statem/../statem/statem.h
 statem/statem_dtls.o: statem/statem_dtls.c statem/statem_locl.h
-statem/statem_lib.o: ../e_os.h ../include/openssl/asn1.h
+statem/statem_lib.o: ../e_os.h ../include/internal/dane.h
+statem/statem_lib.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 statem/statem_lib.o: ../include/openssl/async.h ../include/openssl/bio.h
 statem/statem_lib.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 statem/statem_lib.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -757,6 +788,7 @@ statem/statem_lib.o: statem/../packet_locl.h statem/../record/record.h
 statem/statem_lib.o: statem/../ssl_locl.h statem/../statem/statem.h
 statem/statem_lib.o: statem/statem_lib.c statem/statem_locl.h
 statem/statem_srvr.o: ../e_os.h ../include/internal/constant_time_locl.h
+statem/statem_srvr.o: ../include/internal/dane.h ../include/internal/numbers.h
 statem/statem_srvr.o: ../include/openssl/asn1.h ../include/openssl/async.h
 statem/statem_srvr.o: ../include/openssl/bio.h ../include/openssl/bn.h
 statem/statem_srvr.o: ../include/openssl/buffer.h ../include/openssl/comp.h
@@ -781,7 +813,8 @@ statem/statem_srvr.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 statem/statem_srvr.o: statem/../packet_locl.h statem/../record/record.h
 statem/statem_srvr.o: statem/../ssl_locl.h statem/../statem/statem.h
 statem/statem_srvr.o: statem/statem_locl.h statem/statem_srvr.c
-t1_enc.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+t1_enc.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+t1_enc.o: ../include/openssl/asn1.h ../include/openssl/async.h
 t1_enc.o: ../include/openssl/bio.h ../include/openssl/bn.h
 t1_enc.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 t1_enc.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -801,7 +834,8 @@ t1_enc.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 t1_enc.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 t1_enc.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h packet_locl.h
 t1_enc.o: record/record.h ssl_locl.h statem/statem.h t1_enc.c
-t1_ext.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+t1_ext.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+t1_ext.o: ../include/openssl/asn1.h ../include/openssl/async.h
 t1_ext.o: ../include/openssl/bio.h ../include/openssl/bn.h
 t1_ext.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 t1_ext.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -820,7 +854,8 @@ t1_ext.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 t1_ext.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 t1_ext.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h packet_locl.h
 t1_ext.o: record/record.h ssl_locl.h statem/statem.h t1_ext.c
-t1_lib.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+t1_lib.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+t1_lib.o: ../include/openssl/asn1.h ../include/openssl/async.h
 t1_lib.o: ../include/openssl/bio.h ../include/openssl/bn.h
 t1_lib.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 t1_lib.o: ../include/openssl/conf.h ../include/openssl/crypto.h
@@ -842,7 +877,8 @@ t1_lib.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 t1_lib.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 t1_lib.o: ../include/openssl/x509v3.h packet_locl.h record/record.h ssl_locl.h
 t1_lib.o: statem/statem.h t1_lib.c
-t1_reneg.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+t1_reneg.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+t1_reneg.o: ../include/openssl/asn1.h ../include/openssl/async.h
 t1_reneg.o: ../include/openssl/bio.h ../include/openssl/bn.h
 t1_reneg.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 t1_reneg.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -861,7 +897,8 @@ t1_reneg.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 t1_reneg.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 t1_reneg.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 t1_reneg.o: packet_locl.h record/record.h ssl_locl.h statem/statem.h t1_reneg.c
-t1_trce.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+t1_trce.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+t1_trce.o: ../include/openssl/asn1.h ../include/openssl/async.h
 t1_trce.o: ../include/openssl/bio.h ../include/openssl/bn.h
 t1_trce.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 t1_trce.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
@@ -880,7 +917,8 @@ t1_trce.o: ../include/openssl/ssl3.h ../include/openssl/stack.h
 t1_trce.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
 t1_trce.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
 t1_trce.o: packet_locl.h record/record.h ssl_locl.h statem/statem.h t1_trce.c
-tls_srp.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+tls_srp.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+tls_srp.o: ../include/openssl/asn1.h ../include/openssl/async.h
 tls_srp.o: ../include/openssl/bio.h ../include/openssl/bn.h
 tls_srp.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 tls_srp.o: ../include/openssl/crypto.h ../include/openssl/dsa.h
diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c
index a15248d..44d0e7f 100644
--- a/ssl/ssl_ciph.c
+++ b/ssl/ssl_ciph.c
@@ -567,7 +567,7 @@ static void load_builtin_compressions(void)
             SSL_COMP *comp = NULL;
             COMP_METHOD *method = COMP_zlib();
 
-            MemCheck_off();
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
             ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp);
             if (COMP_get_type(method) != NID_undef
                 && ssl_comp_methods != NULL) {
@@ -580,7 +580,7 @@ static void load_builtin_compressions(void)
                     sk_SSL_COMP_sort(ssl_comp_methods);
                 }
             }
-            MemCheck_on();
+            CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         }
     }
 
@@ -1902,10 +1902,10 @@ int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
         return 0;
     }
 
-    MemCheck_off();
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
     comp = OPENSSL_malloc(sizeof(*comp));
     if (comp == NULL) {
-        MemCheck_on();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD, ERR_R_MALLOC_FAILURE);
         return (1);
     }
@@ -1915,20 +1915,20 @@ int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
     load_builtin_compressions();
     if (ssl_comp_methods && sk_SSL_COMP_find(ssl_comp_methods, comp) >= 0) {
         OPENSSL_free(comp);
-        MemCheck_on();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,
                SSL_R_DUPLICATE_COMPRESSION_ID);
         return (1);
-    } else if ((ssl_comp_methods == NULL)
+    }
+    if ((ssl_comp_methods == NULL)
                || !sk_SSL_COMP_push(ssl_comp_methods, comp)) {
         OPENSSL_free(comp);
-        MemCheck_on();
+        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
         SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD, ERR_R_MALLOC_FAILURE);
         return (1);
-    } else {
-        MemCheck_on();
-        return (0);
     }
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+    return (0);
 }
 #endif
 
diff --git a/ssl/ssl_err.c b/ssl/ssl_err.c
index cfa4179..fe47fa6 100644
--- a/ssl/ssl_err.c
+++ b/ssl/ssl_err.c
@@ -86,8 +86,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
     {ERR_FUNC(SSL_F_DTLS1_ENC), "DTLS1_ENC"},
     {ERR_FUNC(SSL_F_DTLS1_GET_HELLO_VERIFY), "DTLS1_GET_HELLO_VERIFY"},
     {ERR_FUNC(SSL_F_DTLS1_GET_MESSAGE), "dtls1_get_message"},
-    {ERR_FUNC(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT),
-     "DTLS1_GET_MESSAGE_FRAGMENT"},
+    {ERR_FUNC(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT), "DTLS1_GET_MESSAGE_FRAGMENT"},
     {ERR_FUNC(SSL_F_DTLS1_GET_RECORD), "dtls1_get_record"},
     {ERR_FUNC(SSL_F_DTLS1_HANDLE_TIMEOUT), "dtls1_handle_timeout"},
     {ERR_FUNC(SSL_F_DTLS1_HEARTBEAT), "dtls1_heartbeat"},
@@ -115,8 +114,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
     {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_HELLO), "dtls1_send_server_hello"},
     {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE),
      "dtls1_send_server_key_exchange"},
-    {ERR_FUNC(SSL_F_DTLS1_WRITE_APP_DATA_BYTES),
-     "dtls1_write_app_data_bytes"},
+    {ERR_FUNC(SSL_F_DTLS1_WRITE_APP_DATA_BYTES), "dtls1_write_app_data_bytes"},
     {ERR_FUNC(SSL_F_DTLS_CONSTRUCT_CHANGE_CIPHER_SPEC),
      "dtls_construct_change_cipher_spec"},
     {ERR_FUNC(SSL_F_DTLS_CONSTRUCT_HELLO_VERIFY_REQUEST),
@@ -137,10 +135,8 @@ static ERR_STRING_DATA SSL_str_functs[] = {
     {ERR_FUNC(SSL_F_SSL3_CONNECT), "ssl3_connect"},
     {ERR_FUNC(SSL_F_SSL3_CTRL), "ssl3_ctrl"},
     {ERR_FUNC(SSL_F_SSL3_CTX_CTRL), "ssl3_ctx_ctrl"},
-    {ERR_FUNC(SSL_F_SSL3_DIGEST_CACHED_RECORDS),
-     "ssl3_digest_cached_records"},
-    {ERR_FUNC(SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC),
-     "ssl3_do_change_cipher_spec"},
+    {ERR_FUNC(SSL_F_SSL3_DIGEST_CACHED_RECORDS), "ssl3_digest_cached_records"},
+    {ERR_FUNC(SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC), "ssl3_do_change_cipher_spec"},
     {ERR_FUNC(SSL_F_SSL3_ENC), "ssl3_enc"},
     {ERR_FUNC(SSL_F_SSL3_FINAL_FINISH_MAC), "ssl3_final_finish_mac"},
     {ERR_FUNC(SSL_F_SSL3_GENERATE_KEY_BLOCK), "ssl3_generate_key_block"},
@@ -198,8 +194,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
     {ERR_FUNC(SSL_F_SSL_ADD_CERT_TO_BUF), "ssl_add_cert_to_buf"},
     {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT),
      "ssl_add_clienthello_renegotiate_ext"},
-    {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT),
-     "ssl_add_clienthello_tlsext"},
+    {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT), "ssl_add_clienthello_tlsext"},
     {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT),
      "ssl_add_clienthello_use_srtp_ext"},
     {ERR_FUNC(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK),
@@ -208,8 +203,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
      "SSL_add_file_cert_subjects_to_stack"},
     {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT),
      "ssl_add_serverhello_renegotiate_ext"},
-    {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_TLSEXT),
-     "ssl_add_serverhello_tlsext"},
+    {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_TLSEXT), "ssl_add_serverhello_tlsext"},
     {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT),
      "ssl_add_serverhello_use_srtp_ext"},
     {ERR_FUNC(SSL_F_SSL_BAD_METHOD), "ssl_bad_method"},
@@ -225,8 +219,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
      "ssl_check_serverhello_tlsext"},
     {ERR_FUNC(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG),
      "ssl_check_srvr_ecc_cert_and_alg"},
-    {ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR),
-     "ssl_cipher_process_rulestr"},
+    {ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR), "ssl_cipher_process_rulestr"},
     {ERR_FUNC(SSL_F_SSL_CIPHER_STRENGTH_SORT), "ssl_cipher_strength_sort"},
     {ERR_FUNC(SSL_F_SSL_CLEAR), "SSL_clear"},
     {ERR_FUNC(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD),
@@ -313,10 +306,8 @@ static ERR_STRING_DATA SSL_str_functs[] = {
     {ERR_FUNC(SSL_F_SSL_SET_PURPOSE), "SSL_set_purpose"},
     {ERR_FUNC(SSL_F_SSL_SET_RFD), "SSL_set_rfd"},
     {ERR_FUNC(SSL_F_SSL_SET_SESSION), "SSL_set_session"},
-    {ERR_FUNC(SSL_F_SSL_SET_SESSION_ID_CONTEXT),
-     "SSL_set_session_id_context"},
-    {ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT),
-     "SSL_set_session_ticket_ext"},
+    {ERR_FUNC(SSL_F_SSL_SET_SESSION_ID_CONTEXT), "SSL_set_session_id_context"},
+    {ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT), "SSL_set_session_ticket_ext"},
     {ERR_FUNC(SSL_F_SSL_SET_TRUST), "SSL_set_trust"},
     {ERR_FUNC(SSL_F_SSL_SET_WFD), "SSL_set_wfd"},
     {ERR_FUNC(SSL_F_SSL_SHUTDOWN), "SSL_shutdown"},
@@ -335,10 +326,8 @@ static ERR_STRING_DATA SSL_str_functs[] = {
     {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_FILE), "SSL_use_PrivateKey_file"},
     {ERR_FUNC(SSL_F_SSL_USE_PSK_IDENTITY_HINT), "SSL_use_psk_identity_hint"},
     {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY), "SSL_use_RSAPrivateKey"},
-    {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1),
-     "SSL_use_RSAPrivateKey_ASN1"},
-    {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE),
-     "SSL_use_RSAPrivateKey_file"},
+    {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1), "SSL_use_RSAPrivateKey_ASN1"},
+    {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE), "SSL_use_RSAPrivateKey_file"},
     {ERR_FUNC(SSL_F_SSL_VERIFY_CERT_CHAIN), "ssl_verify_cert_chain"},
     {ERR_FUNC(SSL_F_SSL_WRITE), "SSL_write"},
     {ERR_FUNC(SSL_F_STATE_MACHINE), "STATE_MACHINE"},
@@ -366,8 +355,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
      "tls_construct_certificate_request"},
     {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CLIENT_CERTIFICATE),
      "tls_construct_client_certificate"},
-    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO),
-     "tls_construct_client_hello"},
+    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO), "tls_construct_client_hello"},
     {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE),
      "tls_construct_client_key_exchange"},
     {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY),
@@ -378,11 +366,9 @@ static ERR_STRING_DATA SSL_str_functs[] = {
     {ERR_FUNC(SSL_F_TLS_CONSTRUCT_SERVER_CERTIFICATE),
      "tls_construct_server_certificate"},
     {ERR_FUNC(SSL_F_TLS_CONSTRUCT_SERVER_DONE), "tls_construct_server_done"},
-    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_SERVER_HELLO),
-     "tls_construct_server_hello"},
+    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_SERVER_HELLO), "tls_construct_server_hello"},
     {ERR_FUNC(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE),
      "tls_construct_server_key_exchange"},
-    {ERR_FUNC(SSL_F_TLS_GET_MESSAGE_BODY), "tls_get_message_body"},
     {ERR_FUNC(SSL_F_TLS_GET_MESSAGE_HEADER), "tls_get_message_header"},
     {ERR_FUNC(SSL_F_TLS_POST_PROCESS_CLIENT_HELLO),
      "tls_post_process_client_hello"},
@@ -410,8 +396,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
      "tls_process_server_certificate"},
     {ERR_FUNC(SSL_F_TLS_PROCESS_SERVER_DONE), "tls_process_server_done"},
     {ERR_FUNC(SSL_F_TLS_PROCESS_SERVER_HELLO), "tls_process_server_hello"},
-    {ERR_FUNC(SSL_F_USE_CERTIFICATE_CHAIN_FILE),
-     "use_certificate_chain_file"},
+    {ERR_FUNC(SSL_F_USE_CERTIFICATE_CHAIN_FILE), "use_certificate_chain_file"},
     {0, NULL}
 };
 
@@ -470,16 +455,14 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
     {ERR_REASON(SSL_R_BAD_VALUE), "bad value"},
     {ERR_REASON(SSL_R_BAD_WRITE_RETRY), "bad write retry"},
     {ERR_REASON(SSL_R_BIO_NOT_SET), "bio not set"},
-    {ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG),
-     "block cipher pad is wrong"},
+    {ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG), "block cipher pad is wrong"},
     {ERR_REASON(SSL_R_BN_LIB), "bn lib"},
     {ERR_REASON(SSL_R_CA_DN_LENGTH_MISMATCH), "ca dn length mismatch"},
     {ERR_REASON(SSL_R_CA_DN_TOO_LONG), "ca dn too long"},
     {ERR_REASON(SSL_R_CA_KEY_TOO_SMALL), "ca key too small"},
     {ERR_REASON(SSL_R_CA_MD_TOO_WEAK), "ca md too weak"},
     {ERR_REASON(SSL_R_CCS_RECEIVED_EARLY), "ccs received early"},
-    {ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED),
-     "certificate verify failed"},
+    {ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED), "certificate verify failed"},
     {ERR_REASON(SSL_R_CERT_CB_ERROR), "cert cb error"},
     {ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH), "cert length mismatch"},
     {ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH), "cipher code wrong length"},
@@ -492,8 +475,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
     {ERR_REASON(SSL_R_COMPRESSION_FAILURE), "compression failure"},
     {ERR_REASON(SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE),
      "compression id not within private range"},
-    {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),
-     "compression library error"},
+    {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR), "compression library error"},
     {ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET), "connection type not set"},
     {ERR_REASON(SSL_R_CONTEXT_NOT_DANE_ENABLED), "context not dane enabled"},
     {ERR_REASON(SSL_R_COOKIE_GEN_CALLBACK_FAILURE),
@@ -540,8 +522,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
     {ERR_REASON(SSL_R_EE_KEY_TOO_SMALL), "ee key too small"},
     {ERR_REASON(SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST),
      "empty srtp protection profile list"},
-    {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),
-     "encrypted length too long"},
+    {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG), "encrypted length too long"},
     {ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST),
      "error in received cipher list"},
     {ERR_REASON(SSL_R_ERROR_SETTING_TLSA_BASE_DOMAIN),
@@ -620,14 +601,11 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
      "no shared sigature algorithms"},
     {ERR_REASON(SSL_R_NO_SRTP_PROFILES), "no srtp profiles"},
     {ERR_REASON(SSL_R_NO_VERIFY_CALLBACK), "no verify callback"},
-    {ERR_REASON(SSL_R_NO_VERIFY_COOKIE_CALLBACK),
-     "no verify cookie callback"},
+    {ERR_REASON(SSL_R_NO_VERIFY_COOKIE_CALLBACK), "no verify cookie callback"},
     {ERR_REASON(SSL_R_NULL_SSL_CTX), "null ssl ctx"},
     {ERR_REASON(SSL_R_NULL_SSL_METHOD_PASSED), "null ssl method passed"},
     {ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED),
      "old session cipher not returned"},
-    {ERR_REASON(SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED),
-     "old session compression algorithm not returned"},
     {ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG), "packet length too long"},
     {ERR_REASON(SSL_R_PARSE_TLSEXT), "parse tlsext"},
     {ERR_REASON(SSL_R_PATH_TOO_LONG), "path too long"},
@@ -675,8 +653,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
     {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE),
      "ssl3 ext invalid servername type"},
     {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG), "ssl3 session id too long"},
-    {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT),
-     "ssl3 session id too short"},
+    {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT), "ssl3 session id too short"},
     {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_CERTIFICATE),
      "sslv3 alert bad certificate"},
     {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_RECORD_MAC),
@@ -718,8 +695,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
      "ssl session id context too long"},
     {ERR_REASON(SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH),
      "ssl session id has bad length"},
-    {ERR_REASON(SSL_R_TLSV1_ALERT_ACCESS_DENIED),
-     "tlsv1 alert access denied"},
+    {ERR_REASON(SSL_R_TLSV1_ALERT_ACCESS_DENIED), "tlsv1 alert access denied"},
     {ERR_REASON(SSL_R_TLSV1_ALERT_DECODE_ERROR), "tlsv1 alert decode error"},
     {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPTION_FAILED),
      "tlsv1 alert decryption failed"},
@@ -765,8 +741,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
      "tls peer did not respond with certificate list"},
     {ERR_REASON(SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG),
      "tls rsa encrypted value length is wrong"},
-    {ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS),
-     "unable to decode dh certs"},
+    {ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS), "unable to decode dh certs"},
     {ERR_REASON(SSL_R_UNABLE_TO_DECODE_ECDH_CERTS),
      "unable to decode ecdh certs"},
     {ERR_REASON(SSL_R_UNABLE_TO_FIND_DH_PARAMETERS),
@@ -775,8 +750,7 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
      "unable to find ecdh parameters"},
     {ERR_REASON(SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS),
      "unable to find public key parameters"},
-    {ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD),
-     "unable to find ssl method"},
+    {ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD), "unable to find ssl method"},
     {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES),
      "unable to load ssl3 md5 routines"},
     {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES),
@@ -791,12 +765,10 @@ static ERR_STRING_DATA SSL_str_reasons[] = {
     {ERR_REASON(SSL_R_UNKNOWN_CMD_NAME), "unknown cmd name"},
     {ERR_REASON(SSL_R_UNKNOWN_COMMAND), "unknown command"},
     {ERR_REASON(SSL_R_UNKNOWN_DIGEST), "unknown digest"},
-    {ERR_REASON(SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE),
-     "unknown key exchange type"},
+    {ERR_REASON(SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE), "unknown key exchange type"},
     {ERR_REASON(SSL_R_UNKNOWN_PKEY_TYPE), "unknown pkey type"},
     {ERR_REASON(SSL_R_UNKNOWN_PROTOCOL), "unknown protocol"},
-    {ERR_REASON(SSL_R_UNKNOWN_REMOTE_ERROR_TYPE),
-     "unknown remote error type"},
+    {ERR_REASON(SSL_R_UNKNOWN_REMOTE_ERROR_TYPE), "unknown remote error type"},
     {ERR_REASON(SSL_R_UNKNOWN_SSL_VERSION), "unknown ssl version"},
     {ERR_REASON(SSL_R_UNKNOWN_STATE), "unknown state"},
     {ERR_REASON(SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED),
diff --git a/test/Makefile b/test/Makefile
index 8103558..8854212 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -30,6 +30,7 @@ LIBFIPS= -L.. -lfips
 START= @@@ START
 
 NPTEST=		nptest
+MEMLEAKTEST=    memleaktest
 BNTEST=		bntest
 ECTEST=		ectest
 ECDSATEST=	ecdsatest
@@ -83,7 +84,8 @@ ASYNCTEST=	asynctest
 
 TESTS=		alltests
 
-EXE=	$(NPTEST)$(EXE_EXT) $(BNTEST)$(EXE_EXT) $(ECTEST)$(EXE_EXT) \
+EXE=	$(NPTEST)$(EXE_EXT) $(MEMLEAKTEST)$(EXE_EXT) \
+	$(BNTEST)$(EXE_EXT) $(ECTEST)$(EXE_EXT) \
 	$(ECDSATEST)$(EXE_EXT) $(ECDHTEST)$(EXE_EXT) $(GMDIFFTEST)$(EXE_EXT) \
 	$(PBELUTEST)$(EXE_EXT) $(IDEATEST)$(EXE_EXT) \
 	$(MD2TEST)$(EXE_EXT)  $(MD4TEST)$(EXE_EXT) $(MD5TEST)$(EXE_EXT) $(HMACTEST)$(EXE_EXT) $(WPTEST)$(EXE_EXT) \
@@ -103,7 +105,8 @@ EXE=	$(NPTEST)$(EXE_EXT) $(BNTEST)$(EXE_EXT) $(ECTEST)$(EXE_EXT) \
 
 # $(METHTEST)$(EXE_EXT)
 
-OBJ=	$(NPTEST).o $(BNTEST).o $(ECTEST).o \
+OBJ=	$(NPTEST).o $(MEMLEAKTEST).o \
+	$(BNTEST).o $(ECTEST).o \
 	$(ECDSATEST).o $(ECDHTEST).o $(GMDIFFTEST).o $(PBELUTEST).o $(IDEATEST).o \
 	$(MD2TEST).o $(MD4TEST).o $(MD5TEST).o \
 	$(HMACTEST).o $(WPTEST).o \
@@ -117,7 +120,8 @@ OBJ=	$(NPTEST).o $(BNTEST).o $(ECTEST).o \
 	$(CONSTTIMETEST).o $(VERIFYEXTRATEST).o $(CLIENTHELLOTEST).o \
 	$(PACKETTEST).o $(ASYNCTEST).o testutil.o
 
-SRC=	$(NPTEST).c $(BNTEST).c $(ECTEST).c \
+SRC=	$(NPTEST).c $(MEMLEAKTEST).c \
+	$(BNTEST).c $(ECTEST).c \
 	$(ECDSATEST).c $(ECDHTEST).c $(GMDIFFTEST).c $(PBELUTEST).c $(IDEATEST).c \
 	$(MD2TEST).c  $(MD4TEST).c $(MD5TEST).c \
 	$(HMACTEST).c $(WPTEST).c \
@@ -205,6 +209,9 @@ $(RSATEST)$(EXE_EXT): $(RSATEST).o $(DLIBCRYPTO)
 $(NPTEST)$(EXE_EXT): $(NPTEST).o $(DLIBCRYPTO)
 	@target=$(NPTEST); $(BUILD_CMD)
 
+$(MEMLEAKTEST)$(EXE_EXT): $(MEMLEAKTEST).o $(DLIBCRYPTO)
+	@target=$(MEMLEAKTEST); $(BUILD_CMD)
+
 $(BNTEST)$(EXE_EXT): $(BNTEST).o $(DLIBCRYPTO)
 	@target=$(BNTEST); $(BUILD_CMD)
 
@@ -570,7 +577,8 @@ gost2814789test.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
 gost2814789test.o: ../include/openssl/sha.h ../include/openssl/stack.h
 gost2814789test.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
 gost2814789test.o: ../include/openssl/x509_vfy.h gost2814789test.c
-heartbeat_test.o: ../e_os.h ../include/openssl/asn1.h
+heartbeat_test.o: ../e_os.h ../include/internal/dane.h
+heartbeat_test.o: ../include/internal/numbers.h ../include/openssl/asn1.h
 heartbeat_test.o: ../include/openssl/async.h ../include/openssl/bio.h
 heartbeat_test.o: ../include/openssl/bn.h ../include/openssl/buffer.h
 heartbeat_test.o: ../include/openssl/comp.h ../include/openssl/crypto.h
@@ -631,6 +639,11 @@ mdc2test.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 mdc2test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 mdc2test.o: ../include/openssl/safestack.h ../include/openssl/stack.h
 mdc2test.o: ../include/openssl/symhacks.h mdc2test.c
+memleaktest.o: ../include/openssl/bio.h ../include/openssl/crypto.h
+memleaktest.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
+memleaktest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+memleaktest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+memleaktest.o: ../include/openssl/symhacks.h memleaktest.c
 nptest.o: nptest.c
 p5_crpt2_test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
 p5_crpt2_test.o: ../include/openssl/buffer.h ../include/openssl/conf.h
@@ -644,12 +657,12 @@ p5_crpt2_test.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
 p5_crpt2_test.o: ../include/openssl/sha.h ../include/openssl/stack.h
 p5_crpt2_test.o: ../include/openssl/symhacks.h ../include/openssl/x509.h
 p5_crpt2_test.o: ../include/openssl/x509_vfy.h p5_crpt2_test.c
-packettest.o: ../include/openssl/bn.h ../include/openssl/buffer.h
-packettest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
-packettest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
-packettest.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h
-packettest.o: ../include/openssl/stack.h ../include/openssl/symhacks.h
-packettest.o: ../ssl/packet_locl.h packettest.c
+packettest.o: ../include/internal/numbers.h ../include/openssl/bn.h
+packettest.o: ../include/openssl/buffer.h ../include/openssl/crypto.h
+packettest.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
+packettest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
+packettest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
+packettest.o: ../include/openssl/symhacks.h ../ssl/packet_locl.h packettest.c
 pbelutest.o: ../include/openssl/asn1.h ../include/openssl/bio.h
 pbelutest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
 pbelutest.o: ../include/openssl/evp.h ../include/openssl/obj_mac.h
@@ -689,7 +702,8 @@ sha1test.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
 sha1test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
 sha1test.o: ../include/openssl/safestack.h ../include/openssl/sha.h
 sha1test.o: ../include/openssl/stack.h ../include/openssl/symhacks.h sha1test.c
-ssltest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/async.h
+ssltest.o: ../e_os.h ../include/internal/dane.h ../include/internal/numbers.h
+ssltest.o: ../include/openssl/asn1.h ../include/openssl/async.h
 ssltest.o: ../include/openssl/bio.h ../include/openssl/bn.h
 ssltest.o: ../include/openssl/buffer.h ../include/openssl/comp.h
 ssltest.o: ../include/openssl/conf.h ../include/openssl/crypto.h
diff --git a/test/Makefile b/test/Makefile.orig
similarity index 100%
copy from test/Makefile
copy to test/Makefile.orig
diff --git a/test/asynctest.c b/test/asynctest.c
index be41d2b..3e68b1d 100644
--- a/test/asynctest.c
+++ b/test/asynctest.c
@@ -282,8 +282,7 @@ int main(int argc, char **argv)
 #ifdef ASYNC_NULL
     fprintf(stderr, "NULL implementation - skipping async tests\n");
 #else
-    CRYPTO_malloc_debug_init();
-    CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     if (       !test_ASYNC_init()
diff --git a/test/clienthellotest.c b/test/clienthellotest.c
index 318d6e8..289ca1e 100644
--- a/test/clienthellotest.c
+++ b/test/clienthellotest.c
@@ -107,8 +107,7 @@ int main(int argc, char *argv[])
 
     err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     /*
@@ -212,7 +211,9 @@ int main(int argc, char *argv[])
     ERR_remove_thread_state(NULL);
     EVP_cleanup();
     CRYPTO_cleanup_all_ex_data();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks(err);
+#endif
     BIO_free(err);
 
     return testresult?0:1;
diff --git a/test/danetest.c b/test/danetest.c
index 063b944..2c7c3c6 100644
--- a/test/danetest.c
+++ b/test/danetest.c
@@ -301,27 +301,29 @@ static ossl_ssize_t checked_uint8(const char *in, void *out)
     return cp - in;
 }
 
+struct tlsa_field {
+    void *var;
+    const char *name;
+    ossl_ssize_t (*parser)(const char *, void *);
+};
+
 static int tlsa_import_rr(SSL *ssl, const char *rrdata)
 {
-    int ret;
-    uint8_t usage;
-    uint8_t selector;
-    uint8_t mtype;
-    unsigned char *data = NULL;
-    const char *cp = rrdata;
-    ossl_ssize_t len = 0;
-    struct tlsa_field {
-        void *var;
-        const char *name;
-        ossl_ssize_t (*parser)(const char *, void *);
-    } tlsa_fields[] = {
+    static uint8_t usage;
+    static uint8_t selector;
+    static uint8_t mtype;
+    static unsigned char *data = NULL;
+    static struct tlsa_field tlsa_fields[] = {
         { &usage, "usage", checked_uint8 },
         { &selector, "selector", checked_uint8 },
         { &mtype, "mtype", checked_uint8 },
         { &data, "data", hexdecode },
         { NULL, }
     };
+    int ret;
     struct tlsa_field *f;
+    const char *cp = rrdata;
+    ossl_ssize_t len = 0;
 
     for (f = tlsa_fields; f->var; ++f) {
         if ((len = f->parser(cp += len, f->var)) <= 0) {
@@ -452,23 +454,29 @@ static int test_tlsafile(SSL_CTX *ctx, const char *basename,
 
 int main(int argc, char *argv[])
 {
-    progname = argv[0];
     FILE *f;
     BIO *bio_err;
     SSL_CTX *ctx = NULL;
     const char *basedomain;
     const char *CAfile;
     const char *tlsafile;
+    const char *p;
     int ret = 1;
 
+    progname = argv[0];
     if (argc != 4) {
         usage();
         EXIT(1);
     }
     basedomain = argv[1];
+    basedomain++; /* Force a use! */
     CAfile = argv[2];
     tlsafile = argv[3];
 
+    p = getenv("OPENSSL_DEBUG_MEMORY");
+    if (p != NULL && strcmp(p, "on") == 0)
+        CRYPTO_set_mem_debug(1);
+
     f = fopen(tlsafile, "r");
     if (f == NULL) {
         fprintf(stderr, "%s: Error opening tlsa record file: '%s': %s\n",
@@ -478,17 +486,6 @@ int main(int argc, char *argv[])
 
     bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
 
-    /* enable memory leak checking unless explicitly disabled */
-    if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL)
-          && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) {
-        CRYPTO_malloc_debug_init();
-        CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-    } else {
-        /* OPENSSL_DEBUG_MEMORY=off */
-        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-    }
-    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
-
     SSL_library_init();
     SSL_load_error_strings();
 
diff --git a/test/dhtest.c b/test/dhtest.c
index 0ca5175..93a866c 100644
--- a/test/dhtest.c
+++ b/test/dhtest.c
@@ -96,14 +96,9 @@ int main(int argc, char *argv[])
     int ret = 1;
     BIO *out = NULL;
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
-# ifdef OPENSSL_SYS_WIN32
-    CRYPTO_malloc_init();
-# endif
-
     RAND_seed(rnd_seed, sizeof rnd_seed);
 
     out = BIO_new(BIO_s_file());
diff --git a/test/dsatest.c b/test/dsatest.c
index 1f4b837..81c36cb 100644
--- a/test/dsatest.c
+++ b/test/dsatest.c
@@ -138,8 +138,7 @@ int main(int argc, char **argv)
     if (bio_err == NULL)
         bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     ERR_load_crypto_strings();
@@ -216,7 +215,9 @@ int main(int argc, char **argv)
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
     ERR_free_strings();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks(bio_err);
+#endif
     BIO_free(bio_err);
     bio_err = NULL;
 # ifdef OPENSSL_SYS_NETWARE
diff --git a/test/ecdhtest.c b/test/ecdhtest.c
index d77e007..c299c32 100644
--- a/test/ecdhtest.c
+++ b/test/ecdhtest.c
@@ -452,14 +452,9 @@ int main(int argc, char *argv[])
     int ret = 1;
     BIO *out;
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
-# ifdef OPENSSL_SYS_WIN32
-    CRYPTO_malloc_init();
-# endif
-
     RAND_seed(rnd_seed, sizeof rnd_seed);
 
     out = BIO_new(BIO_s_file());
@@ -521,7 +516,9 @@ int main(int argc, char *argv[])
     BIO_free(out);
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
+#endif
     EXIT(ret);
 }
 #endif
diff --git a/test/ecdsatest.c b/test/ecdsatest.c
index 023eb12..2e85d5e 100644
--- a/test/ecdsatest.c
+++ b/test/ecdsatest.c
@@ -516,20 +516,13 @@ int main(void)
 {
     int ret = 1;
     BIO *out;
+    char *p;
 
     out = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
 
-    /* enable memory leak checking unless explicitly disabled */
-    if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) &&
-          (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) {
-        CRYPTO_malloc_debug_init();
-        CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-    } else {
-        /* OPENSSL_DEBUG_MEMORY=off */
-        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-    }
-    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
-
+    p = getenv("OPENSSL_DEBUG_MEMORY");
+    if (p != NULL && strcmp(p, "on") == 0)
+        CRYPTO_set_mem_debug(1);
     ERR_load_crypto_strings();
 
     /* initialize the prng */
@@ -552,7 +545,9 @@ int main(void)
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
     ERR_free_strings();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks(out);
+#endif
     BIO_free(out);
     return ret;
 }
diff --git a/test/ectest.c b/test/ectest.c
index c6f1d7e..9667772 100644
--- a/test/ectest.c
+++ b/test/ectest.c
@@ -1637,16 +1637,11 @@ static const char rnd_seed[] =
 
 int main(int argc, char *argv[])
 {
+    char *p;
 
-    /* enable memory leak checking unless explicitly disabled */
-    if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL)
-          && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) {
-        CRYPTO_malloc_debug_init();
-        CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-    } else {
-        /* OPENSSL_DEBUG_MEMORY=off */
-        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-    }
+    p = getenv("OPENSSL_DEBUG_MEMORY");
+    if (p != NULL && strcmp(p, "on") == 0)
+        CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
     ERR_load_crypto_strings();
 
@@ -1669,7 +1664,9 @@ int main(int argc, char *argv[])
     CRYPTO_cleanup_all_ex_data();
     ERR_free_strings();
     ERR_remove_thread_state(NULL);
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
+#endif
 
     return 0;
 }
diff --git a/test/enginetest.c b/test/enginetest.c
index bbe40e6..f5924e0 100644
--- a/test/enginetest.c
+++ b/test/enginetest.c
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
 {
     ENGINE *block[512];
     char buf[256];
-    const char *id, *name;
+    const char *id, *name, *p;
     ENGINE *ptr;
     int loop;
     int to_return = 1;
@@ -107,16 +107,9 @@ int main(int argc, char *argv[])
     ENGINE *new_h3 = NULL;
     ENGINE *new_h4 = NULL;
 
-    /* enable memory leak checking unless explicitly disabled */
-    if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL)
-          && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) {
-        CRYPTO_malloc_debug_init();
-        CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-    } else {
-        /* OPENSSL_DEBUG_MEMORY=off */
-        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-    }
-    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+    p = getenv("OPENSSL_DEBUG_MEMORY");
+    if (p != NULL && strcmp(p, "on") == 0)
+        CRYPTO_set_mem_debug(1);
     ERR_load_crypto_strings();
 
     memset(block, 0, sizeof(block));
@@ -256,7 +249,9 @@ int main(int argc, char *argv[])
     CRYPTO_cleanup_all_ex_data();
     ERR_free_strings();
     ERR_remove_thread_state(NULL);
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
+#endif
     return to_return;
 }
 #endif
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index a536308..0d6ad03 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -419,8 +419,7 @@ static int test_EVP_PKCS82PKEY(void)
 
 int main(void)
 {
-    CRYPTO_malloc_debug_init();
-    CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     ERR_load_crypto_strings();
@@ -467,7 +466,9 @@ int main(void)
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
     ERR_free_strings();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
+#endif
 
     printf("PASS\n");
     return 0;
diff --git a/test/jpaketest.c b/test/jpaketest.c
index 15f00cf..2771e51 100644
--- a/test/jpaketest.c
+++ b/test/jpaketest.c
@@ -116,8 +116,7 @@ int main(int argc, char **argv)
 
     bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug_functions(1)
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     ERR_load_crypto_strings();
diff --git a/test/nptest.c b/test/memleaktest.c
similarity index 79%
copy from test/nptest.c
copy to test/memleaktest.c
index 9528851..cccbcf6 100644
--- a/test/nptest.c
+++ b/test/memleaktest.c
@@ -52,15 +52,37 @@
  *
  */
 
-
 #include <stdio.h>
 #include <string.h>
+#include <openssl/bio.h>
+#include <openssl/crypto.h>
 
-int main()
+int main(int argc, char **argv)
 {
-    char *p = NULL;
-    char bytes[sizeof(p)];
+#ifdef CRYPTO_MDEBUG
+    char *p;
+    char *lost;
+
+    p = getenv("OPENSSL_DEBUG_MEMORY");
+    if (p != NULL && strcmp(p, "on") == 0)
+        CRYPTO_set_mem_debug(1);
+    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+
+    lost = OPENSSL_malloc(3);
+    if (lost == NULL) {
+        fprintf(stderr, "OPENSSL_malloc failed\n");
+        return 1;
+    }
+
+    if (argv[1] && strcmp(argv[1], "freeit") == 0)
+        OPENSSL_free(lost);
 
-    memset(bytes, 0, sizeof bytes);
-    return memcmp(&p, bytes, sizeof(bytes)) == 0 ? 0 : 1;
+    CRYPTO_mem_leaks_fp(stderr);
+    return 0;
+#else
+    if (argv[1] && strcmp(argv[1], "freeit") == 0)
+        return 0;
+    fprintf(stderr, "Leak simulated\n");
+    return 1;
+#endif
 }
diff --git a/test/p5_crpt2_test.c b/test/p5_crpt2_test.c
index 01661b1..657d10e 100644
--- a/test/p5_crpt2_test.c
+++ b/test/p5_crpt2_test.c
@@ -180,8 +180,7 @@ int main(int argc, char **argv)
     int i;
     testdata *test = test_cases;
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     OpenSSL_add_all_digests();
@@ -206,6 +205,8 @@ int main(int argc, char **argv)
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
     ERR_free_strings();
+# ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
+# endif
     return 0;
 }
diff --git a/test/recipes/90-test_memleak.t b/test/recipes/90-test_memleak.t
new file mode 100644
index 0000000..7aff0c0
--- /dev/null
+++ b/test/recipes/90-test_memleak.t
@@ -0,0 +1,7 @@
+#! /usr/bi/nperl
+
+use OpenSSL::Test;
+
+setup("test_memleak");
+plan tests => 1;
+ok(!run(test(["memleaktest"])), "running memleaktest");
diff --git a/test/rsa_test.c b/test/rsa_test.c
index 85c7440..3cfd32e 100644
--- a/test/rsa_test.c
+++ b/test/rsa_test.c
@@ -222,8 +222,7 @@ int main(int argc, char *argv[])
     int num;
     int n;
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
@@ -328,7 +327,9 @@ int main(int argc, char *argv[])
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
 
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
+#endif
 
 # ifdef OPENSSL_SYS_NETWARE
     if (err)
diff --git a/test/srptest.c b/test/srptest.c
index 60cdbc3..03e8cf4 100644
--- a/test/srptest.c
+++ b/test/srptest.c
@@ -126,8 +126,7 @@ int main(int argc, char **argv)
     BIO *bio_err;
     bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
 
-    CRYPTO_malloc_debug_init();
-    CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     ERR_load_crypto_strings();
@@ -147,7 +146,9 @@ int main(int argc, char **argv)
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
     ERR_free_strings();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks(bio_err);
+#endif
     BIO_free(bio_err);
 
     return 0;
diff --git a/test/ssltest.c b/test/ssltest.c
index 44d0019..c3d655e 100644
--- a/test/ssltest.c
+++ b/test/ssltest.c
@@ -1009,6 +1009,7 @@ int main(int argc, char *argv[])
     int server_auth = 0, i;
     struct app_verify_arg app_verify_arg =
         { APP_CALLBACK_STRING, 0, 0, NULL, NULL };
+    char *p;
 #ifndef OPENSSL_NO_EC
     char *named_curve = NULL;
 #endif
@@ -1059,15 +1060,9 @@ int main(int argc, char *argv[])
 
     CRYPTO_set_locking_callback(lock_dbg_cb);
 
-    /* enable memory leak checking unless explicitly disabled */
-    if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL)
-          && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) {
-        CRYPTO_malloc_debug_init();
-        CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
-    } else {
-        /* OPENSSL_DEBUG_MEMORY=off */
-        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
-    }
+    p = getenv("OPENSSL_DEBUG_MEMORY");
+    if (p != NULL && strcmp(p, "on") == 0)
+        CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     RAND_seed(rnd_seed, sizeof rnd_seed);
@@ -1826,7 +1821,9 @@ int main(int argc, char *argv[])
     ERR_free_strings();
     ERR_remove_thread_state(NULL);
     EVP_cleanup();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks(bio_err);
+#endif
     BIO_free(bio_err);
     EXIT(ret);
 }
diff --git a/test/verify_extra_test.c b/test/verify_extra_test.c
index 7cc6739..005fae6 100644
--- a/test/verify_extra_test.c
+++ b/test/verify_extra_test.c
@@ -187,8 +187,7 @@ static int test_alt_chains_cert_forgery(const char *roots_f,
 
 int main(int argc, char **argv)
 {
-    CRYPTO_malloc_debug_init();
-    CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+    CRYPTO_set_mem_debug(1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
     ERR_load_crypto_strings();
@@ -208,7 +207,9 @@ int main(int argc, char **argv)
     CRYPTO_cleanup_all_ex_data();
     ERR_remove_thread_state(NULL);
     ERR_free_strings();
+#ifdef CRYPTO_MDEBUG
     CRYPTO_mem_leaks_fp(stderr);
+#endif
 
     printf("PASS\n");
     return 0;
diff --git a/util/libeay.num b/util/libeay.num
index a202fca..45e0d28 100755
--- a/util/libeay.num
+++ b/util/libeay.num
@@ -159,16 +159,15 @@ BN_value_one                            166	1_1_0	EXIST::FUNCTION:
 BUF_MEM_free                            167	1_1_0	EXIST::FUNCTION:
 BUF_MEM_grow                            168	1_1_0	EXIST::FUNCTION:
 BUF_MEM_new                             169	1_1_0	EXIST::FUNCTION:
-BUF_strdup                              170	1_1_0	NOEXIST::FUNCTION:
 CONF_free                               171	1_1_0	EXIST::FUNCTION:
 CONF_get_number                         172	1_1_0	EXIST::FUNCTION:
 CONF_get_section                        173	1_1_0	EXIST::FUNCTION:
 CONF_get_string                         174	1_1_0	EXIST::FUNCTION:
 CONF_load                               175	1_1_0	EXIST::FUNCTION:
 CRYPTO_add_lock                         176	1_1_0	EXIST::FUNCTION:
-CRYPTO_dbg_free                         177	1_1_0	EXIST::FUNCTION:
-CRYPTO_dbg_malloc                       178	1_1_0	EXIST::FUNCTION:
-CRYPTO_dbg_realloc                      179	1_1_0	EXIST::FUNCTION:
+CRYPTO_mem_debug_free                   177	1_1_0	EXIST::FUNCTION:
+CRYPTO_mem_debug_malloc                 178	1_1_0	EXIST::FUNCTION:
+CRYPTO_mem_debug_realloc                179	1_1_0	EXIST::FUNCTION:
 CRYPTO_dbg_remalloc                     180	1_1_0	NOEXIST::FUNCTION:
 CRYPTO_free                             181	1_1_0	EXIST::FUNCTION:
 CRYPTO_get_add_lock_callback            182	1_1_0	EXIST::FUNCTION:
@@ -180,7 +179,7 @@ CRYPTO_lock                             187	1_1_0	EXIST::FUNCTION:
 CRYPTO_malloc                           188	1_1_0	EXIST::FUNCTION:
 CRYPTO_mem_ctrl                         189	1_1_0	EXIST::FUNCTION:
 CRYPTO_mem_leaks                        190	1_1_0	EXIST::FUNCTION:
-CRYPTO_mem_leaks_cb                     191	1_1_0	EXIST::FUNCTION:
+CRYPTO_mem_leaks_cb                     191	1_1_0	NOEXIST::FUNCTION:
 CRYPTO_mem_leaks_fp                     192	1_1_0	EXIST::FUNCTION:STDIO
 CRYPTO_realloc                          193	1_1_0	EXIST::FUNCTION:
 CRYPTO_remalloc                         194	1_1_0	NOEXIST::FUNCTION:
@@ -1679,14 +1678,12 @@ PKCS7_simple_smimecap                   2153	1_1_0	EXIST::FUNCTION:
 PKCS7_get_smimecap                      2154	1_1_0	EXIST::FUNCTION:
 PKCS7_sign                              2155	1_1_0	EXIST::FUNCTION:
 PKCS7_add_attrib_smimecap               2156	1_1_0	EXIST::FUNCTION:
-CRYPTO_dbg_set_options                  2157	1_1_0	EXIST::FUNCTION:
+CRYPTO_dbg_set_options                  2157	1_1_0	NOEXIST::FUNCTION:
 CRYPTO_remove_all_info                  2158	1_1_0	NOEXIST::FUNCTION:
-CRYPTO_get_mem_debug_functions          2159	1_1_0	EXIST::FUNCTION:
-CRYPTO_is_mem_check_on                  2160	1_1_0	EXIST::FUNCTION:
-CRYPTO_set_mem_debug_functions          2161	1_1_0	EXIST::FUNCTION:
-CRYPTO_mem_debug_pop                    2162	1_1_0	EXIST::FUNCTION:
-CRYPTO_mem_debug_push                   2163	1_1_0	EXIST::FUNCTION:
-CRYPTO_set_mem_debug_options            2164	1_1_0	EXIST::FUNCTION:
+CRYPTO_get_mem_debug_functions          2159	1_1_0	NOEXIST::FUNCTION:
+CRYPTO_is_mem_check_on                  2160	1_1_0	NOEXIST::FUNCTION:
+CRYPTO_set_mem_debug_functions          2161	1_1_0	NOEXIST::FUNCTION:
+CRYPTO_set_mem_debug_options            2164	1_1_0	NOEXIST::FUNCTION:
 PEM_write_PKCS8PrivateKey_nid           2165	1_1_0	EXIST::FUNCTION:STDIO
 PEM_write_bio_PKCS8PrivateKey_nid       2166	1_1_0	EXIST:!VMS:FUNCTION:
 PEM_write_bio_PKCS8PrivKey_nid          2166	1_1_0	EXIST:VMS:FUNCTION:
@@ -1750,9 +1747,9 @@ BN_CTX_start                            2242	1_1_0	EXIST::FUNCTION:
 BN_CTX_get                              2243	1_1_0	EXIST::FUNCTION:
 EVP_PKEY2PKCS8_broken                   2244	1_1_0	EXIST::FUNCTION:
 ASN1_STRING_TABLE_add                   2245	1_1_0	EXIST::FUNCTION:
-CRYPTO_dbg_get_options                  2246	1_1_0	EXIST::FUNCTION:
+CRYPTO_dbg_get_options                  2246	1_1_0	NOEXIST::FUNCTION:
 AUTHORITY_INFO_ACCESS_new               2247	1_1_0	EXIST::FUNCTION:
-CRYPTO_get_mem_debug_options            2248	1_1_0	EXIST::FUNCTION:
+CRYPTO_get_mem_debug_options            2248	1_1_0	NOEXIST::FUNCTION:
 DES_crypt                               2249	1_1_0	EXIST::FUNCTION:DES
 PEM_write_bio_X509_REQ_NEW              2250	1_1_0	EXIST::FUNCTION:
 PEM_write_X509_REQ_NEW                  2251	1_1_0	EXIST::FUNCTION:
@@ -2233,7 +2230,6 @@ DIRECTORYSTRING_it                      2767	1_1_0	EXIST:!EXPORT_VAR_AS_FUNCTION
 DIRECTORYSTRING_it                      2767	1_1_0	EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
 d2i_OCSP_CRLID                          2768	1_1_0	EXIST::FUNCTION:
 EC_POINT_is_on_curve                    2769	1_1_0	EXIST::FUNCTION:EC
-CRYPTO_set_locked_mem_ex_funcs          2770	1_1_0	NOEXIST::FUNCTION:
 CRYPTO_set_locked_mem_ex_functions      2770	1_1_0	NOEXIST::FUNCTION:
 d2i_KRB5_CHECKSUM                       2771	1_1_0	NOEXIST::FUNCTION:
 ASN1_item_dup                           2772	1_1_0	EXIST::FUNCTION:
@@ -2243,13 +2239,10 @@ BN_mod_add                              2774	1_1_0	EXIST::FUNCTION:
 KRB5_AUTHDATA_free                      2775	1_1_0	NOEXIST::FUNCTION:
 _ossl_old_des_cbc_cksum                 2776	1_1_0	NOEXIST::FUNCTION:
 ASN1_item_verify                        2777	1_1_0	EXIST::FUNCTION:
-CRYPTO_set_mem_ex_functions             2778	1_1_0	EXIST::FUNCTION:
 EC_POINT_get_Jprojective_coordinates_GFp 2779	1_1_0	EXIST:!VMS:FUNCTION:EC
 EC_POINT_get_Jproj_coords_GFp           2779	1_1_0	EXIST:VMS:FUNCTION:EC
 ZLONG_it                                2780	1_1_0	EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
 ZLONG_it                                2780	1_1_0	EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
-CRYPTO_get_locked_mem_ex_funcs          2781	1_1_0	NOEXIST::FUNCTION:
-CRYPTO_get_locked_mem_ex_functions      2781	1_1_0	NOEXIST::FUNCTION:
 ASN1_TIME_check                         2782	1_1_0	EXIST::FUNCTION:
 UI_get0_user_data                       2783	1_1_0	EXIST::FUNCTION:
 HMAC_CTX_cleanup                        2784	1_1_0	NOEXIST::FUNCTION:
@@ -2339,7 +2332,6 @@ OCSP_ONEREQ_get_ext                     2851	1_1_0	EXIST::FUNCTION:
 EC_POINT_method_of                      2852	1_1_0	EXIST::FUNCTION:EC
 i2d_KRB5_APREQBODY                      2853	1_1_0	NOEXIST::FUNCTION:
 _ossl_old_des_ecb3_encrypt              2854	1_1_0	NOEXIST::FUNCTION:
-CRYPTO_get_mem_ex_functions             2855	1_1_0	EXIST::FUNCTION:
 ENGINE_get_ex_data                      2856	1_1_0	EXIST::FUNCTION:ENGINE
 UI_destroy_method                       2857	1_1_0	EXIST::FUNCTION:
 ASN1_item_i2d_bio                       2858	1_1_0	EXIST::FUNCTION:
@@ -2786,10 +2778,8 @@ EVP_des_ede3_ecb                        3236	1_1_0	EXIST::FUNCTION:DES
 X509_REQ_print_ex                       3237	1_1_0	EXIST::FUNCTION:
 ENGINE_up_ref                           3238	1_1_0	EXIST::FUNCTION:ENGINE
 BUF_MEM_grow_clean                      3239	1_1_0	EXIST::FUNCTION:
-CRYPTO_clear_realloc                    3240	1_1_0	EXIST::FUNCTION:
 BUF_strlcat                             3241	1_1_0	NOEXIST::FUNCTION:
 BIO_indent                              3242	1_1_0	EXIST::FUNCTION:
-BUF_strlcpy                             3243	1_1_0	NOEXIST::FUNCTION:
 OpenSSLDie                              3244	1_1_0	EXIST::FUNCTION:
 OPENSSL_cleanse                         3245	1_1_0	EXIST::FUNCTION:
 ENGINE_setup_bsd_cryptodev              3246	1_1_0	EXIST:__FreeBSD__:FUNCTION:ENGINE
@@ -3051,7 +3041,6 @@ STORE_meth_set_delete_fn                3486	1_1_0	NOEXIST::FUNCTION:
 STORE_method_set_delete_function        3486	1_1_0	NOEXIST::FUNCTION:
 STORE_list_certificate_next             3487	1_1_0	NOEXIST::FUNCTION:
 ASN1_generate_nconf                     3488	1_1_0	EXIST::FUNCTION:
-BUF_memdup                              3489	1_1_0	NOEXIST::FUNCTION:
 BN_GF2m_mod_mul                         3490	1_1_0	EXIST::FUNCTION:EC2M
 STORE_meth_get_list_next_fn             3491	1_1_0	NOEXIST::FUNCTION:
 STORE_method_get_list_next_function     3491	1_1_0	NOEXIST::FUNCTION:
@@ -3077,7 +3066,6 @@ ECDSA_get_ex_data                       3509	1_1_0	NOEXIST::FUNCTION:
 SHA224                                  3510	1_1_0	EXIST::FUNCTION:
 BIO_dump_indent_fp                      3511	1_1_0	EXIST::FUNCTION:STDIO
 EC_KEY_set_group                        3512	1_1_0	EXIST::FUNCTION:EC
-BUF_strndup                             3513	1_1_0	NOEXIST::FUNCTION:
 STORE_list_certificate_start            3514	1_1_0	NOEXIST::FUNCTION:
 BN_GF2m_mod                             3515	1_1_0	EXIST::FUNCTION:EC2M
 X509_REQ_check_private_key              3516	1_1_0	EXIST::FUNCTION:
@@ -3655,7 +3643,6 @@ FIPS_dsa_sig_decode                     4049	1_1_0	NOEXIST::FUNCTION:
 EVP_CIPHER_CTX_clear_flags              4050	1_1_0	EXIST::FUNCTION:
 FIPS_rand_status                        4051	1_1_0	NOEXIST::FUNCTION:
 FIPS_rand_set_key                       4052	1_1_0	NOEXIST::FUNCTION:
-CRYPTO_set_mem_info_functions           4053	1_1_0	NOEXIST::FUNCTION:
 RSA_X931_generate_key_ex                4054	1_1_0	EXIST::FUNCTION:RSA
 int_ERR_set_state_func                  4055	1_1_0	NOEXIST::FUNCTION:
 int_EVP_MD_set_engine_callbacks         4056	1_1_0	NOEXIST::FUNCTION:
@@ -4393,7 +4380,6 @@ X509_VERIFY_PARAM_get0                  4762	1_1_0	EXIST::FUNCTION:
 X509V3_EXT_free                         4763	1_1_0	NOEXIST::FUNCTION:
 BIO_hex_string                          4764	1_1_0	EXIST::FUNCTION:
 X509_VERIFY_PARAM_set_hostflags         4765	1_1_0	EXIST::FUNCTION:
-BUF_strnlen                             4766	1_1_0	NOEXIST::FUNCTION:
 X509_VERIFY_PARAM_get0_peername         4767	1_1_0	EXIST::FUNCTION:
 ECDSA_METHOD_set_app_data               4768	1_1_0	NOEXIST::FUNCTION:
 sk_deep_copy                            4769	1_1_0	EXIST::FUNCTION:
@@ -4560,7 +4546,6 @@ PKCS5_pbe2_set_scrypt                   4931	1_1_0	EXIST::FUNCTION:SCRYPT
 PKCS8_set0_pbe                          4932	1_1_0	EXIST::FUNCTION:
 DH_bits                                 4933	1_1_0	EXIST::FUNCTION:DH
 RSA_bits                                4934	1_1_0	EXIST::FUNCTION:RSA
-CRYPTO_set_secure_mem_ex_functions      4935	1_1_0	EXIST::FUNCTION:
 CRYPTO_secure_allocated                 4936	1_1_0	EXIST::FUNCTION:
 BN_CTX_secure_new                       4937	1_1_0	EXIST::FUNCTION:
 CRYPTO_secure_malloc                    4938	1_1_0	EXIST::FUNCTION:
@@ -4568,12 +4553,9 @@ CRYPTO_secure_malloc_done               4939	1_1_0	EXIST::FUNCTION:
 BUF_MEM_new_ex                          4940	1_1_0	EXIST::FUNCTION:
 CRYPTO_secure_malloc_initialized        4941	1_1_0	EXIST::FUNCTION:
 CRYPTO_secure_malloc_init               4942	1_1_0	EXIST::FUNCTION:
-CRYPTO_get_secure_mem_functions         4943	1_1_0	EXIST::FUNCTION:
 BN_secure_new                           4944	1_1_0	EXIST::FUNCTION:
 CRYPTO_secure_free                      4945	1_1_0	EXIST::FUNCTION:
 BIO_s_secmem                            4946	1_1_0	EXIST::FUNCTION:
-CRYPTO_get_secure_mem_ex_functions      4947	1_1_0	EXIST::FUNCTION:
-CRYPTO_set_secure_mem_functions         4948	1_1_0	EXIST::FUNCTION:
 X509_STORE_CTX_get_num_untrusted        4949	1_1_0	EXIST::FUNCTION:
 X509_up_ref                             4950	1_1_0	EXIST::FUNCTION:
 X509_REQ_get_version                    4951	1_1_0	EXIST::FUNCTION:
@@ -4732,8 +4714,12 @@ EC_KEY_oct2key                          5107	1_1_0	EXIST::FUNCTION:EC
 OPENSSL_strlcpy                         5108	1_1_0	EXIST::FUNCTION:
 OPENSSL_strnlen                         5109	1_1_0	EXIST::FUNCTION:
 OPENSSL_strlcat                         5110	1_1_0	EXIST::FUNCTION:
-OPENSSL_memdup                          5111	1_1_0	NOEXIST::FUNCTION:
 CRYPTO_memdup                           5112	1_1_0	EXIST::FUNCTION:
 CRYPTO_strndup                          5113	1_1_0	EXIST::FUNCTION:
 X509_VERIFY_PARAM_move_peername         5114	1_1_0	EXIST::FUNCTION:
 X509_STORE_CTX_set0_dane                5115	1_1_0	EXIST::FUNCTION:
+CRYPTO_secure_used                      5116	1_1_0	EXIST::FUNCTION:
+CRYPTO_clear_realloc                    5117	1_1_0	EXIST::FUNCTION:
+CRYPTO_mem_debug_push                   5118	1_1_0	EXIST::FUNCTION:
+CRYPTO_set_mem_debug                    5119	1_1_0	EXIST::FUNCTION:
+CRYPTO_mem_debug_pop                    5120	1_1_0	EXIST::FUNCTION:


More information about the openssl-commits mailing list