2e2c49
diff --git a/bin/Makefile.in b/bin/Makefile.in
943bc6
index a18b222..26a7e4e 100644
2e2c49
--- a/bin/Makefile.in
2e2c49
+++ b/bin/Makefile.in
2e2c49
@@ -11,8 +11,8 @@ srcdir =	@srcdir@
2e2c49
 VPATH =		@srcdir@
2e2c49
 top_srcdir =	@top_srcdir@
2e2c49
 
2e2c49
-SUBDIRS =	named rndc dig delv dnssec tools nsupdate check confgen \
2e2c49
-		@NZD_TOOLS@ @PYTHON_TOOLS@ @PKCS11_TOOLS@ tests
2e2c49
+SUBDIRS =	named named-pkcs11 rndc dig delv dnssec dnssec-pkcs11 tools nsupdate \
2e2c49
+		check confgen @NZD_TOOLS@ @PYTHON_TOOLS@ @PKCS11_TOOLS@ tests
2e2c49
 TARGETS =
2e2c49
 
2e2c49
 @BIND9_MAKE_RULES@
2e2c49
diff --git a/bin/dnssec-pkcs11/Makefile.in b/bin/dnssec-pkcs11/Makefile.in
943bc6
index 390aa0c..e59a118 100644
2e2c49
--- a/bin/dnssec-pkcs11/Makefile.in
2e2c49
+++ b/bin/dnssec-pkcs11/Makefile.in
10d019
@@ -15,18 +15,18 @@ VERSION=@BIND9_VERSION@
2e2c49
 
2e2c49
 @BIND9_MAKE_INCLUDES@
2e2c49
 
2e2c49
-CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} @DST_OPENSSL_INC@
2e2c49
+CINCLUDES =	${DNS_PKCS11_INCLUDES} ${ISC_PKCS11_INCLUDES}
2e2c49
 
10d019
-CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
2e2c49
-		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
10d019
+CDEFINES =	-DVERSION=\"${VERSION}\" @PKCS11_ENGINE@ \
2e2c49
+		@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
2e2c49
 CWARNINGS =
2e2c49
 
10d019
-DNSLIBS =	../../lib/dns/libdns.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
2e2c49
-ISCLIBS =	../../lib/isc/libisc.@A@
2e2c49
-ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
10d019
+DNSLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
2e2c49
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
2e2c49
+ISCNOSYMLIBS =	../../lib/isc-pkcs11/libisc-pkcs11-nosymtbl.@A@
2e2c49
 
2e2c49
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
2e2c49
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
2e2c49
+DNSDEPLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@
2e2c49
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
2e2c49
 
2e2c49
 DEPLIBS =	${DNSDEPLIBS} ${ISCDEPLIBS}
2e2c49
 
10d019
@@ -35,10 +35,10 @@ LIBS =		${DNSLIBS} ${ISCLIBS} @LIBS@
2e2c49
 NOSYMLIBS =	${DNSLIBS} ${ISCNOSYMLIBS} @LIBS@
2e2c49
 
2e2c49
 # Alphabetically
2e2c49
-TARGETS =	dnssec-keygen@EXEEXT@ dnssec-signzone@EXEEXT@ \
2e2c49
-		dnssec-keyfromlabel@EXEEXT@ dnssec-dsfromkey@EXEEXT@ \
2e2c49
-		dnssec-revoke@EXEEXT@ dnssec-settime@EXEEXT@ \
2e2c49
-		dnssec-verify@EXEEXT@ dnssec-importkey@EXEEXT@
2e2c49
+TARGETS =	dnssec-keygen-pkcs11@EXEEXT@ dnssec-signzone-pkcs11@EXEEXT@ \
2e2c49
+		dnssec-keyfromlabel-pkcs11@EXEEXT@ dnssec-dsfromkey-pkcs11@EXEEXT@ \
2e2c49
+		dnssec-revoke-pkcs11@EXEEXT@ dnssec-settime-pkcs11@EXEEXT@ \
2e2c49
+		dnssec-verify-pkcs11@EXEEXT@ dnssec-importkey-pkcs11@EXEEXT@
2e2c49
 
2e2c49
 OBJS =		dnssectool.@O@
2e2c49
 
10d019
@@ -59,15 +59,15 @@ MANOBJS =	${MANPAGES} ${HTMLPAGES}
2e2c49
 
2e2c49
 @BIND9_MAKE_RULES@
2e2c49
 
2e2c49
-dnssec-dsfromkey@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-dsfromkey-pkcs11@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	export BASEOBJS="dnssec-dsfromkey.@O@ ${OBJS}"; \
2e2c49
 	${FINALBUILDCMD}
2e2c49
 
2e2c49
-dnssec-keyfromlabel@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-keyfromlabel-pkcs11@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	export BASEOBJS="dnssec-keyfromlabel.@O@ ${OBJS}"; \
2e2c49
 	${FINALBUILDCMD}
2e2c49
 
2e2c49
-dnssec-keygen@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-keygen-pkcs11@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	export BASEOBJS="dnssec-keygen.@O@ ${OBJS}"; \
2e2c49
 	${FINALBUILDCMD}
2e2c49
 
10d019
@@ -75,7 +75,7 @@ dnssec-signzone.@O@: dnssec-signzone.c
2e2c49
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
2e2c49
 		-c ${srcdir}/dnssec-signzone.c
2e2c49
 
2e2c49
-dnssec-signzone@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-signzone-pkcs11@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	export BASEOBJS="dnssec-signzone.@O@ ${OBJS}"; \
2e2c49
 	${FINALBUILDCMD}
2e2c49
 
10d019
@@ -83,19 +83,19 @@ dnssec-verify.@O@: dnssec-verify.c
2e2c49
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
2e2c49
 		-c ${srcdir}/dnssec-verify.c
2e2c49
 
2e2c49
-dnssec-verify@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-verify-pkcs11@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	export BASEOBJS="dnssec-verify.@O@ ${OBJS}"; \
2e2c49
 	${FINALBUILDCMD}
2e2c49
 
2e2c49
-dnssec-revoke@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-revoke-pkcs11@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
2e2c49
 	dnssec-revoke.@O@ ${OBJS} ${LIBS}
2e2c49
 
2e2c49
-dnssec-settime@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-settime-pkcs11@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
2e2c49
 	dnssec-settime.@O@ ${OBJS} ${LIBS}
2e2c49
 
2e2c49
-dnssec-importkey@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
2e2c49
+dnssec-importkey-pkcs11@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
2e2c49
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
2e2c49
 	dnssec-importkey.@O@ ${OBJS} ${LIBS}
2e2c49
 
10d019
@@ -106,16 +106,14 @@ docclean manclean maintainer-clean::
2e2c49
 
2e2c49
 installdirs:
2e2c49
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${sbindir}
2e2c49
-	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man8
2e2c49
 
2e2c49
 install-man8: ${MANPAGES}
2e2c49
 	${INSTALL_DATA} $^ ${DESTDIR}${mandir}/man8
2e2c49
 
2e2c49
-install:: ${TARGETS} installdirs install-man8
2e2c49
+install:: ${TARGETS} installdirs
10d019
 	for t in ${TARGETS}; do ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} $$t ${DESTDIR}${sbindir} || exit 1; done
2e2c49
 
2e2c49
 uninstall::
10d019
-	for m in ${MANPAGES}; do rm -f ${DESTDIR}${mandir}/man8/$$m || exit 1; done
10d019
 	for t in ${TARGETS}; do ${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/$$t || exit 1; done
2e2c49
 
2e2c49
 clean distclean::
2e2c49
diff --git a/bin/dnssec/Makefile.in b/bin/dnssec/Makefile.in
943bc6
index 390aa0c..851a008 100644
2e2c49
--- a/bin/dnssec/Makefile.in
2e2c49
+++ b/bin/dnssec/Makefile.in
10d019
@@ -17,7 +17,7 @@ VERSION=@BIND9_VERSION@
2e2c49
 
2e2c49
 CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} @DST_OPENSSL_INC@
2e2c49
 
2e2c49
-CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
2e2c49
+CDEFINES =	-DVERSION=\"${VERSION}\" \
2e2c49
 		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
2e2c49
 CWARNINGS =
2e2c49
 
2e2c49
diff --git a/bin/named-pkcs11/Makefile.in b/bin/named-pkcs11/Makefile.in
1bd7b4
index 277a0f5..52a6375 100644
2e2c49
--- a/bin/named-pkcs11/Makefile.in
2e2c49
+++ b/bin/named-pkcs11/Makefile.in
10d019
@@ -43,27 +43,27 @@ DLZDRIVER_INCLUDES =	@DLZ_DRIVER_INCLUDES@
2e2c49
 DLZDRIVER_LIBS =	@DLZ_DRIVER_LIBS@
2e2c49
 
2e2c49
 CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
2e2c49
-		${LWRES_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES} \
2e2c49
-		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_INCLUDES} \
10d019
+		${LWRES_INCLUDES} ${DNS_PKCS11_INCLUDES} ${BIND9_INCLUDES} \
10d019
+		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_PKCS11_INCLUDES} \
10d019
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} ${MAXMINDDB_CFLAGS} \
10d019
 		@DST_OPENSSL_INC@
2e2c49
 
2e2c49
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
10d019
+CDEFINES =      @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO_PK11@ @USE_GSSAPI@
2e2c49
 
2e2c49
 CWARNINGS =
2e2c49
 
10d019
-DNSLIBS =	../../lib/dns/libdns.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
10d019
+DNSLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
2e2c49
 ISCCFGLIBS =	../../lib/isccfg/libisccfg.@A@
2e2c49
 ISCCCLIBS =	../../lib/isccc/libisccc.@A@
2e2c49
-ISCLIBS =	../../lib/isc/libisc.@A@
10d019
-ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
10d019
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
10d019
+ISCNOSYMLIBS =	../../lib/isc-pkcs11/libisc-pkcs11-nosymtbl.@A@
2e2c49
 LWRESLIBS =	../../lib/lwres/liblwres.@A@
2e2c49
 BIND9LIBS =	../../lib/bind9/libbind9.@A@
2e2c49
 
2e2c49
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
10d019
+DNSDEPLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@
2e2c49
 ISCCFGDEPLIBS =	../../lib/isccfg/libisccfg.@A@
2e2c49
 ISCCCDEPLIBS =	../../lib/isccc/libisccc.@A@
2e2c49
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
10d019
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
2e2c49
 LWRESDEPLIBS =	../../lib/lwres/liblwres.@A@
2e2c49
 BIND9DEPLIBS =	../../lib/bind9/libbind9.@A@
2e2c49
 
10d019
@@ -72,15 +72,15 @@ DEPLIBS =	${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
2e2c49
 
2e2c49
 LIBS =		${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
2e2c49
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} \
2e2c49
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
2e2c49
+		@LIBS@
2e2c49
 
2e2c49
 NOSYMLIBS =	${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
2e2c49
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCNOSYMLIBS} \
2e2c49
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
10d019
+		@LIBS@
2e2c49
 
2e2c49
 SUBDIRS =	unix
2e2c49
 
2e2c49
-TARGETS =	named@EXEEXT@ lwresd@EXEEXT@
10d019
+TARGETS =	named-pkcs11@EXEEXT@
2e2c49
 
2e2c49
 GEOIPLINKOBJS = geoip.@O@
10d019
 GEOIP2LINKOBJS = geoip.@O@
10d019
@@ -94,8 +94,7 @@ OBJS =		builtin.@O@ client.@O@ config.@O@ control.@O@ \
2e2c49
 		tkeyconf.@O@ tsigconf.@O@ update.@O@ xfrout.@O@ \
2e2c49
 		zoneconf.@O@ \
2e2c49
 		lwaddr.@O@ lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
2e2c49
-		lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@ \
2e2c49
-		${DLZDRIVER_OBJS} ${DBDRIVER_OBJS}
2e2c49
+        lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@
2e2c49
 
2e2c49
 UOBJS =		unix/os.@O@ unix/dlz_dlopen_driver.@O@
2e2c49
 
10d019
@@ -113,8 +112,7 @@ SRCS =		builtin.c client.c config.c control.c \
2e2c49
 		tkeyconf.c tsigconf.c update.c xfrout.c \
2e2c49
 		zoneconf.c \
2e2c49
 		lwaddr.c lwresd.c lwdclient.c lwderror.c lwdgabn.c \
2e2c49
-		lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c \
2e2c49
-		${DLZDRIVER_SRCS} ${DBDRIVER_SRCS}
2e2c49
+        lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c
2e2c49
 
2e2c49
 MANPAGES =	named.8 lwresd.8 named.conf.5
2e2c49
 
10d019
@@ -154,14 +152,14 @@ server.@O@: server.c
2e2c49
 		-DPRODUCT=\"${PRODUCT}\" \
2e2c49
 		-DVERSION=\"${VERSION}\" -c ${srcdir}/server.c
2e2c49
 
2e2c49
-named@EXEEXT@: ${OBJS} ${DEPLIBS}
2e2c49
+named-pkcs11@EXEEXT@: ${OBJS} ${DEPLIBS}
2e2c49
 	export MAKE_SYMTABLE="yes"; \
2e2c49
 	export BASEOBJS="${OBJS} ${UOBJS}"; \
2e2c49
 	${FINALBUILDCMD}
2e2c49
 
2e2c49
-lwresd@EXEEXT@: named@EXEEXT@
2e2c49
+lwresd@EXEEXT@: named-pkcs11@EXEEXT@
2e2c49
 	rm -f lwresd@EXEEXT@
2e2c49
-	@LN@ named@EXEEXT@ lwresd@EXEEXT@
2e2c49
+	@LN@ named-pkcs11@EXEEXT@ lwresd@EXEEXT@
2e2c49
 
2e2c49
 doc man:: ${MANOBJS}
2e2c49
 
10d019
@@ -192,16 +190,11 @@ install-man8: named.8 lwresd.8
2e2c49
 
2e2c49
 install-man: install-man5 install-man8
2e2c49
 
2e2c49
-install:: named@EXEEXT@ lwresd@EXEEXT@ installdirs install-man
2e2c49
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named@EXEEXT@ ${DESTDIR}${sbindir}
2e2c49
-	(cd ${DESTDIR}${sbindir}; rm -f lwresd@EXEEXT@; @LN@ named@EXEEXT@ lwresd@EXEEXT@)
2e2c49
+install:: named-pkcs11@EXEEXT@ installdirs
2e2c49
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named-pkcs11@EXEEXT@ ${DESTDIR}${sbindir}
2e2c49
 
2e2c49
 uninstall::
2e2c49
-	rm -f ${DESTDIR}${mandir}/man5/named.conf.5
2e2c49
-	rm -f ${DESTDIR}${mandir}/man8/lwresd.8
2e2c49
-	rm -f ${DESTDIR}${mandir}/man8/named.8
2e2c49
-	rm -f ${DESTDIR}${sbindir}/lwresd@EXEEXT@
2e2c49
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/named@EXEEXT@
2e2c49
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/named-pkcs11@EXEEXT@
2e2c49
 
2e2c49
 @DLZ_DRIVER_RULES@
2e2c49
 
2e2c49
diff --git a/bin/named/Makefile.in b/bin/named/Makefile.in
1bd7b4
index 277a0f5..0e00885 100644
2e2c49
--- a/bin/named/Makefile.in
2e2c49
+++ b/bin/named/Makefile.in
10d019
@@ -48,7 +48,7 @@ CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
10d019
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} ${MAXMINDDB_CFLAGS} \
10d019
 		@DST_OPENSSL_INC@
2e2c49
 
2e2c49
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
10d019
+CDEFINES =      @CONTRIB_DLZ@ @USE_GSSAPI@ @CRYPTO@
2e2c49
 
2e2c49
 CWARNINGS =
2e2c49
 
2e2c49
diff --git a/bin/pkcs11/Makefile.in b/bin/pkcs11/Makefile.in
943bc6
index 2c19e7e..8223d5e 100644
2e2c49
--- a/bin/pkcs11/Makefile.in
2e2c49
+++ b/bin/pkcs11/Makefile.in
943bc6
@@ -13,13 +13,13 @@ top_srcdir =	@top_srcdir@
2e2c49
 
2e2c49
 @BIND9_MAKE_INCLUDES@
2e2c49
 
2e2c49
-CINCLUDES =	${ISC_INCLUDES}
2e2c49
+CINCLUDES =	${ISC_PKCS11_INCLUDES}
2e2c49
 
2e2c49
 CDEFINES =
2e2c49
 
2e2c49
-ISCLIBS =	../../lib/isc/libisc.@A@ @ISC_OPENSSL_LIBS@
2e2c49
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@ @ISC_OPENSSL_LIBS@
2e2c49
 
2e2c49
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
2e2c49
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
2e2c49
 
2e2c49
 DEPLIBS =	${ISCDEPLIBS}
2e2c49
 
10d019
diff --git a/configure.ac b/configure.ac
1bd7b4
index 83cad4a..e1e1a32 100644
10d019
--- a/configure.ac
10d019
+++ b/configure.ac
1bd7b4
@@ -1178,12 +1178,14 @@ AC_SUBST(USE_GSSAPI)
2e2c49
 AC_SUBST(DST_GSSAPI_INC)
2e2c49
 AC_SUBST(DNS_GSSAPI_LIBS)
2e2c49
 DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_LIBS"
2e2c49
+DNS_CRYPTO_PK11_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_PK11_LIBS"
2e2c49
 
2e2c49
 #
2e2c49
 # Applications linking with libdns also need to link with these libraries.
2e2c49
 #
2e2c49
 
2e2c49
 AC_SUBST(DNS_CRYPTO_LIBS)
2e2c49
+AC_SUBST(DNS_CRYPTO_PK11_LIBS)
2e2c49
 
2e2c49
 #
2e2c49
 # was --with-randomdev specified?
1bd7b4
@@ -1556,12 +1558,12 @@ AC_ARG_ENABLE(openssl-hash,
2e2c49
 AC_MSG_CHECKING(for OpenSSL library)
2e2c49
 OPENSSL_WARNING=
10d019
 openssldirs="/usr /usr/local /usr/local/ssl /opt/local /usr/pkg /usr/sfw"
2e2c49
-if test "yes" = "$want_native_pkcs11"
2e2c49
-then
2e2c49
-	use_openssl="native_pkcs11"
943bc6
-	want_openssl_hash="no"
2e2c49
-	AC_MSG_RESULT(use of native PKCS11 instead)
2e2c49
-fi
943bc6
+#if test "yes" = "$want_native_pkcs11"
943bc6
+#then
943bc6
+#	use_openssl="native_pkcs11"
943bc6
+#	want_openssl_hash="no"
943bc6
+#	AC_MSG_RESULT(use of native PKCS11 instead)
943bc6
+#fi
2e2c49
 
2e2c49
 if test "auto" = "$use_openssl"
2e2c49
 then
1bd7b4
@@ -1574,6 +1576,7 @@ then
2e2c49
 		fi
2e2c49
 	done
2e2c49
 fi
2e2c49
+CRYPTO_PK11=""
2e2c49
 OPENSSL_ECDSA=""
2e2c49
 OPENSSL_GOST=""
2e2c49
 OPENSSL_ED25519=""
1bd7b4
@@ -1595,11 +1598,10 @@ case "$with_gost" in
2e2c49
 		;;
2e2c49
 esac
2e2c49
 
2e2c49
-case "$use_openssl" in
2e2c49
-	native_pkcs11)
2e2c49
-		AC_MSG_RESULT(disabled because of native PKCS11)
2e2c49
+if test "$want_native_pkcs11" = "yes"
2e2c49
+then
2e2c49
 		DST_OPENSSL_INC=""
2e2c49
-		CRYPTO="-DPKCS11CRYPTO"
2e2c49
+		CRYPTO_PK11="-DPKCS11CRYPTO"
89a891
 		CRYPTOLIB="pkcs11"
2e2c49
 		OPENSSLECDSALINKOBJS=""
2e2c49
 		OPENSSLECDSALINKSRCS=""
1bd7b4
@@ -1609,7 +1611,9 @@ case "$use_openssl" in
2e2c49
 		OPENSSLGOSTLINKSRCS=""
2e2c49
 		OPENSSLLINKOBJS=""
2e2c49
 		OPENSSLLINKSRCS=""
2e2c49
-		;;
2e2c49
+fi
2e2c49
+
2e2c49
+case "$use_openssl" in
2e2c49
 	no)
2e2c49
 		AC_MSG_RESULT(no)
2e2c49
 		DST_OPENSSL_INC=""
1bd7b4
@@ -1641,7 +1645,7 @@ case "$use_openssl" in
89a891
 If you do not want OpenSSL, use --without-openssl])
2e2c49
 		;;
2e2c49
 	*)
2e2c49
-		if test "yes" = "$want_native_pkcs11"
89a891
+		if false # test "yes" = "$want_native_pkcs11"
2e2c49
 		then
89a891
 			AC_MSG_RESULT()
89a891
 			AC_MSG_ERROR([OpenSSL and native PKCS11 cannot be used together.])
1bd7b4
@@ -2077,6 +2081,7 @@ AC_SUBST(OPENSSL_ED25519)
2e2c49
 AC_SUBST(OPENSSL_GOST)
2e2c49
 
2e2c49
 DNS_CRYPTO_LIBS="$DNS_CRYPTO_LIBS $DST_OPENSSL_LIBS"
2e2c49
+DNS_CRYPTO_PK11_LIBS="$DNS_CRYPTO_LIBS"
2e2c49
 
2e2c49
 ISC_PLATFORM_WANTAES="#undef ISC_PLATFORM_WANTAES"
2e2c49
 if test "yes" = "$with_aes"
1bd7b4
@@ -2363,6 +2368,7 @@ esac
2e2c49
 AC_SUBST(PKCS11LINKOBJS)
2e2c49
 AC_SUBST(PKCS11LINKSRCS)
2e2c49
 AC_SUBST(CRYPTO)
2e2c49
+AC_SUBST(CRYPTO_PK11)
2e2c49
 AC_SUBST(PKCS11_ECDSA)
2e2c49
 AC_SUBST(PKCS11_GOST)
2e2c49
 AC_SUBST(PKCS11_ED25519)
1bd7b4
@@ -5491,8 +5497,11 @@ AC_CONFIG_FILES([
2e2c49
 	bin/delv/Makefile
2e2c49
 	bin/dig/Makefile
2e2c49
 	bin/dnssec/Makefile
2e2c49
+	bin/dnssec-pkcs11/Makefile	
2e2c49
 	bin/named/Makefile
2e2c49
 	bin/named/unix/Makefile
2e2c49
+	bin/named-pkcs11/Makefile
2e2c49
+	bin/named-pkcs11/unix/Makefile
2e2c49
 	bin/nsupdate/Makefile
2e2c49
 	bin/pkcs11/Makefile
2e2c49
 	bin/python/Makefile
1bd7b4
@@ -5565,6 +5574,10 @@ AC_CONFIG_FILES([
2e2c49
 	lib/dns/include/dns/Makefile
2e2c49
 	lib/dns/include/dst/Makefile
2e2c49
 	lib/dns/tests/Makefile
2e2c49
+	lib/dns-pkcs11/Makefile
2e2c49
+	lib/dns-pkcs11/include/Makefile
2e2c49
+	lib/dns-pkcs11/include/dns/Makefile
2e2c49
+	lib/dns-pkcs11/include/dst/Makefile
2e2c49
 	lib/irs/Makefile
2e2c49
 	lib/irs/include/Makefile
2e2c49
 	lib/irs/include/irs/Makefile
1bd7b4
@@ -5589,6 +5602,24 @@ AC_CONFIG_FILES([
2e2c49
 	lib/isc/unix/include/Makefile
2e2c49
 	lib/isc/unix/include/isc/Makefile
2e2c49
 	lib/isc/unix/include/pkcs11/Makefile
2e2c49
+	lib/isc-pkcs11/$arch/Makefile
2e2c49
+	lib/isc-pkcs11/$arch/include/Makefile
2e2c49
+	lib/isc-pkcs11/$arch/include/isc/Makefile
2e2c49
+	lib/isc-pkcs11/$thread_dir/Makefile
2e2c49
+	lib/isc-pkcs11/$thread_dir/include/Makefile
2e2c49
+	lib/isc-pkcs11/$thread_dir/include/isc/Makefile
2e2c49
+	lib/isc-pkcs11/Makefile
2e2c49
+	lib/isc-pkcs11/include/Makefile
2e2c49
+	lib/isc-pkcs11/include/isc/Makefile
2e2c49
+	lib/isc-pkcs11/include/isc/platform.h
2e2c49
+	lib/isc-pkcs11/include/pk11/Makefile
2e2c49
+	lib/isc-pkcs11/include/pkcs11/Makefile
2e2c49
+	lib/isc-pkcs11/tests/Makefile
2e2c49
+	lib/isc-pkcs11/nls/Makefile
2e2c49
+	lib/isc-pkcs11/unix/Makefile
2e2c49
+	lib/isc-pkcs11/unix/include/Makefile
2e2c49
+	lib/isc-pkcs11/unix/include/isc/Makefile
2e2c49
+	lib/isc-pkcs11/unix/include/pkcs11/Makefile
2e2c49
 	lib/isccc/Makefile
2e2c49
 	lib/isccc/include/Makefile
2e2c49
 	lib/isccc/include/isccc/Makefile
2e2c49
diff --git a/lib/Makefile.in b/lib/Makefile.in
943bc6
index f089bea..3ed939b 100644
2e2c49
--- a/lib/Makefile.in
2e2c49
+++ b/lib/Makefile.in
2e2c49
@@ -15,7 +15,7 @@ top_srcdir =	@top_srcdir@
2e2c49
 # Attempt to disable parallel processing.
2e2c49
 .NOTPARALLEL:
2e2c49
 .NO_PARALLEL:
2e2c49
-SUBDIRS =	isc isccc dns isccfg bind9 lwres irs samples
2e2c49
+SUBDIRS =	isc isc-pkcs11 isccc dns dns-pkcs11 isccfg bind9 lwres irs samples
2e2c49
 TARGETS =
2e2c49
 
2e2c49
 @BIND9_MAKE_RULES@
2e2c49
diff --git a/lib/dns-pkcs11/Makefile.in b/lib/dns-pkcs11/Makefile.in
1bd7b4
index 1d0f5df..98c9ba0 100644
2e2c49
--- a/lib/dns-pkcs11/Makefile.in
2e2c49
+++ b/lib/dns-pkcs11/Makefile.in
1bd7b4
@@ -24,17 +24,17 @@ VERSION=@BIND9_VERSION@
2e2c49
 
1bd7b4
 @BIND9_MAKE_INCLUDES@
2e2c49
 
2e2c49
-CINCLUDES =	-I. -I${top_srcdir}/lib/dns -Iinclude ${DNS_INCLUDES} \
10d019
-		${ISC_INCLUDES} ${MAXMINDDB_CFLAGS} \
2e2c49
+CINCLUDES =	-I. -I${top_srcdir}/lib/dns-pkcs11 -Iinclude ${DNS_PKCS11_INCLUDES} \
1bd7b4
+		${ISC_PKCS11_INCLUDES} ${MAXMINDDB_CFLAGS} \
1bd7b4
 		@DST_OPENSSL_INC@ @DST_GSSAPI_INC@
2e2c49
 
1bd7b4
-CDEFINES =	-DUSE_MD5 @CRYPTO@ @USE_GSSAPI@
1bd7b4
+CDEFINES =	-DUSE_MD5 @CRYPTO_PK11@ @USE_GSSAPI@
2e2c49
 
2e2c49
 CWARNINGS =
2e2c49
 
2e2c49
-ISCLIBS =	../../lib/isc/libisc.@A@
2e2c49
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
2e2c49
 
2e2c49
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
2e2c49
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
2e2c49
 
10d019
 LIBS =		${MAXMINDDB_LIBS} @LIBS@
2e2c49
 
1bd7b4
@@ -148,15 +148,15 @@ version.@O@: version.c
2e2c49
 		-DLIBAGE=${LIBAGE} \
2e2c49
 		-c ${srcdir}/version.c
2e2c49
 
2e2c49
-libdns.@SA@: ${OBJS}
2e2c49
+libdns-pkcs11.@SA@: ${OBJS}
2e2c49
 	${AR} ${ARFLAGS} $@ ${OBJS}
2e2c49
 	${RANLIB} $@
2e2c49
 
2e2c49
-libdns.la: ${OBJS}
2e2c49
+libdns-pkcs11.la: ${OBJS}
2e2c49
 	${LIBTOOL_MODE_LINK} \
2e2c49
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns.la -rpath ${libdir} \
2e2c49
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns-pkcs11.la -rpath ${libdir} \
2e2c49
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
2e2c49
-		${OBJS} ${ISCLIBS} @DNS_CRYPTO_LIBS@ ${LIBS}
2e2c49
+		${OBJS} ${ISCLIBS} @DNS_CRYPTO_PK11_LIBS@ ${LIBS}
2e2c49
 
2e2c49
 include: gen
2e2c49
 	${MAKE} include/dns/enumtype.h
1bd7b4
@@ -187,22 +187,22 @@ gen: gen.c
10d019
 	${BUILD_CPPFLAGS} ${BUILD_LDFLAGS} -o $@ ${srcdir}/gen.c \
10d019
 	${BUILD_LIBS} ${LFS_LIBS}
2e2c49
 
2e2c49
-timestamp: include libdns.@A@
2e2c49
+timestamp: include libdns-pkcs11.@A@
2e2c49
 	touch timestamp
2e2c49
 
2e2c49
-testdirs: libdns.@A@
2e2c49
+testdirs: libdns-pkcs11.@A@
2e2c49
 
2e2c49
 installdirs:
2e2c49
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
2e2c49
 
2e2c49
 install:: timestamp installdirs
2e2c49
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libdns.@A@ ${DESTDIR}${libdir}
2e2c49
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libdns-pkcs11.@A@ ${DESTDIR}${libdir}
2e2c49
 
2e2c49
 uninstall::
2e2c49
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libdns.@A@
2e2c49
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libdns-pkcs11.@A@
2e2c49
 
2e2c49
 clean distclean::
2e2c49
-	rm -f libdns.@A@ timestamp
2e2c49
+	rm -f libdns-pkcs11.@A@ timestamp
2e2c49
 	rm -f gen code.h include/dns/enumtype.h include/dns/enumclass.h
2e2c49
 	rm -f include/dns/rdatastruct.h
10d019
 	rm -f dnstap.pb-c.c dnstap.pb-c.h
2e2c49
diff --git a/lib/isc-pkcs11/Makefile.in b/lib/isc-pkcs11/Makefile.in
943bc6
index 7e3e9ce..58d7466 100644
2e2c49
--- a/lib/isc-pkcs11/Makefile.in
2e2c49
+++ b/lib/isc-pkcs11/Makefile.in
2e2c49
@@ -23,8 +23,8 @@ CINCLUDES =	-I${srcdir}/unix/include \
2e2c49
 		-I${srcdir}/@ISC_THREAD_DIR@/include \
2e2c49
 		-I${srcdir}/@ISC_ARCH_DIR@/include \
2e2c49
 		-I./include \
2e2c49
-		-I${srcdir}/include ${DNS_INCLUDES} @ISC_OPENSSL_INC@
2e2c49
-CDEFINES =	@CRYPTO@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
2e2c49
+		-I${srcdir}/include ${DNS_PKCS11_INCLUDES}
2e2c49
+CDEFINES =	@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
2e2c49
 CWARNINGS =
2e2c49
 
2e2c49
 # Alphabetically
943bc6
@@ -107,40 +107,40 @@ version.@O@: version.c
2e2c49
 		-DLIBAGE=${LIBAGE} \
2e2c49
 		-c ${srcdir}/version.c
2e2c49
 
2e2c49
-libisc.@SA@: ${OBJS} ${SYMTBLOBJS}
2e2c49
+libisc-pkcs11.@SA@: ${OBJS} ${SYMTBLOBJS}
2e2c49
 	${AR} ${ARFLAGS} $@ ${OBJS} ${SYMTBLOBJS}
2e2c49
 	${RANLIB} $@
2e2c49
 
2e2c49
-libisc-nosymtbl.@SA@: ${OBJS}
2e2c49
+libisc-pkcs11-nosymtbl.@SA@: ${OBJS}
2e2c49
 	${AR} ${ARFLAGS} $@ ${OBJS}
2e2c49
 	${RANLIB} $@
2e2c49
 
2e2c49
-libisc.la: ${OBJS} ${SYMTBLOBJS}
2e2c49
+libisc-pkcs11.la: ${OBJS} ${SYMTBLOBJS}
2e2c49
 	${LIBTOOL_MODE_LINK} \
2e2c49
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc.la -rpath ${libdir} \
2e2c49
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11.la -rpath ${libdir} \
2e2c49
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
2e2c49
 		${OBJS} ${SYMTBLOBJS} ${LIBS}
2e2c49
 
2e2c49
-libisc-nosymtbl.la: ${OBJS}
2e2c49
+libisc-pkcs11-nosymtbl.la: ${OBJS}
2e2c49
 	${LIBTOOL_MODE_LINK} \
2e2c49
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-nosymtbl.la -rpath ${libdir} \
2e2c49
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11-nosymtbl.la -rpath ${libdir} \
2e2c49
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
2e2c49
 		${OBJS} ${LIBS}
2e2c49
 
2e2c49
-timestamp: libisc.@A@ libisc-nosymtbl.@A@
2e2c49
+timestamp: libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@
2e2c49
 	touch timestamp
2e2c49
 
2e2c49
-testdirs: libisc.@A@ libisc-nosymtbl.@A@
2e2c49
+testdirs: libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@
2e2c49
 
2e2c49
 installdirs:
2e2c49
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
2e2c49
 
2e2c49
 install:: timestamp installdirs
2e2c49
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libisc.@A@ ${DESTDIR}${libdir}
2e2c49
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libisc-pkcs11.@A@ ${DESTDIR}${libdir}
2e2c49
 
2e2c49
 uninstall::
2e2c49
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libisc.@A@
2e2c49
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libisc-pkcs11.@A@
2e2c49
 
2e2c49
 clean distclean::
2e2c49
-	rm -f libisc.@A@ libisc-nosymtbl.@A@ libisc.la \
2e2c49
-	libisc-nosymtbl.la timestamp
2e2c49
+	rm -f libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@ libisc-pkcs11.la \
2e2c49
+	libisc-pkcs11-nosymtbl.la timestamp
2e2c49
diff --git a/make/includes.in b/make/includes.in
943bc6
index 66efe68..966671f 100644
2e2c49
--- a/make/includes.in
2e2c49
+++ b/make/includes.in
943bc6
@@ -41,3 +41,13 @@ BIND9_INCLUDES = @BIND9_BIND9_BUILDINCLUDE@ \
2e2c49
 
2e2c49
 TEST_INCLUDES = \
2e2c49
 	-I${top_srcdir}/lib/tests/include
2e2c49
+
2e2c49
+ISC_PKCS11_INCLUDES = @BIND9_ISC_BUILDINCLUDE@ \
2e2c49
+	-I${top_srcdir}/lib/isc-pkcs11 \
2e2c49
+	-I${top_srcdir}/lib/isc-pkcs11/include \
2e2c49
+	-I${top_srcdir}/lib/isc-pkcs11/unix/include \
2e2c49
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_THREAD_DIR@/include \
2e2c49
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_ARCH_DIR@/include
2e2c49
+
2e2c49
+DNS_PKCS11_INCLUDES = @BIND9_DNS_BUILDINCLUDE@ \
2e2c49
+	-I${top_srcdir}/lib/dns-pkcs11/include