e55890
diff --git a/bin/Makefile.in b/bin/Makefile.in
e55890
index f0c504a..ce7a2da 100644
e55890
--- a/bin/Makefile.in
e55890
+++ b/bin/Makefile.in
e55890
@@ -11,8 +11,8 @@ srcdir =	@srcdir@
e55890
 VPATH =		@srcdir@
e55890
 top_srcdir =	@top_srcdir@
e55890
 
e55890
-SUBDIRS =	named rndc dig delv dnssec tools nsupdate check confgen \
e55890
-		@NZD_TOOLS@ @PYTHON_TOOLS@ @PKCS11_TOOLS@ tests
e55890
+SUBDIRS =	named named-pkcs11 rndc dig delv dnssec dnssec-pkcs11 tools nsupdate \
e55890
+		check confgen @NZD_TOOLS@ @PYTHON_TOOLS@ @PKCS11_TOOLS@ tests
e55890
 TARGETS =
e55890
 
e55890
 @BIND9_MAKE_RULES@
e55890
diff --git a/bin/dnssec-pkcs11/Makefile.in b/bin/dnssec-pkcs11/Makefile.in
e55890
index 1d0c4ce..7b7f89b 100644
e55890
--- a/bin/dnssec-pkcs11/Makefile.in
e55890
+++ b/bin/dnssec-pkcs11/Makefile.in
e55890
@@ -17,18 +17,18 @@ VERSION=@BIND9_VERSION@
e55890
 
e55890
 @BIND9_MAKE_INCLUDES@
e55890
 
e55890
-CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} @DST_OPENSSL_INC@
e55890
+CINCLUDES =	${DNS_PKCS11_INCLUDES} ${ISC_PKCS11_INCLUDES}
e55890
 
e55890
 CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
e55890
-		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
e55890
+		@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
e55890
 CWARNINGS =
e55890
 
e55890
-DNSLIBS =	../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
e55890
-ISCLIBS =	../../lib/isc/libisc.@A@
e55890
-ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
e55890
+DNSLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@ @DNS_CRYPTO_LIBS@
e55890
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
e55890
+ISCNOSYMLIBS =	../../lib/isc-pkcs11/libisc-pkcs11-nosymtbl.@A@
e55890
 
e55890
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
e55890
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
e55890
+DNSDEPLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@
e55890
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
e55890
 
e55890
 DEPLIBS =	${DNSDEPLIBS} ${ISCDEPLIBS}
e55890
 
e55890
@@ -37,10 +37,10 @@ LIBS =		${DNSLIBS} ${ISCLIBS} @LIBS@
e55890
 NOSYMLIBS =	${DNSLIBS} ${ISCNOSYMLIBS} @LIBS@
e55890
 
e55890
 # Alphabetically
e55890
-TARGETS =	dnssec-keygen@EXEEXT@ dnssec-signzone@EXEEXT@ \
e55890
-		dnssec-keyfromlabel@EXEEXT@ dnssec-dsfromkey@EXEEXT@ \
e55890
-		dnssec-revoke@EXEEXT@ dnssec-settime@EXEEXT@ \
e55890
-		dnssec-verify@EXEEXT@ dnssec-importkey@EXEEXT@
e55890
+TARGETS =	dnssec-keygen-pkcs11@EXEEXT@ dnssec-signzone-pkcs11@EXEEXT@ \
e55890
+		dnssec-keyfromlabel-pkcs11@EXEEXT@ dnssec-dsfromkey-pkcs11@EXEEXT@ \
e55890
+		dnssec-revoke-pkcs11@EXEEXT@ dnssec-settime-pkcs11@EXEEXT@ \
e55890
+		dnssec-verify-pkcs11@EXEEXT@ dnssec-importkey-pkcs11@EXEEXT@
e55890
 
e55890
 OBJS =		dnssectool.@O@
e55890
 
e55890
@@ -61,15 +61,15 @@ MANOBJS =	${MANPAGES} ${HTMLPAGES}
e55890
 
e55890
 @BIND9_MAKE_RULES@
e55890
 
e55890
-dnssec-dsfromkey@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-dsfromkey-pkcs11@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
e55890
 	export BASEOBJS="dnssec-dsfromkey.@O@ ${OBJS}"; \
e55890
 	${FINALBUILDCMD}
e55890
 
e55890
-dnssec-keyfromlabel@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-keyfromlabel-pkcs11@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
e55890
 	export BASEOBJS="dnssec-keyfromlabel.@O@ ${OBJS}"; \
e55890
 	${FINALBUILDCMD}
e55890
 
e55890
-dnssec-keygen@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-keygen-pkcs11@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
e55890
 	export BASEOBJS="dnssec-keygen.@O@ ${OBJS}"; \
e55890
 	${FINALBUILDCMD}
e55890
 
e55890
@@ -77,7 +77,7 @@ dnssec-signzone.@O@: dnssec-signzone.c
e55890
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
e55890
 		-c ${srcdir}/dnssec-signzone.c
e55890
 
e55890
-dnssec-signzone@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-signzone-pkcs11@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
e55890
 	export BASEOBJS="dnssec-signzone.@O@ ${OBJS}"; \
e55890
 	${FINALBUILDCMD}
e55890
 
e55890
@@ -85,19 +85,19 @@ dnssec-verify.@O@: dnssec-verify.c
e55890
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
e55890
 		-c ${srcdir}/dnssec-verify.c
e55890
 
e55890
-dnssec-verify@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-verify-pkcs11@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
e55890
 	export BASEOBJS="dnssec-verify.@O@ ${OBJS}"; \
e55890
 	${FINALBUILDCMD}
e55890
 
e55890
-dnssec-revoke@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-revoke-pkcs11@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
e55890
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
e55890
 	dnssec-revoke.@O@ ${OBJS} ${LIBS}
e55890
 
e55890
-dnssec-settime@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-settime-pkcs11@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
e55890
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
e55890
 	dnssec-settime.@O@ ${OBJS} ${LIBS}
e55890
 
e55890
-dnssec-importkey@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
e55890
+dnssec-importkey-pkcs11@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
e55890
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
e55890
 	dnssec-importkey.@O@ ${OBJS} ${LIBS}
e55890
 
e55890
@@ -108,16 +108,14 @@ docclean manclean maintainer-clean::
e55890
 
e55890
 installdirs:
e55890
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${sbindir}
e55890
-	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man8
e55890
 
e55890
 install-man8: ${MANPAGES}
e55890
 	${INSTALL_DATA} $^ ${DESTDIR}${mandir}/man8
e55890
 
e55890
-install:: ${TARGETS} installdirs install-man8
e55890
+install:: ${TARGETS} installdirs
e55890
 	for t in ${TARGETS}; do ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} $$t ${DESTDIR}${sbindir}; done
e55890
 
e55890
 uninstall::
e55890
-	for m in ${MANPAGES}; do rm -f ${DESTDIR}${mandir}/man8/$$m ; done
e55890
 	for t in ${TARGETS}; do ${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/$$t ; done
e55890
 
e55890
 clean distclean::
e55890
diff --git a/bin/dnssec/Makefile.in b/bin/dnssec/Makefile.in
e55890
index 1d0c4ce..11538cf 100644
e55890
--- a/bin/dnssec/Makefile.in
e55890
+++ b/bin/dnssec/Makefile.in
e55890
@@ -19,7 +19,7 @@ VERSION=@BIND9_VERSION@
e55890
 
e55890
 CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} @DST_OPENSSL_INC@
e55890
 
e55890
-CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
e55890
+CDEFINES =	-DVERSION=\"${VERSION}\" \
e55890
 		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
e55890
 CWARNINGS =
e55890
 
e55890
diff --git a/bin/named-pkcs11/Makefile.in b/bin/named-pkcs11/Makefile.in
e55890
index d92bc9a..a8c42a4 100644
e55890
--- a/bin/named-pkcs11/Makefile.in
e55890
+++ b/bin/named-pkcs11/Makefile.in
e55890
@@ -43,26 +43,26 @@ DLZDRIVER_INCLUDES =	@DLZ_DRIVER_INCLUDES@
e55890
 DLZDRIVER_LIBS =	@DLZ_DRIVER_LIBS@
e55890
 
e55890
 CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
e55890
-		${LWRES_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES} \
e55890
-		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_INCLUDES} \
e55890
+        ${LWRES_INCLUDES} ${DNS_PKCS11_INCLUDES} ${BIND9_INCLUDES} \
e55890
+        ${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_PKCS11_INCLUDES} \
e55890
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} @DST_OPENSSL_INC@
e55890
 
e55890
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
e55890
+CDEFINES =      @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO_PK11@
e55890
 
e55890
 CWARNINGS =
e55890
 
e55890
-DNSLIBS =	../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
e55890
+DNSLIBS =  ../../lib/dns-pkcs11/libdns-pkcs11.@A@ @DNS_CRYPTO_LIBS@
e55890
 ISCCFGLIBS =	../../lib/isccfg/libisccfg.@A@
e55890
 ISCCCLIBS =	../../lib/isccc/libisccc.@A@
e55890
-ISCLIBS =	../../lib/isc/libisc.@A@
e55890
+ISCLIBS =  ../../lib/isc-pkcs11/libisc-pkcs11.@A@
e55890
 ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
e55890
 LWRESLIBS =	../../lib/lwres/liblwres.@A@
e55890
 BIND9LIBS =	../../lib/bind9/libbind9.@A@
e55890
 
e55890
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
e55890
+DNSDEPLIBS =   ../../lib/dns-pkcs11/libdns-pkcs11.@A@
e55890
 ISCCFGDEPLIBS =	../../lib/isccfg/libisccfg.@A@
e55890
 ISCCCDEPLIBS =	../../lib/isccc/libisccc.@A@
e55890
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
e55890
+ISCDEPLIBS =   ../../lib/isc-pkcs11/libisc-pkcs11.@A@
e55890
 LWRESDEPLIBS =	../../lib/lwres/liblwres.@A@
e55890
 BIND9DEPLIBS =	../../lib/bind9/libbind9.@A@
e55890
 
e55890
@@ -71,15 +71,15 @@ DEPLIBS =	${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
e55890
 
e55890
 LIBS =		${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
e55890
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} \
e55890
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
e55890
+		@LIBS@
e55890
 
e55890
 NOSYMLIBS =	${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
e55890
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCNOSYMLIBS} \
e55890
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
e55890
+        @LIBS@
e55890
 
e55890
 SUBDIRS =	unix
e55890
 
e55890
-TARGETS =	named@EXEEXT@ lwresd@EXEEXT@
e55890
+TARGETS =  named-pkcs11@EXEEXT@
e55890
 
e55890
 GEOIPLINKOBJS = geoip.@O@
e55890
 
e55890
@@ -90,8 +90,7 @@ OBJS =		builtin.@O@ client.@O@ config.@O@ control.@O@ \
e55890
 		tkeyconf.@O@ tsigconf.@O@ update.@O@ xfrout.@O@ \
e55890
 		zoneconf.@O@ \
e55890
 		lwaddr.@O@ lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
e55890
-		lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@ \
e55890
-		${DLZDRIVER_OBJS} ${DBDRIVER_OBJS}
e55890
+        lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@
e55890
 
e55890
 UOBJS =		unix/os.@O@ unix/dlz_dlopen_driver.@O@
e55890
 
e55890
@@ -106,8 +105,7 @@ SRCS =		builtin.c client.c config.c control.c \
e55890
 		tkeyconf.c tsigconf.c update.c xfrout.c \
e55890
 		zoneconf.c \
e55890
 		lwaddr.c lwresd.c lwdclient.c lwderror.c lwdgabn.c \
e55890
-		lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c \
e55890
-		${DLZDRIVER_SRCS} ${DBDRIVER_SRCS}
e55890
+        lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c
e55890
 
e55890
 MANPAGES =	named.8 lwresd.8 named.conf.5
e55890
 
e55890
@@ -146,14 +144,14 @@ server.@O@: server.c
e55890
 		-DPRODUCT=\"${PRODUCT}\" \
e55890
 		-DVERSION=\"${VERSION}\" -c ${srcdir}/server.c
e55890
 
e55890
-named@EXEEXT@: ${OBJS} ${DEPLIBS}
e55890
+named-pkcs11@EXEEXT@: ${OBJS} ${DEPLIBS}
e55890
 	export MAKE_SYMTABLE="yes"; \
e55890
 	export BASEOBJS="${OBJS} ${UOBJS}"; \
e55890
 	${FINALBUILDCMD}
e55890
 
e55890
-lwresd@EXEEXT@: named@EXEEXT@
e55890
+lwresd@EXEEXT@: named-pkcs11@EXEEXT@
e55890
 	rm -f lwresd@EXEEXT@
e55890
-	@LN@ named@EXEEXT@ lwresd@EXEEXT@
e55890
+	@LN@ named-pkcs11@EXEEXT@ lwresd@EXEEXT@
e55890
 
e55890
 doc man:: ${MANOBJS}
e55890
 
e55890
@@ -184,16 +182,11 @@ install-man8: named.8 lwresd.8
e55890
 
e55890
 install-man: install-man5 install-man8
e55890
 
e55890
-install:: named@EXEEXT@ lwresd@EXEEXT@ installdirs install-man
e55890
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named@EXEEXT@ ${DESTDIR}${sbindir}
e55890
-	(cd ${DESTDIR}${sbindir}; rm -f lwresd@EXEEXT@; @LN@ named@EXEEXT@ lwresd@EXEEXT@)
e55890
+install:: named-pkcs11@EXEEXT@ installdirs
e55890
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named-pkcs11@EXEEXT@ ${DESTDIR}${sbindir}
e55890
 
e55890
 uninstall::
e55890
-	rm -f ${DESTDIR}${mandir}/man5/named.conf.5
e55890
-	rm -f ${DESTDIR}${mandir}/man8/lwresd.8
e55890
-	rm -f ${DESTDIR}${mandir}/man8/named.8
e55890
-	rm -f ${DESTDIR}${sbindir}/lwresd@EXEEXT@
e55890
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/named@EXEEXT@
e55890
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/named-pkcs11@EXEEXT@
e55890
 
e55890
 @DLZ_DRIVER_RULES@
e55890
 
e55890
diff --git a/bin/named/Makefile.in b/bin/named/Makefile.in
e55890
index d92bc9a..6d2bfd1 100644
e55890
--- a/bin/named/Makefile.in
e55890
+++ b/bin/named/Makefile.in
e55890
@@ -47,7 +47,7 @@ CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
e55890
 		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_INCLUDES} \
e55890
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} @DST_OPENSSL_INC@
e55890
 
e55890
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
e55890
+CDEFINES =      @CONTRIB_DLZ@ @CRYPTO@
e55890
 
e55890
 CWARNINGS =
e55890
 
e55890
diff --git a/bin/pkcs11/Makefile.in b/bin/pkcs11/Makefile.in
e55890
index a058c91..d4b689a 100644
e55890
--- a/bin/pkcs11/Makefile.in
e55890
+++ b/bin/pkcs11/Makefile.in
e55890
@@ -15,13 +15,13 @@ top_srcdir =	@top_srcdir@
e55890
 
e55890
 @BIND9_MAKE_INCLUDES@
e55890
 
e55890
-CINCLUDES =	${ISC_INCLUDES}
e55890
+CINCLUDES =	${ISC_PKCS11_INCLUDES}
e55890
 
e55890
 CDEFINES =
e55890
 
e55890
-ISCLIBS =	../../lib/isc/libisc.@A@ @ISC_OPENSSL_LIBS@
e55890
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@ @ISC_OPENSSL_LIBS@
e55890
 
e55890
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
e55890
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
e55890
 
e55890
 DEPLIBS =	${ISCDEPLIBS}
e55890
 
e55890
diff --git a/configure.in b/configure.in
e55890
index 849fa94..69e6373 100644
e55890
--- a/configure.in
e55890
+++ b/configure.in
e55890
@@ -1164,12 +1164,14 @@ AC_SUBST(USE_GSSAPI)
e55890
 AC_SUBST(DST_GSSAPI_INC)
e55890
 AC_SUBST(DNS_GSSAPI_LIBS)
e55890
 DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_LIBS"
e55890
+DNS_CRYPTO_PK11_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_PK11_LIBS"
e55890
 
e55890
 #
e55890
 # Applications linking with libdns also need to link with these libraries.
e55890
 #
e55890
 
e55890
 AC_SUBST(DNS_CRYPTO_LIBS)
e55890
+AC_SUBST(DNS_CRYPTO_PK11_LIBS)
e55890
 
e55890
 #
e55890
 # was --with-randomdev specified?
e55890
@@ -1554,11 +1556,11 @@ fi
e55890
 AC_MSG_CHECKING(for OpenSSL library)
e55890
 OPENSSL_WARNING=
e55890
 openssldirs="/usr /usr/local /usr/local/ssl /usr/pkg /usr/sfw"
e55890
-if test "yes" = "$want_native_pkcs11"
e55890
-then
e55890
-	use_openssl="native_pkcs11"
e55890
-	AC_MSG_RESULT(use of native PKCS11 instead)
e55890
-fi
e55890
+# if test "yes" = "$want_native_pkcs11"
e55890
+# then
e55890
+# 	use_openssl="native_pkcs11"
e55890
+# 	AC_MSG_RESULT(use of native PKCS11 instead)
e55890
+# fi
e55890
 
e55890
 if test "auto" = "$use_openssl"
e55890
 then
e55890
@@ -1571,6 +1573,7 @@ then
e55890
 		fi
e55890
 	done
e55890
 fi
e55890
+CRYPTO_PK11=""
e55890
 OPENSSL_ECDSA=""
e55890
 OPENSSL_GOST=""
e55890
 OPENSSL_ED25519=""
e55890
@@ -1592,11 +1595,10 @@ case "$with_gost" in
e55890
 		;;
e55890
 esac
e55890
 
e55890
-case "$use_openssl" in
e55890
-	native_pkcs11)
e55890
-		AC_MSG_RESULT(disabled because of native PKCS11)
e55890
+if test "$want_native_pkcs11" = "yes"
e55890
+then
e55890
 		DST_OPENSSL_INC=""
e55890
-		CRYPTO="-DPKCS11CRYPTO"
e55890
+		CRYPTO_PK11="-DPKCS11CRYPTO"
e55890
 		CRYPTOLIB="pkcs11"
e55890
 		OPENSSLECDSALINKOBJS=""
e55890
 		OPENSSLECDSALINKSRCS=""
e55890
@@ -1606,7 +1608,9 @@ case "$use_openssl" in
e55890
 		OPENSSLGOSTLINKSRCS=""
e55890
 		OPENSSLLINKOBJS=""
e55890
 		OPENSSLLINKSRCS=""
e55890
-		;;
e55890
+fi
e55890
+
e55890
+case "$use_openssl" in
e55890
 	no)
e55890
 		AC_MSG_RESULT(no)
e55890
 		DST_OPENSSL_INC=""
e55890
@@ -1638,7 +1642,7 @@ case "$use_openssl" in
e55890
 If you do not want OpenSSL, use --without-openssl])
e55890
 		;;
e55890
 	*)
e55890
-		if test "yes" = "$want_native_pkcs11"
e55890
+		if false # test "yes" = "$want_native_pkcs11"
e55890
 		then
e55890
 			AC_MSG_RESULT()
e55890
 			AC_MSG_ERROR([OpenSSL and native PKCS11 cannot be used together.])
e55890
@@ -2066,6 +2070,7 @@ AC_SUBST(OPENSSL_ED25519)
e55890
 AC_SUBST(OPENSSL_GOST)
e55890
 
e55890
 DNS_CRYPTO_LIBS="$DNS_CRYPTO_LIBS $DST_OPENSSL_LIBS"
e55890
+DNS_CRYPTO_PK11_LIBS="$DNS_CRYPTO_LIBS"
e55890
 
e55890
 ISC_PLATFORM_WANTAES="#undef ISC_PLATFORM_WANTAES"
e55890
 if test "yes" = "$with_aes"
e55890
@@ -2384,6 +2389,7 @@ esac
e55890
 AC_SUBST(PKCS11LINKOBJS)
e55890
 AC_SUBST(PKCS11LINKSRCS)
e55890
 AC_SUBST(CRYPTO)
e55890
+AC_SUBST(CRYPTO_PK11)
e55890
 AC_SUBST(PKCS11_ECDSA)
e55890
 AC_SUBST(PKCS11_GOST)
e55890
 AC_SUBST(PKCS11_ED25519)
e55890
@@ -5497,8 +5503,11 @@ AC_CONFIG_FILES([
e55890
 	bin/delv/Makefile
e55890
 	bin/dig/Makefile
e55890
 	bin/dnssec/Makefile
e55890
+	bin/dnssec-pkcs11/Makefile	
e55890
 	bin/named/Makefile
e55890
 	bin/named/unix/Makefile
e55890
+	bin/named-pkcs11/Makefile
e55890
+	bin/named-pkcs11/unix/Makefile
e55890
 	bin/nsupdate/Makefile
e55890
 	bin/pkcs11/Makefile
e55890
 	bin/python/Makefile
e55890
@@ -5572,6 +5581,10 @@ AC_CONFIG_FILES([
e55890
 	lib/dns/include/dns/Makefile
e55890
 	lib/dns/include/dst/Makefile
e55890
 	lib/dns/tests/Makefile
e55890
+	lib/dns-pkcs11/Makefile
e55890
+	lib/dns-pkcs11/include/Makefile
e55890
+	lib/dns-pkcs11/include/dns/Makefile
e55890
+	lib/dns-pkcs11/include/dst/Makefile
e55890
 	lib/irs/Makefile
e55890
 	lib/irs/include/Makefile
e55890
 	lib/irs/include/irs/Makefile
e55890
@@ -5596,6 +5609,24 @@ AC_CONFIG_FILES([
e55890
 	lib/isc/unix/include/Makefile
e55890
 	lib/isc/unix/include/isc/Makefile
e55890
 	lib/isc/unix/include/pkcs11/Makefile
e55890
+	lib/isc-pkcs11/$arch/Makefile
e55890
+	lib/isc-pkcs11/$arch/include/Makefile
e55890
+	lib/isc-pkcs11/$arch/include/isc/Makefile
e55890
+	lib/isc-pkcs11/$thread_dir/Makefile
e55890
+	lib/isc-pkcs11/$thread_dir/include/Makefile
e55890
+	lib/isc-pkcs11/$thread_dir/include/isc/Makefile
e55890
+	lib/isc-pkcs11/Makefile
e55890
+	lib/isc-pkcs11/include/Makefile
e55890
+	lib/isc-pkcs11/include/isc/Makefile
e55890
+	lib/isc-pkcs11/include/isc/platform.h
e55890
+	lib/isc-pkcs11/include/pk11/Makefile
e55890
+	lib/isc-pkcs11/include/pkcs11/Makefile
e55890
+	lib/isc-pkcs11/tests/Makefile
e55890
+	lib/isc-pkcs11/nls/Makefile
e55890
+	lib/isc-pkcs11/unix/Makefile
e55890
+	lib/isc-pkcs11/unix/include/Makefile
e55890
+	lib/isc-pkcs11/unix/include/isc/Makefile
e55890
+	lib/isc-pkcs11/unix/include/pkcs11/Makefile
e55890
 	lib/isccc/Makefile
e55890
 	lib/isccc/include/Makefile
e55890
 	lib/isccc/include/isccc/Makefile
e55890
diff --git a/lib/Makefile.in b/lib/Makefile.in
e55890
index 81270a0..bcb5312 100644
e55890
--- a/lib/Makefile.in
e55890
+++ b/lib/Makefile.in
e55890
@@ -15,7 +15,7 @@ top_srcdir =	@top_srcdir@
e55890
 # Attempt to disable parallel processing.
e55890
 .NOTPARALLEL:
e55890
 .NO_PARALLEL:
e55890
-SUBDIRS =	isc isccc dns isccfg bind9 lwres irs samples
e55890
+SUBDIRS =	isc isc-pkcs11 isccc dns dns-pkcs11 isccfg bind9 lwres irs samples
e55890
 TARGETS =
e55890
 
e55890
 @BIND9_MAKE_RULES@
e55890
diff --git a/lib/dns-pkcs11/Makefile.in b/lib/dns-pkcs11/Makefile.in
e55890
index 4a8549e..6a19906 100644
e55890
--- a/lib/dns-pkcs11/Makefile.in
e55890
+++ b/lib/dns-pkcs11/Makefile.in
e55890
@@ -26,16 +26,16 @@ VERSION=@BIND9_VERSION@
e55890
 
e55890
 USE_ISC_SPNEGO = @USE_ISC_SPNEGO@
e55890
 
e55890
-CINCLUDES =	-I. -I${top_srcdir}/lib/dns -Iinclude ${DNS_INCLUDES} \
e55890
-		${ISC_INCLUDES} @DST_OPENSSL_INC@ @DST_GSSAPI_INC@
e55890
+CINCLUDES =	-I. -I${top_srcdir}/lib/dns-pkcs11 -Iinclude ${DNS_PKCS11_INCLUDES} \
e55890
+		${ISC_PKCS11_INCLUDES} @DST_OPENSSL_INC@ @DST_GSSAPI_INC@
e55890
 
e55890
-CDEFINES =	-DUSE_MD5 @CRYPTO@ @USE_GSSAPI@ ${USE_ISC_SPNEGO}
e55890
+CDEFINES =	-DUSE_MD5 @CRYPTO_PK11@ @USE_GSSAPI@ ${USE_ISC_SPNEGO}
e55890
 
e55890
 CWARNINGS =
e55890
 
e55890
-ISCLIBS =	../../lib/isc/libisc.@A@
e55890
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
e55890
 
e55890
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
e55890
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
e55890
 
e55890
 LIBS =		@LIBS@
e55890
 
e55890
@@ -146,15 +146,15 @@ version.@O@: version.c
e55890
 		-DLIBAGE=${LIBAGE} \
e55890
 		-c ${srcdir}/version.c
e55890
 
e55890
-libdns.@SA@: ${OBJS}
e55890
+libdns-pkcs11.@SA@: ${OBJS}
e55890
 	${AR} ${ARFLAGS} $@ ${OBJS}
e55890
 	${RANLIB} $@
e55890
 
e55890
-libdns.la: ${OBJS}
e55890
+libdns-pkcs11.la: ${OBJS}
e55890
 	${LIBTOOL_MODE_LINK} \
e55890
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns.la -rpath ${libdir} \
e55890
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns-pkcs11.la -rpath ${libdir} \
e55890
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
e55890
-		${OBJS} ${ISCLIBS} @DNS_CRYPTO_LIBS@ ${LIBS}
e55890
+		${OBJS} ${ISCLIBS} @DNS_CRYPTO_PK11_LIBS@ ${LIBS}
e55890
 
e55890
 include: gen
e55890
 	${MAKE} include/dns/enumtype.h
e55890
@@ -180,25 +180,25 @@ code.h:	gen
e55890
 	./gen -s ${srcdir} > code.h || { rm -f $@ ; exit 1; }
e55890
 
e55890
 gen: gen.c
e55890
-	${BUILD_CC} ${BUILD_CFLAGS} -I${top_srcdir}/lib/isc/include \
e55890
+	${BUILD_CC} ${BUILD_CFLAGS} -I${top_srcdir}/lib/isc-pkcs11/include \
e55890
 	${BUILD_CPPFLAGS} ${BUILD_LDFLAGS} -o $@ ${srcdir}/gen.c ${BUILD_LIBS}
e55890
 
e55890
-timestamp: include libdns.@A@
e55890
+timestamp: include libdns-pkcs11.@A@
e55890
 	touch timestamp
e55890
 
e55890
-testdirs: libdns.@A@
e55890
+testdirs: libdns-pkcs11.@A@
e55890
 
e55890
 installdirs:
e55890
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
e55890
 
e55890
 install:: timestamp installdirs
e55890
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libdns.@A@ ${DESTDIR}${libdir}
e55890
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libdns-pkcs11.@A@ ${DESTDIR}${libdir}
e55890
 
e55890
 uninstall::
e55890
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libdns.@A@
e55890
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libdns-pkcs11.@A@
e55890
 
e55890
 clean distclean::
e55890
-	rm -f libdns.@A@ timestamp
e55890
+	rm -f libdns-pkcs11.@A@ timestamp
e55890
 	rm -f gen code.h include/dns/enumtype.h include/dns/enumclass.h
e55890
 	rm -f include/dns/rdatastruct.h
e55890
 	rm -f dnstap.pb-c.c dnstap.pb-c.h include/dns/dnstap.pb-c.h
e55890
diff --git a/lib/isc-pkcs11/Makefile.in b/lib/isc-pkcs11/Makefile.in
e55890
index ba53ef1..d1f1771 100644
e55890
--- a/lib/isc-pkcs11/Makefile.in
e55890
+++ b/lib/isc-pkcs11/Makefile.in
e55890
@@ -23,8 +23,8 @@ CINCLUDES =	-I${srcdir}/unix/include \
e55890
 		-I${srcdir}/@ISC_THREAD_DIR@/include \
e55890
 		-I${srcdir}/@ISC_ARCH_DIR@/include \
e55890
 		-I./include \
e55890
-		-I${srcdir}/include ${DNS_INCLUDES} @ISC_OPENSSL_INC@
e55890
-CDEFINES =	@CRYPTO@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
e55890
+		-I${srcdir}/include ${DNS_PKCS11_INCLUDES}
e55890
+CDEFINES =	@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
e55890
 CWARNINGS =
e55890
 
e55890
 # Alphabetically
e55890
@@ -107,40 +107,40 @@ version.@O@: version.c
e55890
 		-DLIBAGE=${LIBAGE} \
e55890
 		-c ${srcdir}/version.c
e55890
 
e55890
-libisc.@SA@: ${OBJS} ${SYMTBLOBJS}
e55890
+libisc-pkcs11.@SA@: ${OBJS} ${SYMTBLOBJS}
e55890
 	${AR} ${ARFLAGS} $@ ${OBJS} ${SYMTBLOBJS}
e55890
 	${RANLIB} $@
e55890
 
e55890
-libisc-nosymtbl.@SA@: ${OBJS}
e55890
+libisc-pkcs11-nosymtbl.@SA@: ${OBJS}
e55890
 	${AR} ${ARFLAGS} $@ ${OBJS}
e55890
 	${RANLIB} $@
e55890
 
e55890
-libisc.la: ${OBJS} ${SYMTBLOBJS}
e55890
+libisc-pkcs11.la: ${OBJS} ${SYMTBLOBJS}
e55890
 	${LIBTOOL_MODE_LINK} \
e55890
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc.la -rpath ${libdir} \
e55890
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11.la -rpath ${libdir} \
e55890
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
e55890
 		${OBJS} ${SYMTBLOBJS} ${LIBS}
e55890
 
e55890
-libisc-nosymtbl.la: ${OBJS}
e55890
+libisc-pkcs11-nosymtbl.la: ${OBJS}
e55890
 	${LIBTOOL_MODE_LINK} \
e55890
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-nosymtbl.la -rpath ${libdir} \
e55890
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11-nosymtbl.la -rpath ${libdir} \
e55890
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
e55890
 		${OBJS} ${LIBS}
e55890
 
e55890
-timestamp: libisc.@A@ libisc-nosymtbl.@A@
e55890
+timestamp: libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@
e55890
 	touch timestamp
e55890
 
e55890
-testdirs: libisc.@A@ libisc-nosymtbl.@A@
e55890
+testdirs: libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@
e55890
 
e55890
 installdirs:
e55890
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
e55890
 
e55890
 install:: timestamp installdirs
e55890
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libisc.@A@ ${DESTDIR}${libdir}
e55890
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libisc-pkcs11.@A@ ${DESTDIR}${libdir}
e55890
 
e55890
 uninstall::
e55890
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libisc.@A@
e55890
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libisc-pkcs11.@A@
e55890
 
e55890
 clean distclean::
e55890
-	rm -f libisc.@A@ libisc-nosymtbl.@A@ libisc.la \
e55890
-	libisc-nosymtbl.la timestamp
e55890
+	rm -f libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@ libisc-pkcs11.la \
e55890
+	libisc-pkcs11-nosymtbl.la timestamp
e55890
diff --git a/make/includes.in b/make/includes.in
e55890
index fa86ad1..3cfbe9f 100644
e55890
--- a/make/includes.in
e55890
+++ b/make/includes.in
e55890
@@ -43,3 +43,13 @@ BIND9_INCLUDES = @BIND9_BIND9_BUILDINCLUDE@ \
e55890
 
e55890
 TEST_INCLUDES = \
e55890
 	-I${top_srcdir}/lib/tests/include
e55890
+
e55890
+ISC_PKCS11_INCLUDES = @BIND9_ISC_BUILDINCLUDE@ \
e55890
+	-I${top_srcdir}/lib/isc-pkcs11 \
e55890
+	-I${top_srcdir}/lib/isc-pkcs11/include \
e55890
+	-I${top_srcdir}/lib/isc-pkcs11/unix/include \
e55890
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_THREAD_DIR@/include \
e55890
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_ARCH_DIR@/include
e55890
+
e55890
+DNS_PKCS11_INCLUDES = @BIND9_DNS_BUILDINCLUDE@ \
e55890
+	-I${top_srcdir}/lib/dns-pkcs11/include