diff --git a/contrib/wpa_supplicant/src/crypto/tls_openssl.c b/contrib/wpa_supplicant/src/crypto/tls_openssl.c
index d025ae0a8a..5923ca5273 100644
--- a/contrib/wpa_supplicant/src/crypto/tls_openssl.c
+++ b/contrib/wpa_supplicant/src/crypto/tls_openssl.c
@@ -2761,7 +2761,7 @@ struct wpabuf * tls_connection_decrypt(void *tls_ctx,
 
 int tls_connection_resumed(void *ssl_ctx, struct tls_connection *conn)
 {
-	return conn ? conn->ssl->hit : 0;
+	return conn ? SSL_cache_hit(conn->ssl) : 0;
 }
 
 
diff --git a/lib/librecrypto/Makefile b/lib/librecrypto/Makefile
index 8e4d29fd1b..a923fbdb65 100644
--- a/lib/librecrypto/Makefile
+++ b/lib/librecrypto/Makefile
@@ -11,10 +11,10 @@ NO_STRICT_ALIASING=
 
 INCS+=  	aes.h asn1.h asn1_mac.h asn1t.h
 INCS+=  	bio.h blowfish.h bn.h buffer.h
-INCS+=  	camellia.h cast.h chacha.h cmac.h cms.h comp.h conf.h conf_api.h crypto.h
+INCS+=  	camellia.h cast.h chacha.h cmac.h comp.h conf.h conf_api.h crypto.h
 INCS+=  	des.h dh.h dsa.h dso.h
 INCS+=  	ec.h ecdh.h ecdsa.h engine.h err.h evp.h
-INCS+=  	gost.h hmac.h idea.h krb5_asn.h lhash.h
+INCS+=  	gost.h hmac.h idea.h lhash.h
 INCS+=  	md4.h md5.h modes.h
 INCS+=  	obj_mac.h objects.h ocsp.h opensslconf.h opensslfeatures.h opensslv.h ossl_typ.h
 INCS+=  	pem.h pem2.h pkcs12.h pkcs7.h poly1305.h
@@ -24,7 +24,11 @@ INCS+=  	ts.h txt_db.h ui.h ui_compat.h
 INCS+=  	whrlpool.h x509.h x509_vfy.h x509v3.h
 INCSDIR=	${INCLUDEDIR}/priv/openssl
 
-CFLAGS+=	-I${LCRYPTO_SRC}/modes -I${LCRYPTO_SRC}/asn1 -I${LCRYPTO_SRC}/evp -I${.OBJDIR}
+CFLAGS+=	-I${LCRYPTO_SRC}/asn1 \
+		-I${LCRYPTO_SRC}/bn \
+		-I${LCRYPTO_SRC}/evp \
+		-I${LCRYPTO_SRC}/modes \
+		-I${.OBJDIR}
 
 CFLAGS+=	-DAES_ASM \
 		-DBSAES_ASM \
@@ -48,24 +52,24 @@ bzero_FLAGS_FILES=	explicit_bzero.c
 
 # Vendor ASM_X86_64_ELF definition with directories stripped off and
 # rearranged one per row
-ASM_X86_64_ELF=	aes-elf-x86_64.s \
-		bsaes-elf-x86_64.s \
-		vpaes-elf-x86_64.s \
-		aesni-elf-x86_64.s \
-		aesni-sha1-elf-x86_64.s \
-		modexp512-elf-x86_64.s \
-		mont-elf-x86_64.s \
-		mont5-elf-x86_64.s \
-		gf2m-elf-x86_64.s \
-		cmll-elf-x86_64.s \
-		md5-elf-x86_64.s \
-		ghash-elf-x86_64.s \
-		rc4-elf-x86_64.s \
-		rc4-md5-elf-x86_64.s \
-		sha1-elf-x86_64.s \
+ASM_X86_64_ELF=	aes-elf-x86_64.S \
+		bsaes-elf-x86_64.S \
+		vpaes-elf-x86_64.S \
+		aesni-elf-x86_64.S \
+		aesni-sha1-elf-x86_64.S \
+		modexp512-elf-x86_64.S \
+		mont-elf-x86_64.S \
+		mont5-elf-x86_64.S \
+		gf2m-elf-x86_64.S \
+		cmll-elf-x86_64.S \
+		md5-elf-x86_64.S \
+		ghash-elf-x86_64.S \
+		rc4-elf-x86_64.S \
+		rc4-md5-elf-x86_64.S \
+		sha1-elf-x86_64.S \
 		sha256-elf-x86_64.S \
 		sha512-elf-x86_64.S \
-		wp-elf-x86_64.s \
+		wp-elf-x86_64.S \
 		cpuid-elf-x86_64.S
 
 # Based on vendor libcrypto_la_SOURCES definitions with subdirectories stripped out
@@ -106,6 +110,7 @@ SRC_CMAC=	cm_ameth.c cm_pmeth.c cmac.c
 SRC_COMP=	c_rle.c c_zlib.c
 SRC_CONF=	comp_err.c comp_lib.c conf_api.c conf_def.c \
 		conf_err.c conf_lib.c conf_mall.c conf_mod.c conf_sap.c
+SRC_CURVE25519=	curve25519.c curve25519-generic.c
 SRC_DES=	cbc_cksm.c cbc_enc.c cfb64ede.c cfb64enc.c cfb_enc.c \
 		des_enc.c ecb3_enc.c ecb_enc.c ede_cbcm_enc.c enc_read.c \
 		enc_writ.c fcrypt.c fcrypt_b.c ofb64ede.c ofb64enc.c \
@@ -135,18 +140,18 @@ SRC_EVP=	bio_b64.c bio_enc.c bio_md.c c_all.c digest.c e_aes.c \
 		e_idea.c e_null.c e_old.c e_rc2.c e_rc4.c e_rc4_hmac_md5.c \
 		e_xcbc_d.c encode.c evp_aead.c evp_enc.c evp_err.c evp_key.c \
 		evp_lib.c evp_pbe.c evp_pkey.c m_dss.c m_dss1.c m_ecdsa.c \
-		m_gost2814789.c m_gostr341194.c m_md4.c m_md5.c m_null.c \
-		m_ripemd.c m_sha1.c m_sigver.c m_streebog.c m_wp.c names.c \
-		p5_crpt.c p5_crpt2.c p_dec.c p_enc.c p_lib.c p_open.c \
+		m_gost2814789.c m_gostr341194.c m_md4.c m_md5.c m_md5_sha1.c \
+		m_null.c m_ripemd.c m_sha1.c m_sigver.c m_streebog.c m_wp.c \
+		names.c p5_crpt.c p5_crpt2.c p_dec.c p_enc.c p_lib.c p_open.c \
 		p_seal.c p_sign.c p_verify.c pmeth_fn.c pmeth_gn.c \
 		pmeth_lib.c
 SRC_GOST=	gost2814789.c gost89_keywrap.c gost89_params.c gost89imit_ameth.c \
 		gost89imit_pmeth.c gost_asn1.c gost_err.c gostr341001.c \
 		gostr341001_ameth.c gostr341001_key.c gostr341001_params.c \
 		gostr341001_pmeth.c gostr341194.c streebog.c
+SRC_HKDF=	hkdf.c
 SRC_HMAC=	hm_ameth.c hm_pmeth.c hmac.c
 SRC_IDEA=	i_cbc.c i_cfb64.c i_ecb.c i_ofb64.c i_skey.c
-SRC_KRB5=	krb5_asn.c
 SRC_LHASH=	lh_stats.c lhash.c
 SRC_MD4=	md4_dgst.c md4_one.c
 SRC_MD5=	md5_dgst.c md5_one.c
@@ -170,7 +175,7 @@ SRC_RIPEMD=	rmd_dgst.c rmd_one.c
 SRC_RSA=	rsa_ameth.c rsa_asn1.c rsa_chk.c rsa_crpt.c rsa_depr.c \
 		rsa_eay.c rsa_err.c rsa_gen.c rsa_lib.c rsa_none.c \
 		rsa_oaep.c rsa_pk1.c rsa_pmeth.c rsa_prn.c rsa_pss.c \
-		rsa_saos.c rsa_sign.c rsa_ssl.c rsa_x931.c
+		rsa_saos.c rsa_sign.c rsa_x931.c
 SRC_SHA=	sha1_one.c sha1dgst.c sha256.c sha512.c
 SRC_STACK=	stack.c
 SRC_TS=		ts_asn1.c ts_conf.c ts_err.c ts_lib.c ts_req_print.c \
@@ -194,10 +199,10 @@ SRC_X509V3=	pcy_cache.c pcy_data.c pcy_lib.c pcy_map.c pcy_node.c \
 
 SRCS=		${ASM_X86_64_ELF} ${SRC_TOP} ${SRC_AES} ${SRC_ASN1} \
 		${SRC_BF} ${SRC_BIO} ${SRC_BN} ${SRC_BUFFER} ${SRC_CAMELLIA} \
-		${SRC_CAST} ${SRC_CHACHA} ${SRC_CMAC} ${SRC_COMP} \
-		${SRC_CONF} ${SRC_DES} ${SRC_DH} ${SRC_DSA} ${SRC_DSO} \
+		${SRC_CAST} ${SRC_CHACHA} ${SRC_CMAC} ${SRC_COMP} ${SRC_CONF} \
+		${SRC_CURVE25519} ${SRC_DES} ${SRC_DH} ${SRC_DSA} ${SRC_DSO} \
 		${SRC_EC} ${SRC_ECDH} ${SRC_ECDSA} ${SRC_ENGINE} ${SRC_ERR} \
-		${SRC_EVP} ${SRC_GOST} ${SRC_HMAC} ${SRC_IDEA} ${SRC_KRB5} \
+		${SRC_EVP} ${SRC_GOST} ${SRC_HKDF} ${SRC_HMAC} ${SRC_IDEA} \
 		${SRC_LHASH} ${SRC_MD4} ${SRC_MD5} ${SRC_MODES} \
 		${SRC_OBJECTS} ${SRC_OCSP} ${SRC_PEM} ${SRC_PKCS12} \
 		${SRC_PKCS7} ${SRC_POLY1305} ${SRC_RAND} ${SRC_RC2} \
@@ -219,6 +224,7 @@ SRCS=		${ASM_X86_64_ELF} ${SRC_TOP} ${SRC_AES} ${SRC_ASN1} \
 	${LCRYPTO_SRC}/comp \
 	${LCRYPTO_SRC}/compat \
 	${LCRYPTO_SRC}/conf \
+	${LCRYPTO_SRC}/curve25519 \
 	${LCRYPTO_SRC}/des \
 	${LCRYPTO_SRC}/dh \
 	${LCRYPTO_SRC}/dsa \
@@ -230,6 +236,7 @@ SRCS=		${ASM_X86_64_ELF} ${SRC_TOP} ${SRC_AES} ${SRC_ASN1} \
 	${LCRYPTO_SRC}/err \
 	${LCRYPTO_SRC}/evp \
 	${LCRYPTO_SRC}/gost \
+	${LCRYPTO_SRC}/hkdf \
 	${LCRYPTO_SRC}/hmac \
 	${LCRYPTO_SRC}/idea \
 	${LCRYPTO_SRC}/krb5 \
@@ -259,6 +266,7 @@ SRCS=		${ASM_X86_64_ELF} ${SRC_TOP} ${SRC_AES} ${SRC_ASN1} \
 	${LIBRESSL_SRC}/include/openssl
 
 # compat/
-SRCS+=	explicit_bzero.c reallocarray.c timingsafe_bcmp.c timingsafe_memcmp.c
+SRCS+=	explicit_bzero.c freezero.c recallocarray.c reallocarray.c \
+	timingsafe_bcmp.c timingsafe_memcmp.c
 
 .include <bsd.lib.mk>
diff --git a/lib/librecrypto/Makefile.inc b/lib/librecrypto/Makefile.inc
index 563696eeb6..8910374a00 100644
--- a/lib/librecrypto/Makefile.inc
+++ b/lib/librecrypto/Makefile.inc
@@ -45,7 +45,10 @@ CFLAGS+=	-DSTDC_HEADERS=1 \
 		-DHAVE___VA_COPY=1 \
 		-DHAS_GNU_WARNING_LONG=1 \
 		-DSIZEOF_TIME_T=8
-CFLAGS+=	-DLIBRESSL_INTERNAL -DOPENSSL_NO_HW_PADLOCK
+CFLAGS+=	-DLIBRESSL_INTERNAL \
+		-D__BEGIN_HIDDEN_DECLS= \
+		-D__END_HIDDEN_DECLS= \
+		-DOPENSSL_NO_HW_PADLOCK
 
 .if defined(LIB)
 _docs=	${LIB}
diff --git a/lib/libressl/Makefile b/lib/libressl/Makefile
index d351302f44..84a637ca20 100644
--- a/lib/libressl/Makefile
+++ b/lib/libressl/Makefile
@@ -12,11 +12,13 @@ WARNS?=		2
 libssl_la_SOURCES= \
 	bio_ssl.c bs_ber.c bs_cbb.c bs_cbs.c d1_both.c \
 	d1_clnt.c d1_enc.c d1_lib.c d1_meth.c d1_pkt.c d1_srtp.c \
-	d1_srvr.c pqueue.c s23_clnt.c s23_lib.c s23_pkt.c s23_srvr.c \
-	s3_both.c s3_cbc.c s3_clnt.c s3_lib.c s3_pkt.c s3_srvr.c \
-	ssl_algs.c ssl_asn1.c ssl_cert.c ssl_ciph.c ssl_err.c \
-	ssl_err2.c ssl_lib.c ssl_rsa.c ssl_sess.c ssl_stat.c ssl_txt.c \
-	t1_clnt.c t1_enc.c t1_lib.c t1_meth.c t1_reneg.c t1_srvr.c
+	d1_srvr.c pqueue.c \
+	s3_cbc.c s3_lib.c \
+	ssl_algs.c ssl_asn1.c ssl_both.c ssl_cert.c ssl_ciph.c ssl_clnt.c \
+	ssl_err.c ssl_lib.c ssl_packet.c ssl_pkt.c ssl_rsa.c \
+	ssl_sess.c ssl_srvr.c ssl_stat.c ssl_tlsext.c ssl_txt.c \
+	ssl_versions.c \
+	t1_clnt.c t1_enc.c t1_hash.c t1_lib.c t1_meth.c t1_srvr.c
 
 SRCS=	${libssl_la_SOURCES}
 
diff --git a/usr.bin/nc/Makefile b/usr.bin/nc/Makefile
index 804040c161..d57d9e24ca 100644
--- a/usr.bin/nc/Makefile
+++ b/usr.bin/nc/Makefile
@@ -5,9 +5,11 @@ PROG=	nc
 SRCS=	netcat.c atomicio.c socks.c
 
 # TLS block (no separate libtls.a)
-SRCS+=	tls_client.c	\
+SRCS+=	tls_bio_cb.c	\
+	tls_client.c	\
 	tls_config.c	\
 	tls_conninfo.c	\
+	tls_ocsp.c	\
 	tls_peer.c	\
 	tls_server.c	\
 	tls_util.c	\
@@ -17,6 +19,8 @@ SRCS+=	tls_client.c	\
 WARNS?=	2
 
 CFLAGS+=-DHAVE_ARC4RANDOM_BUF -DHAVE_STRTONUM	\
+	-D__BEGIN_HIDDEN_DECLS=			\
+	-D__END_HIDDEN_DECLS=			\
 	-I${.CURDIR}/../../crypto/libressl/include		\
 	-I${.CURDIR}/../../crypto/libressl/include/compat
 
diff --git a/usr.bin/openssl/Makefile b/usr.bin/openssl/Makefile
index 464bd92754..ea4a189c8b 100644
--- a/usr.bin/openssl/Makefile
+++ b/usr.bin/openssl/Makefile
@@ -12,7 +12,7 @@ LDFLAGS+=	${PRIVATELIB_LDFLAGS}
 CFLAGS+=	-I${.CURDIR}/../../crypto/libressl/include
 CFLAGS+= 	-DMONOLITH -I${.CURDIR}
 
-SRCS=	apps.c apps_posix.c asn1pars.c ca.c certhash.c ciphers.c cms.c crl.c \
+SRCS=	apps.c apps_posix.c asn1pars.c ca.c certhash.c ciphers.c crl.c \
 	crl2p7.c dgst.c dh.c dhparam.c dsa.c dsaparam.c ec.c ecparam.c enc.c \
 	errstr.c gendh.c gendsa.c genpkey.c genrsa.c nseq.c ocsp.c \
 	openssl.c passwd.c pkcs12.c pkcs7.c pkcs8.c pkey.c pkeyparam.c \
