900526
diff --git a/bin/Makefile.in b/bin/Makefile.in
900526
index 87ca5b2..187ec23 100644
900526
--- a/bin/Makefile.in
900526
+++ b/bin/Makefile.in
900526
@@ -19,7 +19,7 @@ srcdir =	@srcdir@
900526
 VPATH =		@srcdir@
900526
 top_srcdir =	@top_srcdir@
900526
 
900526
-SUBDIRS =	named rndc dig dnssec tools tests nsupdate \
900526
+SUBDIRS =	named named-pkcs11 rndc dig dnssec dnssec-pkcs11 tools tests nsupdate \
900526
 		check confgen @PYTHON_TOOLS@ @PKCS11_TOOLS@
900526
 TARGETS =
900526
 
900526
diff --git a/bin/dnssec-pkcs11/Makefile.in b/bin/dnssec-pkcs11/Makefile.in
900526
index 64e1846..7846662 100644
900526
--- a/bin/dnssec-pkcs11/Makefile.in
900526
+++ b/bin/dnssec-pkcs11/Makefile.in
900526
@@ -23,18 +23,18 @@ top_srcdir =	@top_srcdir@
900526
 
900526
 @BIND9_MAKE_INCLUDES@
900526
 
900526
-CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES}
900526
+CINCLUDES =	${DNS_PKCS11_INCLUDES} ${ISC_PKCS11_INCLUDES}
900526
 
900526
 CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
900526
-		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
900526
+		@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
900526
 CWARNINGS =
900526
 
900526
-DNSLIBS =	../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
900526
-ISCLIBS =	../../lib/isc/libisc.@A@
900526
-ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
900526
+DNSLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@ @DNS_CRYPTO_PK11_LIBS@
900526
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
+ISCNOSYMLIBS =	../../lib/isc-pkcs11/libisc-pkcs11-nosymtbl.@A@
900526
 
900526
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
900526
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
900526
+DNSDEPLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@
900526
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
 
900526
 DEPLIBS =	${DNSDEPLIBS} ${ISCDEPLIBS}
900526
 
900526
@@ -43,10 +43,10 @@ LIBS =		${DNSLIBS} ${ISCLIBS} @LIBS@
900526
 NOSYMLIBS =	${DNSLIBS} ${ISCNOSYMLIBS} @LIBS@
900526
 
900526
 # Alphabetically
900526
-TARGETS =	dnssec-keygen@EXEEXT@ dnssec-signzone@EXEEXT@ \
900526
-		dnssec-keyfromlabel@EXEEXT@ dnssec-dsfromkey@EXEEXT@ \
900526
-		dnssec-revoke@EXEEXT@ dnssec-settime@EXEEXT@ \
900526
-		dnssec-verify@EXEEXT@ dnssec-importkey@EXEEXT@
900526
+TARGETS =	dnssec-keygen-pkcs11@EXEEXT@ dnssec-signzone-pkcs11@EXEEXT@ \
900526
+		dnssec-keyfromlabel-pkcs11@EXEEXT@ dnssec-dsfromkey-pkcs11@EXEEXT@ \
900526
+		dnssec-revoke-pkcs11@EXEEXT@ dnssec-settime-pkcs11@EXEEXT@ \
900526
+		dnssec-verify-pkcs11@EXEEXT@ dnssec-importkey-pkcs11@EXEEXT@
900526
 
900526
 OBJS =		dnssectool.@O@
900526
 
900526
@@ -67,15 +67,15 @@ MANOBJS =	${MANPAGES} ${HTMLPAGES}
900526
 
900526
 @BIND9_MAKE_RULES@
900526
 
900526
-dnssec-dsfromkey@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-dsfromkey-pkcs11@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
900526
 	export BASEOBJS="dnssec-dsfromkey.@O@ ${OBJS}"; \
900526
 	${FINALBUILDCMD}
900526
 
900526
-dnssec-keyfromlabel@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-keyfromlabel-pkcs11@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
900526
 	export BASEOBJS="dnssec-keyfromlabel.@O@ ${OBJS}"; \
900526
 	${FINALBUILDCMD}
900526
 
900526
-dnssec-keygen@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-keygen-pkcs11@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
900526
 	export BASEOBJS="dnssec-keygen.@O@ ${OBJS}"; \
900526
 	${FINALBUILDCMD}
900526
 
900526
@@ -83,7 +83,7 @@ dnssec-signzone.@O@: dnssec-signzone.c
900526
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
900526
 		-c ${srcdir}/dnssec-signzone.c
900526
 
900526
-dnssec-signzone@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-signzone-pkcs11@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
900526
 	export BASEOBJS="dnssec-signzone.@O@ ${OBJS}"; \
900526
 	${FINALBUILDCMD}
900526
 
900526
@@ -91,19 +91,19 @@ dnssec-verify.@O@: dnssec-verify.c
900526
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
900526
 		-c ${srcdir}/dnssec-verify.c
900526
 
900526
-dnssec-verify@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-verify-pkcs11@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
900526
 	export BASEOBJS="dnssec-verify.@O@ ${OBJS}"; \
900526
 	${FINALBUILDCMD}
900526
 
900526
-dnssec-revoke@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-revoke-pkcs11@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
900526
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
900526
 	dnssec-revoke.@O@ ${OBJS} ${LIBS}
900526
 
900526
-dnssec-settime@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-settime-pkcs11@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
900526
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
900526
 	dnssec-settime.@O@ ${OBJS} ${LIBS}
900526
 
900526
-dnssec-importkey@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
900526
+dnssec-importkey-pkcs11@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
900526
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
900526
 	dnssec-importkey.@O@ ${OBJS} ${LIBS}
900526
 
900526
@@ -114,11 +114,9 @@ docclean manclean maintainer-clean::
900526
 
900526
 installdirs:
900526
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${sbindir}
900526
-	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man8
900526
 
900526
 install:: ${TARGETS} installdirs
900526
 	for t in ${TARGETS}; do ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} $$t ${DESTDIR}${sbindir}; done
900526
-	for m in ${MANPAGES}; do ${INSTALL_DATA} ${srcdir}/$$m ${DESTDIR}${mandir}/man8; done
900526
 
900526
 clean distclean::
900526
 	rm -f ${TARGETS}
900526
diff --git a/bin/dnssec/Makefile.in b/bin/dnssec/Makefile.in
900526
index 64e1846..cfb5628 100644
900526
--- a/bin/dnssec/Makefile.in
900526
+++ b/bin/dnssec/Makefile.in
900526
@@ -25,7 +25,7 @@ top_srcdir =	@top_srcdir@
900526
 
900526
 CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES}
900526
 
900526
-CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
900526
+CDEFINES =	-DVERSION=\"${VERSION}\" \
900526
 		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
900526
 CWARNINGS =
900526
 
900526
diff --git a/bin/named-pkcs11/Makefile.in b/bin/named-pkcs11/Makefile.in
900526
index 8b9e87a..5b7d939 100644
900526
--- a/bin/named-pkcs11/Makefile.in
900526
+++ b/bin/named-pkcs11/Makefile.in
900526
@@ -45,26 +45,26 @@ DLZDRIVER_INCLUDES =	@DLZ_DRIVER_INCLUDES@
900526
 DLZDRIVER_LIBS =	@DLZ_DRIVER_LIBS@
900526
 
900526
 CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
900526
-		${LWRES_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES} \
900526
-		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_INCLUDES} \
900526
+		${LWRES_INCLUDES} ${DNS_PKCS11_INCLUDES} ${BIND9_INCLUDES} \
900526
+		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_PKCS11_INCLUDES} \
900526
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} @DST_OPENSSL_INC@
900526
 
900526
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
900526
+CDEFINES =      @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO_PK11@
900526
 
900526
 CWARNINGS =
900526
 
900526
-DNSLIBS =	../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
900526
+DNSLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@ @DNS_CRYPTO_LIBS@
900526
 ISCCFGLIBS =	../../lib/isccfg/libisccfg.@A@
900526
 ISCCCLIBS =	../../lib/isccc/libisccc.@A@
900526
-ISCLIBS =	../../lib/isc/libisc.@A@
900526
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
 ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
900526
 LWRESLIBS =	../../lib/lwres/liblwres.@A@
900526
 BIND9LIBS =	../../lib/bind9/libbind9.@A@
900526
 
900526
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
900526
+DNSDEPLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@
900526
 ISCCFGDEPLIBS =	../../lib/isccfg/libisccfg.@A@
900526
 ISCCCDEPLIBS =	../../lib/isccc/libisccc.@A@
900526
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
900526
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
 LWRESDEPLIBS =	../../lib/lwres/liblwres.@A@
900526
 BIND9DEPLIBS =	../../lib/bind9/libbind9.@A@
900526
 
900526
@@ -73,15 +73,15 @@ DEPLIBS =	${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
900526
 
900526
 LIBS =		${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
900526
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} \
900526
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
900526
+		@LIBS@
900526
 
900526
 NOSYMLIBS =	${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
900526
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCNOSYMLIBS} \
900526
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
900526
+		@LIBS@
900526
 
900526
 SUBDIRS =	unix
900526
 
900526
-TARGETS =	named@EXEEXT@ lwresd@EXEEXT@
900526
+TARGETS =	named-pkcs11@EXEEXT@
900526
 
900526
 GEOIPLINKOBJS = geoip.@O@
900526
 
900526
@@ -92,8 +92,7 @@ OBJS =		builtin.@O@ client.@O@ config.@O@ control.@O@ \
900526
 		tkeyconf.@O@ tsigconf.@O@ update.@O@ xfrout.@O@ \
900526
 		zoneconf.@O@ \
900526
 		lwaddr.@O@ lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
900526
-		lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@ \
900526
-		${DLZDRIVER_OBJS} ${DBDRIVER_OBJS}
900526
+		lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@
900526
 
900526
 UOBJS =		unix/os.@O@ unix/dlz_dlopen_driver.@O@
900526
 
900526
@@ -108,8 +107,7 @@ SRCS =		builtin.c client.c config.c control.c \
900526
 		tkeyconf.c tsigconf.c update.c xfrout.c \
900526
 		zoneconf.c \
900526
 		lwaddr.c lwresd.c lwdclient.c lwderror.c lwdgabn.c \
900526
-		lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c \
900526
-		${DLZDRIVER_SRCS} ${DBDRIVER_SRCS}
900526
+		lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c
900526
 
900526
 MANPAGES =	named.8 lwresd.8 named.conf.5
900526
 
900526
@@ -145,7 +143,7 @@ config.@O@: config.c bind.keys.h
900526
 		-DNS_SYSCONFDIR=\"${sysconfdir}\" \
900526
 		-c ${srcdir}/config.c
900526
 
900526
-named@EXEEXT@: ${OBJS} ${UOBJS} ${DEPLIBS}
900526
+named-pkcs11@EXEEXT@: ${OBJS} ${UOBJS} ${DEPLIBS}
900526
 	export MAKE_SYMTABLE="yes"; \
900526
 	export BASEOBJS="${OBJS} ${UOBJS}"; \
900526
 	${FINALBUILDCMD}
900526
@@ -176,15 +174,9 @@ statschannel.@O@: bind9.xsl.h bind9.ver3.xsl.h
900526
 
900526
 installdirs:
900526
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${sbindir}
900526
-	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man5
900526
-	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man8
900526
-
900526
-install:: named@EXEEXT@ lwresd@EXEEXT@ installdirs
900526
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named@EXEEXT@ ${DESTDIR}${sbindir}
900526
-	(cd ${DESTDIR}${sbindir}; rm -f lwresd@EXEEXT@; @LN@ named@EXEEXT@ lwresd@EXEEXT@)
900526
-	${INSTALL_DATA} ${srcdir}/named.8 ${DESTDIR}${mandir}/man8
900526
-	${INSTALL_DATA} ${srcdir}/lwresd.8 ${DESTDIR}${mandir}/man8
900526
-	${INSTALL_DATA} ${srcdir}/named.conf.5 ${DESTDIR}${mandir}/man5
900526
+
900526
+install:: named-pkcs11@EXEEXT@ installdirs
900526
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named-pkcs11@EXEEXT@ ${DESTDIR}${sbindir}
900526
 
900526
 @DLZ_DRIVER_RULES@
900526
 
900526
diff --git a/bin/named/Makefile.in b/bin/named/Makefile.in
900526
index 8b9e87a..5ba3f56 100644
900526
--- a/bin/named/Makefile.in
900526
+++ b/bin/named/Makefile.in
900526
@@ -49,7 +49,7 @@ CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
900526
 		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_INCLUDES} \
900526
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} @DST_OPENSSL_INC@
900526
 
900526
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
900526
+CDEFINES =      @CONTRIB_DLZ@ @CRYPTO@
900526
 
900526
 CWARNINGS =
900526
 
900526
diff --git a/bin/pkcs11/Makefile.in b/bin/pkcs11/Makefile.in
900526
index 15d3fb5..32cc753 100644
900526
--- a/bin/pkcs11/Makefile.in
900526
+++ b/bin/pkcs11/Makefile.in
900526
@@ -20,13 +20,13 @@ top_srcdir =	@top_srcdir@
900526
 
900526
 @BIND9_MAKE_INCLUDES@
900526
 
900526
-CINCLUDES =	${ISC_INCLUDES}
900526
+CINCLUDES =	${ISC_PKCS11_INCLUDES}
900526
 
900526
 CDEFINES =
900526
 
900526
-ISCLIBS =	../../lib/isc/libisc.@A@
900526
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
 
900526
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
900526
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
 
900526
 DEPLIBS =	${ISCDEPLIBS}
900526
 
900526
diff --git a/configure.in b/configure.in
900526
index 5c79d6d..6c08de9 100644
900526
--- a/configure.in
900526
+++ b/configure.in
900526
@@ -659,10 +659,10 @@ AC_ARG_WITH(pkcs11,
900526
 openssldirs="/usr /usr/local /usr/local/ssl /usr/pkg /usr/sfw"
900526
 if test "$use_openssl" = "auto"
900526
 then
900526
-    if test "$want_native_pkcs11" = "yes"
900526
-    then
900526
-        use_openssl="native_pkcs11"
900526
-    else
900526
+#    if test "$want_native_pkcs11" = "yes"
900526
+#    then
900526
+#        use_openssl="native_pkcs11"
900526
+#    else
900526
 	    for d in $openssldirs
900526
     	do
900526
 	    	if test -f $d/include/openssl/opensslv.h
900526
@@ -671,7 +671,7 @@ then
900526
     			break
900526
 		    fi
900526
     	done
900526
-    fi
900526
+#    fi
900526
 fi
900526
 OPENSSL_ECDSA=""
900526
 OPENSSL_GOST=""
900526
@@ -730,11 +730,11 @@ case "$use_openssl" in
900526
 If you don't want OpenSSL, use --without-openssl])
900526
 		;;
900526
 	*)
900526
-		if test "$want_native_pkcs11" = "yes"
900526
-		then
900526
-                        AC_MSG_RESULT()
900526
-			AC_MSG_ERROR([OpenSSL and native PKCS11 cannot be used together.])
900526
-		fi
900526
+#		if test "$want_native_pkcs11" = "yes"
900526
+#		then
900526
+#                        AC_MSG_RESULT()
900526
+#			AC_MSG_ERROR([OpenSSL and native PKCS11 cannot be used together.])
900526
+#		fi
900526
 		if test "$use_openssl" = "yes"
900526
 		then
900526
 			# User did not specify a path - guess it
900526
@@ -1014,6 +1014,7 @@ AC_SUBST(OPENSSL_ECDSA)
900526
 AC_SUBST(OPENSSL_GOST)
900526
 
900526
 DNS_CRYPTO_LIBS="$DNS_CRYPTO_LIBS $DNS_OPENSSL_LIBS"
900526
+DNS_CRYPTO_PK11_LIBS="$DNS_CRYPTO_LIBS"
900526
 
900526
 #
900526
 # Use OpenSSL for hash functions
900526
@@ -1195,7 +1196,7 @@ case "$use_pkcs11" in
900526
 esac
900526
 AC_SUBST(PKCS11_PROVIDER)
900526
 
900526
-
900526
+CRYPTO_PK11=""
900526
 PKCS11_ECDSA=""
900526
 PKCS11_GOST=""
900526
 AC_MSG_CHECKING(for native PKCS11)
900526
@@ -1203,7 +1204,7 @@ AC_MSG_CHECKING(for native PKCS11)
900526
 case "$want_native_pkcs11" in
900526
 	yes)
900526
 		AC_MSG_RESULT(using native PKCS11 crypto)
900526
-		CRYPTO="-DPKCS11CRYPTO"
900526
+		CRYPTO_PK11="-DPKCS11CRYPTO"
900526
 		PKCS11LINKOBJS='${PKCS11LINKOBJS}'
900526
 		PKCS11LINKSRCS='${PKCS11LINKSRCS}'
900526
                 PKCS11_TEST=pkcs11
900526
@@ -1240,6 +1241,7 @@ esac
900526
 AC_SUBST(PKCS11LINKOBJS)
900526
 AC_SUBST(PKCS11LINKSRCS)
900526
 AC_SUBST(CRYPTO)
900526
+AC_SUBST(CRYPTO_PK11)
900526
 AC_SUBST(PKCS11_ECDSA)
900526
 AC_SUBST(PKCS11_GOST)
900526
 AC_SUBST(PKCS11_TEST)
900526
@@ -1531,12 +1533,13 @@ AC_SUBST(USE_GSSAPI)
900526
 AC_SUBST(DST_GSSAPI_INC)
900526
 AC_SUBST(DNS_GSSAPI_LIBS)
900526
 DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_LIBS"
900526
-
900526
+DNS_CRYPTO_PK11_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_PK11_LIBS"
900526
 #
900526
 # Applications linking with libdns also need to link with these libraries.
900526
 #
900526
 
900526
 AC_SUBST(DNS_CRYPTO_LIBS)
900526
+AC_SUBST(DNS_CRYPTO_PK11_LIBS)
900526
 
900526
 #
900526
 # was --with-randomdev specified?
900526
@@ -4014,7 +4017,10 @@ AC_CONFIG_FILES([
900526
 	bin/confgen/unix/Makefile
900526
 	bin/dig/Makefile
900526
 	bin/dnssec/Makefile
900526
+	bin/dnssec-pkcs11/Makefile
900526
 	bin/named/Makefile
900526
+	bin/named-pkcs11/Makefile
900526
+	bin/named-pkcs11/unix/Makefile
900526
 	bin/named/unix/Makefile
900526
 	bin/nsupdate/Makefile
900526
 	bin/pkcs11/Makefile
900526
@@ -4097,11 +4103,19 @@ AC_CONFIG_FILES([
900526
 	lib/dns/include/dns/Makefile
900526
 	lib/dns/include/dst/Makefile
900526
 	lib/dns/tests/Makefile
900526
+	lib/dns-pkcs11/Makefile
900526
+	lib/dns-pkcs11/include/Makefile
900526
+	lib/dns-pkcs11/include/dns/Makefile
900526
+	lib/dns-pkcs11/include/dst/Makefile
900526
 	lib/export/Makefile
900526
 	lib/export/dns/Makefile
900526
 	lib/export/dns/include/Makefile
900526
 	lib/export/dns/include/dns/Makefile
900526
 	lib/export/dns/include/dst/Makefile
900526
+	lib/export/dns-pkcs11/Makefile
900526
+	lib/export/dns-pkcs11/include/Makefile
900526
+	lib/export/dns-pkcs11/include/dns/Makefile
900526
+	lib/export/dns-pkcs11/include/dst/Makefile
900526
 	lib/export/irs/Makefile
900526
 	lib/export/irs/include/Makefile
900526
 	lib/export/irs/include/irs/Makefile
900526
@@ -4115,6 +4129,16 @@ AC_CONFIG_FILES([
900526
 	lib/export/isc/unix/Makefile
900526
 	lib/export/isc/unix/include/Makefile
900526
 	lib/export/isc/unix/include/isc/Makefile
900526
+	lib/export/isc-pkcs11/$thread_dir/Makefile
900526
+	lib/export/isc-pkcs11/$thread_dir/include/Makefile
900526
+	lib/export/isc-pkcs11/$thread_dir/include/isc/Makefile
900526
+	lib/export/isc-pkcs11/Makefile
900526
+	lib/export/isc-pkcs11/include/Makefile
900526
+	lib/export/isc-pkcs11/include/isc/Makefile
900526
+	lib/export/isc-pkcs11/nls/Makefile
900526
+	lib/export/isc-pkcs11/unix/Makefile
900526
+	lib/export/isc-pkcs11/unix/include/Makefile
900526
+	lib/export/isc-pkcs11/unix/include/isc/Makefile
900526
 	lib/export/isccfg/Makefile
900526
 	lib/export/isccfg/include/Makefile
900526
 	lib/export/isccfg/include/isccfg/Makefile
900526
@@ -4143,6 +4167,24 @@ AC_CONFIG_FILES([
900526
 	lib/isc/unix/include/Makefile
900526
 	lib/isc/unix/include/isc/Makefile
900526
 	lib/isc/unix/include/pkcs11/Makefile
900526
+	lib/isc-pkcs11/$arch/Makefile
900526
+	lib/isc-pkcs11/$arch/include/Makefile
900526
+	lib/isc-pkcs11/$arch/include/isc/Makefile
900526
+	lib/isc-pkcs11/$thread_dir/Makefile
900526
+	lib/isc-pkcs11/$thread_dir/include/Makefile
900526
+	lib/isc-pkcs11/$thread_dir/include/isc/Makefile
900526
+	lib/isc-pkcs11/Makefile
900526
+	lib/isc-pkcs11/include/Makefile
900526
+	lib/isc-pkcs11/include/isc/Makefile
900526
+	lib/isc-pkcs11/include/isc/platform.h
900526
+	lib/isc-pkcs11/include/pk11/Makefile
900526
+	lib/isc-pkcs11/include/pkcs11/Makefile
900526
+	lib/isc-pkcs11/tests/Makefile
900526
+	lib/isc-pkcs11/nls/Makefile
900526
+	lib/isc-pkcs11/unix/Makefile
900526
+	lib/isc-pkcs11/unix/include/Makefile
900526
+	lib/isc-pkcs11/unix/include/isc/Makefile
900526
+	lib/isc-pkcs11/unix/include/pkcs11/Makefile
900526
 	lib/isccc/Makefile
900526
 	lib/isccc/include/Makefile
900526
 	lib/isccc/include/isccc/Makefile
900526
diff --git a/lib/Makefile.in b/lib/Makefile.in
900526
index 8dc1d38..8e48d5e 100644
900526
--- a/lib/Makefile.in
900526
+++ b/lib/Makefile.in
900526
@@ -23,7 +23,7 @@ top_srcdir =	@top_srcdir@
900526
 # Attempt to disable parallel processing.
900526
 .NOTPARALLEL:
900526
 .NO_PARALLEL:
900526
-SUBDIRS =	isc isccc dns isccfg bind9 lwres tests
900526
+SUBDIRS =	isc isccc dns isccfg bind9 lwres tests isc-pkcs11 dns-pkcs11
900526
 TARGETS =
900526
 
900526
 @BIND9_MAKE_RULES@
900526
diff --git a/lib/dns-pkcs11/Makefile.in b/lib/dns-pkcs11/Makefile.in
900526
index ae316c5..1a79768 100644
900526
--- a/lib/dns-pkcs11/Makefile.in
900526
+++ b/lib/dns-pkcs11/Makefile.in
900526
@@ -27,16 +27,16 @@ top_srcdir =	@top_srcdir@
900526
 
900526
 USE_ISC_SPNEGO = @USE_ISC_SPNEGO@
900526
 
900526
-CINCLUDES =	-I. -I${top_srcdir}/lib/dns -Iinclude ${DNS_INCLUDES} ${ISC_INCLUDES} \
900526
+CINCLUDES =	-I. -I${top_srcdir}/lib/dns-pkcs11 -Iinclude ${DNS_PKCS11_INCLUDES} ${ISC_PKCS11_INCLUDES} \
900526
 		@DST_OPENSSL_INC@ @DST_GSSAPI_INC@
900526
 
900526
-CDEFINES =	-DUSE_MD5 @CRYPTO@ @USE_GSSAPI@ ${USE_ISC_SPNEGO}
900526
+CDEFINES =	-DUSE_MD5 @CRYPTO_PK11@ @USE_GSSAPI@ ${USE_ISC_SPNEGO}
900526
 
900526
 CWARNINGS =
900526
 
900526
-ISCLIBS =	../../lib/isc/libisc.@A@
900526
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
 
900526
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
900526
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
900526
 
900526
 LIBS =		@LIBS@
900526
 
900526
@@ -131,24 +131,24 @@ version.@O@: version.c
900526
 		-DLIBAGE=${LIBAGE} \
900526
 		-c ${srcdir}/version.c
900526
 
900526
-libdns.@SA@: ${OBJS}
900526
+libdns-pkcs11.@SA@: ${OBJS}
900526
 	${AR} ${ARFLAGS} $@ ${OBJS}
900526
 	${RANLIB} $@
900526
 
900526
-libdns.la: ${OBJS}
900526
+libdns-pkcs11.la: ${OBJS}
900526
 	${LIBTOOL_MODE_LINK} \
900526
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns.la -rpath ${libdir} \
900526
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns-pkcs11.la -rpath ${libdir} \
900526
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
900526
 		${OBJS} ${ISCLIBS} @DNS_CRYPTO_LIBS@ ${LIBS}
900526
 
900526
-timestamp: libdns.@A@
900526
+timestamp: libdns-pkcs11.@A@
900526
 	touch timestamp
900526
 
900526
 installdirs:
900526
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
900526
 
900526
 install:: timestamp installdirs
900526
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libdns.@A@ ${DESTDIR}${libdir}
900526
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libdns-pkcs11.@A@ ${DESTDIR}${libdir}
900526
 
900526
 clean distclean::
900526
 	rm -f libdns.@A@ timestamp
900526
@@ -181,7 +181,7 @@ code.h:	gen
900526
 	./gen -s ${srcdir} > code.h
900526
 
900526
 gen: gen.c
900526
-	${BUILD_CC} ${BUILD_CFLAGS} -I${top_srcdir}/lib/isc/include \
900526
+	${BUILD_CC} ${BUILD_CFLAGS} -I${top_srcdir}/lib/isc-pkcs11/include \
900526
 	${BUILD_CPPFLAGS} ${BUILD_LDFLAGS} -o $@ ${srcdir}/gen.c ${BUILD_LIBS}
900526
 
900526
 rbtdb64.@O@: rbtdb.c
900526
diff --git a/lib/export/Makefile.in b/lib/export/Makefile.in
900526
index 1fd7216..a8a1342 100644
900526
--- a/lib/export/Makefile.in
900526
+++ b/lib/export/Makefile.in
900526
@@ -21,7 +21,7 @@ top_srcdir =	@top_srcdir@
900526
 # Attempt to disable parallel processing.
900526
 .NOTPARALLEL:
900526
 .NO_PARALLEL:
900526
-SUBDIRS =	isc dns isccfg irs samples
900526
+SUBDIRS =	isc dns isccfg irs samples isc-pkcs11 dns-pkcs11
900526
 TARGETS =
900526
 
900526
 @BIND9_MAKE_RULES@
900526
diff --git a/lib/export/dns-pkcs11/Makefile.in b/lib/export/dns-pkcs11/Makefile.in
900526
index 887acb9..0f8abd3 100644
900526
--- a/lib/export/dns-pkcs11/Makefile.in
900526
+++ b/lib/export/dns-pkcs11/Makefile.in
900526
@@ -15,7 +15,7 @@
900526
 # $Id$
900526
 
900526
 top_srcdir =	@top_srcdir@
900526
-srcdir =	@top_srcdir@/lib/dns
900526
+srcdir =	@top_srcdir@/lib/dns-pkcs11
900526
 export_srcdir =	@top_srcdir@/lib/export
900526
 
900526
 # Attempt to disable parallel processing.
900526
@@ -28,16 +28,16 @@ export_srcdir =	@top_srcdir@/lib/export
900526
 
900526
 @BIND9_MAKE_INCLUDES@
900526
 
900526
-CINCLUDES =	-I. -I${top_srcdir}/lib/dns -Iinclude ${DNS_INCLUDES} -I${export_srcdir}/isc/include \
900526
-		${ISC_INCLUDES} @DST_OPENSSL_INC@ @DST_GSSAPI_INC@
900526
+CINCLUDES =	-I. -I${top_srcdir}/lib/dns-pkcs11 -Iinclude ${DNS_PKCS11_INCLUDES} -I${export_srcdir}/isc-pkcs11/include \
900526
+		${ISC_PKCS11_INCLUDES} @DST_OPENSSL_INC@ @DST_GSSAPI_INC@
900526
 
900526
-CDEFINES =	-DUSE_MD5 @CRYPTO@ @USE_GSSAPI@
900526
+CDEFINES =	-DUSE_MD5 @CRYPTO_PK11@ @USE_GSSAPI@
900526
 
900526
 CWARNINGS =
900526
 
900526
-ISCLIBS =	../isc/libisc-export.@A@
900526
+ISCLIBS =	../isc-pkcs11/libisc-pkcs11-export.@A@
900526
 
900526
-ISCDEPLIBS =	../isc/libisc-export.@A@
900526
+ISCDEPLIBS =	../isc-pkcs11/libisc-pkcs11-export.@A@
900526
 
900526
 LIBS =		@LIBS@
900526
 
900526
@@ -118,29 +118,29 @@ version.@O@: ${srcdir}/version.c
900526
 		-DLIBAGE=${LIBAGE} \
900526
 		-c ${srcdir}/version.c
900526
 
900526
-libdns-export.@SA@: ${OBJS}
900526
+libdns-pkcs11-export.@SA@: ${OBJS}
900526
 	${AR} ${ARFLAGS} $@ ${OBJS}
900526
 	${RANLIB} $@
900526
 
900526
-libdns-export.la: ${OBJS}
900526
+libdns-pkcs11-export.la: ${OBJS}
900526
 	${LIBTOOL_MODE_LINK} \
900526
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns-export.la \
900526
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns-pkcs11-export.la \
900526
 		-rpath ${export_libdir} \
900526
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
900526
-		${OBJS} ${ISCLIBS} @DNS_CRYPTO_LIBS@ ${LIBS}
900526
+		${OBJS} ${ISCLIBS} @DNS_CRYPTO_PK11_LIBS@ ${LIBS}
900526
 
900526
-timestamp: libdns-export.@A@
900526
+timestamp: libdns-pkcs11-export.@A@
900526
 	touch timestamp
900526
 
900526
 installdirs:
900526
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${export_libdir}
900526
 
900526
 install:: timestamp installdirs
900526
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libdns-export.@A@ \
900526
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libdns-pkcs11-export.@A@ \
900526
 	${DESTDIR}${export_libdir}/
900526
 
900526
 clean distclean::
900526
-	rm -f libdns-export.@A@ timestamp
900526
+	rm -f libdns-pkcs11-export.@A@ timestamp
900526
 	rm -f gen code.h include/dns/enumtype.h include/dns/enumclass.h
900526
 	rm -f include/dns/rdatastruct.h
900526
 
900526
diff --git a/lib/export/isc-pkcs11/Makefile.in b/lib/export/isc-pkcs11/Makefile.in
900526
index 4f4a9f7..f8224e7 100644
900526
--- a/lib/export/isc-pkcs11/Makefile.in
900526
+++ b/lib/export/isc-pkcs11/Makefile.in
900526
@@ -15,7 +15,7 @@
900526
 # $Id: Makefile.in,v 1.8 2010/06/09 23:50:58 tbox Exp $
900526
 
900526
 top_srcdir =	@top_srcdir@
900526
-srcdir =	@top_srcdir@/lib/isc
900526
+srcdir =	@top_srcdir@/lib/isc-pkcs11
900526
 export_srcdir =	@top_srcdir@/lib/export
900526
 
900526
 @BIND9_VERSION@
900526
@@ -25,9 +25,9 @@ export_srcdir =	@top_srcdir@/lib/export
900526
 CINCLUDES =	-I${srcdir}/unix/include \
900526
 		-I${srcdir}/@ISC_THREAD_DIR@/include \
900526
 		-I${srcdir}/@ISC_ARCH_DIR@/include \
900526
-		-I${export_srcdir}/isc/include -I${srcdir}/include \
900526
+		-I${export_srcdir}/isc-pkcs11/include -I${srcdir}/include \
900526
 		@ISC_OPENSSL_INC@
900526
-CDEFINES =	@CRYPTO@ -DUSE_APPIMPREGISTER -DUSE_MEMIMPREGISTER \
900526
+CDEFINES =	@CRYPTO_PK11@ -DUSE_APPIMPREGISTER -DUSE_MEMIMPREGISTER \
900526
 		-DUSE_SOCKETIMPREGISTER -DUSE_TASKIMPREGISTER \
900526
 		-DUSE_TIMERIMPREGISTER
900526
 CWARNINGS =
900526
@@ -119,26 +119,26 @@ version.@O@: ${srcdir}/version.c
900526
 		-DLIBAGE=${LIBAGE} \
900526
 		-c ${srcdir}/version.c
900526
 
900526
-libisc-export.@SA@: ${OBJS}
900526
+libisc-pkcs11-export.@SA@: ${OBJS}
900526
 	${AR} ${ARFLAGS} $@ ${OBJS}
900526
 	${RANLIB} $@
900526
 
900526
-libisc-export.la: ${OBJS}
900526
+libisc-pkcs11-export.la: ${OBJS}
900526
 	${LIBTOOL_MODE_LINK} \
900526
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-export.la \
900526
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11-export.la \
900526
 		-rpath ${export_libdir} \
900526
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
900526
 		${OBJS} ${LIBS}
900526
 
900526
-timestamp: libisc-export.@A@
900526
+timestamp: libisc-pkcs11-export.@A@
900526
 	touch timestamp
900526
 
900526
 installdirs:
900526
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${export_libdir}
900526
 
900526
 install:: timestamp installdirs
900526
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libisc-export.@A@ \
900526
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libisc-pkcs11-export.@A@ \
900526
 	${DESTDIR}${export_libdir}
900526
 
900526
 clean distclean::
900526
-	rm -f libisc-export.@A@ libisc-export.la timestamp
900526
+	rm -f libisc-pkcs11-export.@A@ libisc-pkcs11-export.la timestamp
900526
diff --git a/lib/isc-pkcs11/Makefile.in b/lib/isc-pkcs11/Makefile.in
900526
index df62ec9..d9f0107 100644
900526
--- a/lib/isc-pkcs11/Makefile.in
900526
+++ b/lib/isc-pkcs11/Makefile.in
900526
@@ -31,8 +31,8 @@ CINCLUDES =	-I${srcdir}/unix/include \
900526
 		-I${srcdir}/@ISC_THREAD_DIR@/include \
900526
 		-I${srcdir}/@ISC_ARCH_DIR@/include \
900526
 		-I./include \
900526
-		-I${srcdir}/include @ISC_OPENSSL_INC@ ${DNS_INCLUDES}
900526
-CDEFINES =	@CRYPTO@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
900526
+		-I${srcdir}/include ${DNS_PKCS11_INCLUDES}
900526
+CDEFINES =	@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
900526
 CWARNINGS =
900526
 
900526
 # Alphabetically
900526
@@ -110,35 +110,35 @@ version.@O@: version.c
900526
 		-DLIBAGE=${LIBAGE} \
900526
 		-c ${srcdir}/version.c
900526
 
900526
-libisc.@SA@: ${OBJS} ${SYMTBLOBJS}
900526
+libisc-pkcs11.@SA@: ${OBJS} ${SYMTBLOBJS}
900526
 	${AR} ${ARFLAGS} $@ ${OBJS} ${SYMTBLOBJS}
900526
 	${RANLIB} $@
900526
 
900526
-libisc-nosymtbl.@SA@: ${OBJS}
900526
+libisc-pkcs11-nosymtbl.@SA@: ${OBJS}
900526
 	${AR} ${ARFLAGS} $@ ${OBJS}
900526
 	${RANLIB} $@
900526
 
900526
-libisc.la: ${OBJS} ${SYMTBLOBJS}
900526
+libisc-pkcs11.la: ${OBJS} ${SYMTBLOBJS}
900526
 	${LIBTOOL_MODE_LINK} \
900526
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc.la -rpath ${libdir} \
900526
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11.la -rpath ${libdir} \
900526
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
900526
 		${OBJS} ${SYMTBLOBJS} ${LIBS}
900526
 
900526
-libisc-nosymtbl.la: ${OBJS}
900526
+libisc-pkcs11-nosymtbl.la: ${OBJS}
900526
 	${LIBTOOL_MODE_LINK} \
900526
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-nosymtbl.la -rpath ${libdir} \
900526
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11-nosymtbl.la -rpath ${libdir} \
900526
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
900526
 		${OBJS} ${LIBS}
900526
 
900526
-timestamp: libisc.@A@ libisc-nosymtbl.@A@
900526
+timestamp: libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@
900526
 	touch timestamp
900526
 
900526
 installdirs:
900526
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
900526
 
900526
 install:: timestamp installdirs
900526
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libisc.@A@ ${DESTDIR}${libdir}
900526
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} libisc-pkcs11.@A@ ${DESTDIR}${libdir}
900526
 
900526
 clean distclean::
900526
-	rm -f libisc.@A@ libisc-nosymtbl.@A@ libisc.la \
900526
-	libisc-nosymtbl.la timestamp
900526
+	rm -f libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@ libisc-pkcs11.la \
900526
+	libisc-pkcs11-nosymtbl.la timestamp
900526
diff --git a/make/includes.in b/make/includes.in
900526
index f2f1b3f..639477c 100644
900526
--- a/make/includes.in
900526
+++ b/make/includes.in
900526
@@ -46,3 +46,13 @@ BIND9_INCLUDES = @BIND9_BIND9_BUILDINCLUDE@ \
900526
 
900526
 TEST_INCLUDES = \
900526
 	-I${top_srcdir}/lib/tests/include
900526
+
900526
+ISC_PKCS11_INCLUDES = @BIND9_ISC_BUILDINCLUDE@ \
900526
+	-I${top_srcdir}/lib/isc-pkcs11 \
900526
+	-I${top_srcdir}/lib/isc-pkcs11/include \
900526
+	-I${top_srcdir}/lib/isc-pkcs11/unix/include \
900526
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_THREAD_DIR@/include \
900526
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_ARCH_DIR@/include
900526
+
900526
+DNS_PKCS11_INCLUDES = @BIND9_DNS_BUILDINCLUDE@ \
900526
+	-I${top_srcdir}/lib/dns-pkcs11/include