]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2738. [func] Add RSASHA256 and RSASHA512 tests to the dnssec system
authorMark Andrews <marka@isc.org>
Tue, 27 Oct 2009 22:25:37 +0000 (22:25 +0000)
committerMark Andrews <marka@isc.org>
Tue, 27 Oct 2009 22:25:37 +0000 (22:25 +0000)
                        test. [RT #20453]

15 files changed:
CHANGES
bin/tests/system/dnssec/clean.sh
bin/tests/system/dnssec/ns1/sign.sh
bin/tests/system/dnssec/ns2/example.db.in
bin/tests/system/dnssec/ns2/sign.sh
bin/tests/system/dnssec/ns3/named.conf
bin/tests/system/dnssec/ns3/rsasha256.example.db.in [new file with mode: 0644]
bin/tests/system/dnssec/ns3/rsasha512.example.db.in [new file with mode: 0644]
bin/tests/system/dnssec/ns3/sign.sh
bin/tests/system/dnssec/setup.sh
bin/tests/system/dnssec/tests.sh
configure.in
lib/dns/dst_api.c
lib/dns/dst_internal.h
lib/dns/opensslrsa_link.c

diff --git a/CHANGES b/CHANGES
index f89fac388bca03aa1830f1971f717b4257642fa9..d5a78f0488a8888391a6e7a1cc607be4f486d137 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+2738.  [func]          Add RSASHA256 and RSASHA512 tests to the dnssec system
+                       test. [RT #20453]
+
 2737.  [func]          UPDATE requests can leak existance information.
                        [RT #17261]
 
index 3f207d5c6a28dde877334af11ceceacefab69ea5..63b834be5d6ea631afed2df79df5d821961d9834 100644 (file)
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: clean.sh,v 1.23 2008/09/25 04:02:38 tbox Exp $
+# $Id: clean.sh,v 1.24 2009/10/27 22:25:37 marka Exp $
 
 rm -f */K* */keyset-* */dsset-* */dlvset-* */signedkey-* */*.signed */trusted.conf */tmp* */*.jnl */*.bk
 rm -f ns1/root.db ns2/example.db ns3/secure.example.db
 rm -f ns3/unsecure.example.db ns3/bogus.example.db ns3/keyless.example.db
 rm -f ns3/dynamic.example.db ns3/dynamic.example.db.signed.jnl
+rm -f ns3/rsasha256.example.db ns3/rsasha512.example.db
 rm -f ns2/private.secure.example.db
 rm -f */example.bk
 rm -f dig.out.*
index 410450aecadd46868955b45f3618647bae498514..55e11bba455abee4d87e7277f85dabb47c1b822f 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
 #
 # Copyright (C) 2004, 2006-2009  Internet Systems Consortium, Inc. ("ISC")
 # Copyright (C) 2000-2003  Internet Software Consortium.
@@ -15,7 +15,7 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: sign.sh,v 1.28 2009/07/19 04:18:04 each Exp $
+# $Id: sign.sh,v 1.29 2009/10/27 22:25:37 marka Exp $
 
 SYSTEMTESTTOP=../..
 . $SYSTEMTESTTOP/conf.sh
index c2b5e987a7e7eb66b74fd734df17c9f07d690df6..24be4d5b8ea224ba7fd99badef48e114a0aa1ba7 100644 (file)
@@ -13,7 +13,7 @@
 ; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 ; PERFORMANCE OF THIS SOFTWARE.
 
-; $Id: example.db.in,v 1.19 2008/09/25 04:02:38 tbox Exp $
+; $Id: example.db.in,v 1.20 2009/10/27 22:25:37 marka Exp $
 
 $TTL 300       ; 5 minutes
 @                      IN SOA  mname1. . (
@@ -95,3 +95,9 @@ multiple              NS      ns.multiple
 ns.multiple            A       10.53.0.3
 
 *.wild                 A       10.0.0.27
+
+rsasha256              NS      ns.rsasha256
+ns.rsasha256           A       10.53.0.3
+
+rsasha512              NS      ns.rsasha512
+ns.rsasha512           A       10.53.0.3
index e9ce8f2e9f95cd51cd7bd78e250fee16cdd5d2ec..17df3d27607a6e69332789626b044f14af1da1c1 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
 #
 # Copyright (C) 2004, 2006-2009  Internet Systems Consortium, Inc. ("ISC")
 # Copyright (C) 2000-2003  Internet Software Consortium.
@@ -15,7 +15,7 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: sign.sh,v 1.33 2009/07/19 04:18:04 each Exp $
+# $Id: sign.sh,v 1.34 2009/10/27 22:25:37 marka Exp $
 
 SYSTEMTESTTOP=../..
 . $SYSTEMTESTTOP/conf.sh
@@ -30,7 +30,8 @@ zonefile=example.db
 
 ( cd ../ns3 && sh sign.sh )
 
-for subdomain in secure bogus dynamic keyless nsec3 optout nsec3-unknown optout-unknown multiple
+for subdomain in secure bogus dynamic keyless nsec3 optout nsec3-unknown \
+    optout-unknown multiple rsasha256 rsasha512
 do
        cp ../ns3/dsset-$subdomain.example. .
 done
index 38f4ad022d51dd77be7fa1893ee6b11596576443..78b6389951f30a8714eade4b8bfe6a36b25c8cae 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: named.conf,v 1.33 2008/09/25 04:02:38 tbox Exp $ */
+/* $Id: named.conf,v 1.34 2009/10/27 22:25:37 marka Exp $ */
 
 // NS3
 
@@ -156,4 +156,14 @@ zone "rfc2335.example" {
        file "rfc2335.example.bk";
 };
 
+zone "rsasha256.example" {
+       type master;
+       file "rsasha256.example.db.signed";
+};
+
+zone "rsasha512.example" {
+       type master;
+       file "rsasha512.example.db.signed";
+};
+
 include "trusted.conf";
diff --git a/bin/tests/system/dnssec/ns3/rsasha256.example.db.in b/bin/tests/system/dnssec/ns3/rsasha256.example.db.in
new file mode 100644 (file)
index 0000000..a25c073
--- /dev/null
@@ -0,0 +1,33 @@
+; Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
+;
+; Permission to use, copy, modify, and/or distribute this software for any
+; purpose with or without fee is hereby granted, provided that the above
+; copyright notice and this permission notice appear in all copies.
+;
+; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+; AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+; PERFORMANCE OF THIS SOFTWARE.
+
+; $Id: rsasha256.example.db.in,v 1.2 2009/10/27 22:25:37 marka Exp $
+
+$TTL 300       ; 5 minutes
+@                      IN SOA  mname1. . (
+                               2009102722 ; serial
+                               20         ; refresh (20 seconds)
+                               20         ; retry (20 seconds)
+                               1814400    ; expire (3 weeks)
+                               3600       ; minimum (1 hour)
+                               )
+                       NS      ns
+ns                     A       10.53.0.3
+
+a                      A       10.0.0.1
+b                      A       10.0.0.2
+d                      A       10.0.0.4
+z                      A       10.0.0.26
+a.a.a.a.a.a.a.a.a.a.e  A       10.0.0.27
+x                      CNAME   a
diff --git a/bin/tests/system/dnssec/ns3/rsasha512.example.db.in b/bin/tests/system/dnssec/ns3/rsasha512.example.db.in
new file mode 100644 (file)
index 0000000..16ce88b
--- /dev/null
@@ -0,0 +1,33 @@
+; Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
+;
+; Permission to use, copy, modify, and/or distribute this software for any
+; purpose with or without fee is hereby granted, provided that the above
+; copyright notice and this permission notice appear in all copies.
+;
+; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+; AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+; PERFORMANCE OF THIS SOFTWARE.
+
+; $Id: rsasha512.example.db.in,v 1.2 2009/10/27 22:25:37 marka Exp $
+
+$TTL 300       ; 5 minutes
+@                      IN SOA  mname1. . (
+                               2009102722 ; serial
+                               20         ; refresh (20 seconds)
+                               20         ; retry (20 seconds)
+                               1814400    ; expire (3 weeks)
+                               3600       ; minimum (1 hour)
+                               )
+                       NS      ns
+ns                     A       10.53.0.3
+
+a                      A       10.0.0.1
+b                      A       10.0.0.2
+d                      A       10.0.0.4
+z                      A       10.0.0.26
+a.a.a.a.a.a.a.a.a.a.e  A       10.0.0.27
+x                      CNAME   a
index cc91ef6213920de53db6b2dffba11be282e4140f..936de270d1396a13adcb8f77d22041df308127ff 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
 #
 # Copyright (C) 2004, 2006-2009  Internet Systems Consortium, Inc. ("ISC")
 # Copyright (C) 2000-2002  Internet Software Consortium.
@@ -15,7 +15,7 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: sign.sh,v 1.28 2009/09/25 06:47:50 each Exp $
+# $Id: sign.sh,v 1.29 2009/10/27 22:25:37 marka Exp $
 
 SYSTEMTESTTOP=../..
 . $SYSTEMTESTTOP/conf.sh
@@ -222,3 +222,29 @@ mv $zonefile.signed $zonefile
 $SIGNER -P -u3 CCCC -r $RANDFILE -o $zone $zonefile > /dev/null
 mv $zonefile.signed $zonefile
 $SIGNER -P -u3 DDDD -r $RANDFILE -o $zone $zonefile > /dev/null
+
+#
+# A RSASHA256 zone.
+#
+zone=rsasha256.example.
+infile=rsasha256.example.db.in
+zonefile=rsasha256.example.db
+
+keyname=`$KEYGEN -r $RANDFILE -a RSASHA256 -b 768 -n zone $zone`
+
+cat $infile $keyname.key >$zonefile
+
+$SIGNER -P -r $RANDFILE -o $zone $zonefile > /dev/null
+
+#
+# A RSASHA512 zone.
+#
+zone=rsasha512.example.
+infile=rsasha512.example.db.in
+zonefile=rsasha512.example.db
+
+keyname=`$KEYGEN -r $RANDFILE -a RSASHA512 -b 1024 -n zone $zone`
+
+cat $infile $keyname.key >$zonefile
+
+$SIGNER -P -r $RANDFILE -o $zone $zonefile > /dev/null
index 913589b8f5489bacfb4a3a43eaee4f31d4ba1a7b..ca77f30a7d2c7d7b9a030935dd5d82d773805d61 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
 #
 # Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
 # Copyright (C) 2000, 2001  Internet Software Consortium.
@@ -15,7 +15,7 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: setup.sh,v 1.16 2009/03/02 23:47:43 tbox Exp $
+# $Id: setup.sh,v 1.17 2009/10/27 22:25:37 marka Exp $
 
 ../../../tools/genrandom 400 random.data
 
index 57faa63787af7df864260a0e4c1f0ec5365b526c..ff620024e670afe7154ff6f0a43f1ab4d86390b3 100644 (file)
@@ -15,7 +15,7 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: tests.sh,v 1.53 2008/09/25 04:02:38 tbox Exp $
+# $Id: tests.sh,v 1.54 2009/10/27 22:25:37 marka Exp $
 
 SYSTEMTESTTOP=..
 . $SYSTEMTESTTOP/conf.sh
@@ -607,6 +607,26 @@ n=`expr $n + 1`
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+echo "I:checking positive validation RSASHA256 NSEC ($n)"
+ret=0
+$DIG $DIGOPTS +noauth a.rsasha256.example. @10.53.0.3 a > dig.out.ns3.test$n || ret=1
+$DIG $DIGOPTS +noauth a.rsasha256.example. @10.53.0.4 a > dig.out.ns4.test$n || ret=1
+$PERL ../digcomp.pl dig.out.ns3.test$n dig.out.ns4.test$n || ret=1
+grep "flags:.*ad.*QUERY" dig.out.ns4.test$n > /dev/null || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
+echo "I:checking positive validation RSASHA512 NSEC ($n)"
+ret=0
+$DIG $DIGOPTS +noauth a.rsasha512.example. @10.53.0.3 a > dig.out.ns3.test$n || ret=1
+$DIG $DIGOPTS +noauth a.rsasha512.example. @10.53.0.4 a > dig.out.ns4.test$n || ret=1
+$PERL ../digcomp.pl dig.out.ns3.test$n dig.out.ns4.test$n || ret=1
+grep "flags:.*ad.*QUERY" dig.out.ns4.test$n > /dev/null || ret=1
+n=`expr $n + 1`
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
 echo "I:checking cd bit on a query that should fail ($n)"
 ret=0
 $DIG $DIGOPTS a.bogus.example. soa @10.53.0.4 \
index af79aad318ff948788a58ac49e593fb4ced9e86f..e815f03bb0225b59bcbee20762e6070baf0d198d 100644 (file)
@@ -18,7 +18,7 @@ AC_DIVERT_PUSH(1)dnl
 esyscmd([sed "s/^/# /" COPYRIGHT])dnl
 AC_DIVERT_POP()dnl
 
-AC_REVISION($Revision: 1.486 $)
+AC_REVISION($Revision: 1.487 $)
 
 AC_INIT(lib/dns/name.c)
 AC_PREREQ(2.59)
@@ -666,8 +666,10 @@ esac
                else
                        AC_MSG_RESULT(no)
                fi
+               AC_CHECK_FUNCS(EVP_sha256 EVP_sha512)
                CFLAGS="$saved_cflags"
                LIBS="$saved_libs"
+
                ;;
 esac
 
@@ -1941,8 +1943,10 @@ int getnameinfo(const struct sockaddr *, socklen_t, char *,
                 socklen_t, char *, socklen_t, unsigned int);],
 [ return (0);],
        [AC_MSG_RESULT(socklen_t for buflen; u_int for flags)
-        AC_DEFINE(IRS_GETNAMEINFO_BUFLEN_T, socklen_t)
-        AC_DEFINE(IRS_GETNAMEINFO_FLAGS_T, unsigned int)],
+        AC_DEFINE(IRS_GETNAMEINFO_BUFLEN_T, socklen_t,
+                  [Define to the buffer length type used by getnameinfo(3).])
+        AC_DEFINE(IRS_GETNAMEINFO_FLAGS_T, unsigned int,
+                  [Define to the flags type used by getnameinfo(3).])],
 [AC_TRY_COMPILE([
 #include <sys/types.h>
 #include <sys/socket.h>
index 9a08ed5d79cf98f0bda83d9d41a0749ed42d02c5..420aaf2a0677ce3f92145894d6232dbbc0ac8a14 100644 (file)
@@ -31,7 +31,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: dst_api.c,v 1.44 2009/10/24 09:46:18 fdupont Exp $
+ * $Id: dst_api.c,v 1.45 2009/10/27 22:25:37 marka Exp $
  */
 
 /*! \file */
@@ -201,11 +201,16 @@ dst_lib_init2(isc_mem_t *mctx, isc_entropy_t *ectx,
        RETERR(dst__hmacsha512_init(&dst_t_func[DST_ALG_HMACSHA512]));
 #ifdef OPENSSL
        RETERR(dst__openssl_init(engine));
-       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSAMD5]));
-       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA1]));
-       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_NSEC3RSASHA1]));
-       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA256]));
-       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA512]));
+       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSAMD5],
+                                   DST_ALG_RSAMD5));
+       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA1],
+                                   DST_ALG_RSASHA1));
+       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_NSEC3RSASHA1],
+                                   DST_ALG_NSEC3RSASHA1));
+       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA256],
+                                   DST_ALG_RSASHA256));
+       RETERR(dst__opensslrsa_init(&dst_t_func[DST_ALG_RSASHA512],
+                                   DST_ALG_RSASHA512));
 #ifdef HAVE_OPENSSL_DSA
        RETERR(dst__openssldsa_init(&dst_t_func[DST_ALG_DSA]));
        RETERR(dst__openssldsa_init(&dst_t_func[DST_ALG_NSEC3DSA]));
index 19b0f8bf2cda66de692578986a948f6448ae4d10..84e461a70f3232e8b19e9d698a7635d82b6450e7 100644 (file)
@@ -29,7 +29,7 @@
  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dst_internal.h,v 1.22 2009/10/24 09:46:19 fdupont Exp $ */
+/* $Id: dst_internal.h,v 1.23 2009/10/27 22:25:37 marka Exp $ */
 
 #ifndef DST_DST_INTERNAL_H
 #define DST_DST_INTERNAL_H 1
@@ -201,7 +201,8 @@ isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
 isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
 isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
 isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
-isc_result_t dst__opensslrsa_init(struct dst_func **funcp);
+isc_result_t dst__opensslrsa_init(struct dst_func **funcp,
+                                 unsigned char algorithm);
 isc_result_t dst__openssldsa_init(struct dst_func **funcp);
 isc_result_t dst__openssldh_init(struct dst_func **funcp);
 isc_result_t dst__gssapi_init(struct dst_func **funcp);
index 68b0a84d8c43aba2b20c8a3a194468525e93a5be..dea074b51e2cd57f3df4cfbea99dcae6ecb814b9 100644 (file)
 
 /*
  * Principal Author: Brian Wellington
- * $Id: opensslrsa_link.c,v 1.33 2009/10/24 09:46:19 fdupont Exp $
+ * $Id: opensslrsa_link.c,v 1.34 2009/10/27 22:25:37 marka Exp $
  */
 #ifdef OPENSSL
+#include <config.h>
+
 #ifndef USE_EVP
+#if !defined(HAVE_EVP_SHA256) || !defined(HAVE_EVP_SHA512)
+#define USE_EVP 0
+#else
 #define USE_EVP 1
 #endif
+#endif
 
-#include <config.h>
 
 #include <isc/entropy.h>
 #include <isc/md5.h>
 
 static isc_result_t opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data);
 
-#if defined(USE_EVP) && OPENSSL_VERSION_NUMBER < 0x00908000L
-/*
- * OpenSSL 0.9.7 doesn't support SHA2.
- * Provide the method functions we need.
- */
-
-/*
- * Use our namespace, not OpenSSL's.
- */
-#define EVP_sha256 ISC_EVP_sha256
-#define EVP_sha512 ISC_EVP_sha512
-
-/*
- * OpensSSL 0.9.8 defines these.
- */
-#if 0
-#define NID_sha256WithRSAEncryption    668
-#define NID_sha256                     672
-#define NID_sha512WithRSAEncryption    670
-#define NID_sha512                     674
-#else
-#define NID_sha256WithRSAEncryption    0
-#define NID_sha256                     0
-#define NID_sha512WithRSAEncryption    0
-#define NID_sha512                     0
-#endif
-
-static int init256(EVP_MD_CTX *ctx)
-       { isc_sha256_init(ctx->md_data); return 1; }
-static int update256(EVP_MD_CTX *ctx,const void *data, unsigned long count)
-       { isc_sha256_update(ctx->md_data,data,count); return 1; }
-static int final256(EVP_MD_CTX *ctx,unsigned char *md)
-       { isc_sha256_final(md,ctx->md_data); return 1; }
-
-static const EVP_MD sha256_md=
-       {
-       NID_sha256,
-       NID_sha256WithRSAEncryption,
-       ISC_SHA256_DIGESTLENGTH,
-       0,
-       init256,
-       update256,
-       final256,
-       NULL,
-       NULL,
-       EVP_PKEY_RSA_method,
-       ISC_SHA256_BLOCK_LENGTH,
-       sizeof(EVP_MD *)+sizeof(isc_sha256_t),
-       };
-
-static const EVP_MD *EVP_sha256(void)
-       { return(&sha256_md); }
-
-static int init512(EVP_MD_CTX *ctx)
-       { isc_sha512_init(ctx->md_data); return 1; }
-static int update512(EVP_MD_CTX *ctx,const void *data,unsigned long count)
-       { isc_sha512_update(ctx->md_data,data,count); return 1; }
-static int final512(EVP_MD_CTX *ctx,unsigned char *md)
-       { isc_sha512_final(md,ctx->md_data); return 1; }
-
-static const EVP_MD sha512_md=
-       {
-       NID_sha512,
-       NID_sha512WithRSAEncryption,
-       ISC_SHA512_DIGESTLENGTH,
-       0,
-       init512,
-       update512,
-       final512,
-       NULL,
-       NULL,
-       EVP_PKEY_RSA_method,
-       ISC_SHA512_BLOCK_LENGTH,
-       sizeof(EVP_MD *)+sizeof(isc_sha512_t),
-       };
-
-static const EVP_MD *EVP_sha512(void)
-       { return(&sha512_md); }
-#endif
-
 static isc_result_t
 opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx) {
 #if USE_EVP
@@ -213,12 +138,16 @@ opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx) {
        case DST_ALG_NSEC3RSASHA1:
                type = EVP_sha1();      /* SHA1 + RSA */
                break;
+#ifdef HAVE_EVP_SHA256
        case DST_ALG_RSASHA256:
                type = EVP_sha256();    /* SHA256 + RSA */
                break;
+#endif
+#ifdef HAVE_EVP_SHA512
        case DST_ALG_RSASHA512:
                type = EVP_sha512();
                break;
+#endif
        default:
                INSIST(0);
        }
@@ -413,6 +342,21 @@ opensslrsa_adddata(dst_context_t *dctx, const isc_region_t *data) {
        return (ISC_R_SUCCESS);
 }
 
+#if ! USE_EVP && OPENSSL_VERSION_NUMBER < 0x00908000L
+/*
+ * Digest prefixes from RFC XXXX (draft-ietf-dnsext-dnssec-rsasha256-14).
+ */
+static unsigned char sha256_prefix[] =
+        { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
+          0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20};
+static unsigned char sha512_prefix[] =
+        { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48,
+          0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40};
+#define PREFIXLEN sizeof(sha512_prefix)
+#else
+#define PREFIXLEN 0
+#endif
+
 static isc_result_t
 opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
        dst_key_t *key = dctx->key;
@@ -424,7 +368,7 @@ opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
 #else
        RSA *rsa = key->keydata.rsa;
        /* note: ISC_SHA512_DIGESTLENGTH >= ISC_*_DIGESTLENGTH */
-       unsigned char digest[ISC_SHA512_DIGESTLENGTH];
+       unsigned char digest[PREFIXLEN + ISC_SHA512_DIGESTLENGTH];
        int status;
        int type = 0;
        unsigned int digestlen = 0;
@@ -432,6 +376,10 @@ opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
        unsigned long err;
        const char* file;
        int line;
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+       unsigned int prefixlen = 0;
+       const unsigned char *prefix = NULL;
+#endif
 #endif
 
        REQUIRE(dctx->key->key_alg == DST_ALG_RSAMD5 ||
@@ -478,8 +426,13 @@ opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
                        isc_sha256_t *sha256ctx = dctx->ctxdata.sha256ctx;
 
                        isc_sha256_final(digest, sha256ctx);
-                       type = NID_sha256;
                        digestlen = ISC_SHA256_DIGESTLENGTH;
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+                       prefix = sha256_prefix;
+                       prefixlen = sizeof(sha256_prefix);
+#else
+                       type = NID_sha256;
+#endif
                }
                break;
        case DST_ALG_RSASHA512:
@@ -487,15 +440,53 @@ opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
                        isc_sha512_t *sha512ctx = dctx->ctxdata.sha512ctx;
 
                        isc_sha512_final(digest, sha512ctx);
-                       type = NID_sha512;
                        digestlen = ISC_SHA512_DIGESTLENGTH;
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+                       prefix = sha512_prefix;
+                       prefixlen = sizeof(sha512_prefix);
+#else
+                       type = NID_sha512;
+#endif
                }
                break;
        default:
                INSIST(0);
        }
 
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+       switch (dctx->key->key_alg) {
+       case DST_ALG_RSAMD5:
+       case DST_ALG_RSASHA1:
+       case DST_ALG_NSEC3RSASHA1:
+               INSIST(type != 0);
+               status = RSA_sign(type, digest, digestlen, r.base,
+                                 &siglen, rsa);
+               break;
+
+       case DST_ALG_RSASHA256:
+       case DST_ALG_RSASHA512:
+               INSIST(prefix != NULL);
+               INSIST(prefixlen != 0);
+               INSIST(prefixlen + digestlen <= sizeof(digest));
+
+               memmove(digest + prefixlen, digest, digestlen);
+               memcpy(digest, prefix, prefixlen);
+               status = RSA_private_encrypt(digestlen + prefixlen,
+                                            digest, r.base, rsa,
+                                            RSA_PKCS1_PADDING);
+               if (status < 0)
+                       status = 0;
+               else
+                       siglen = status;
+               break;
+
+       default:
+               INSIST(0);
+       }
+#else
+       INSIST(type != 0);
        status = RSA_sign(type, digest, digestlen, r.base, &siglen, rsa);
+#endif
        if (status == 0) {
                err = ERR_peek_error_line(&file, &line);
                if (err != 0U) {
@@ -523,6 +514,10 @@ opensslrsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
        int type = 0;
        unsigned int digestlen = 0;
        RSA *rsa = key->keydata.rsa;
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+       unsigned int prefixlen = 0;
+       const unsigned char *prefix = NULL;
+#endif
 #endif
 
        REQUIRE(dctx->key->key_alg == DST_ALG_RSAMD5 ||
@@ -559,8 +554,13 @@ opensslrsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
                        isc_sha256_t *sha256ctx = dctx->ctxdata.sha256ctx;
 
                        isc_sha256_final(digest, sha256ctx);
-                       type = NID_sha256;
                        digestlen = ISC_SHA256_DIGESTLENGTH;
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+                       prefix = sha256_prefix;
+                       prefixlen = sizeof(sha256_prefix);
+#else
+                       type = NID_sha256;
+#endif
                }
                break;
        case DST_ALG_RSASHA512:
@@ -568,19 +568,70 @@ opensslrsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
                        isc_sha512_t *sha512ctx = dctx->ctxdata.sha512ctx;
 
                        isc_sha512_final(digest, sha512ctx);
-                       type = NID_sha512;
                        digestlen = ISC_SHA512_DIGESTLENGTH;
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+                       prefix = sha512_prefix;
+                       prefixlen = sizeof(sha512_prefix);
+#else
+                       type = NID_sha512;
+#endif
                }
                break;
        default:
                INSIST(0);
        }
 
-       if (sig->length < (unsigned int) RSA_size(rsa))
+       if (sig->length != (unsigned int) RSA_size(rsa))
                return (DST_R_VERIFYFAILURE);
 
+#if OPENSSL_VERSION_NUMBER < 0x00908000L
+       switch (dctx->key->key_alg) {
+       case DST_ALG_RSAMD5:
+       case DST_ALG_RSASHA1:
+       case DST_ALG_NSEC3RSASHA1:
+               INSIST(type != 0);
+               status = RSA_verify(type, digest, digestlen, sig->base,
+                                   RSA_size(rsa), rsa);
+               break;
+
+       case DST_ALG_RSASHA256: 
+       case DST_ALG_RSASHA512:
+               {
+                       /*
+                        * 1024 is big enough for all valid RSA bit sizes
+                        * for use with DNSSEC.
+                        */
+                       unsigned char original[PREFIXLEN + 1024];
+
+                       INSIST(prefix != NULL);
+                       INSIST(prefixlen != 0U);
+
+                       if (RSA_size(rsa) > (int)sizeof(original))
+                               return (DST_R_VERIFYFAILURE);
+
+                       status = RSA_public_decrypt(sig->length, sig->base,
+                                                   original, rsa,
+                                                   RSA_PKCS1_PADDING);
+                       if (status <= 0) 
+                               return (DST_R_VERIFYFAILURE);
+                       if (status != (int)(prefixlen + digestlen)) 
+                               return (DST_R_VERIFYFAILURE);
+                       if (memcmp(original, prefix, prefixlen))
+                               return (DST_R_VERIFYFAILURE);
+                       if (memcmp(original + prefixlen, digest, digestlen))
+                               return (DST_R_VERIFYFAILURE);
+                       status = 1;
+               }
+               break;
+
+       default:
+               INSIST(0);
+       }
+#else
+       INSIST(type != 0);
        status = RSA_verify(type, digest, digestlen, sig->base,
-                           RSA_size(rsa), rsa);
+                            RSA_size(rsa), rsa);
+#endif
 #endif
        if (status != 1)
                return (dst__openssl_toresult(DST_R_VERIFYFAILURE));
@@ -1328,10 +1379,26 @@ static dst_func_t opensslrsa_functions = {
 };
 
 isc_result_t
-dst__opensslrsa_init(dst_func_t **funcp) {
+dst__opensslrsa_init(dst_func_t **funcp, unsigned char algorithm) {
        REQUIRE(funcp != NULL);
-       if (*funcp == NULL)
-               *funcp = &opensslrsa_functions;
+
+       if (*funcp == NULL) {
+               switch (algorithm) {
+               case DST_ALG_RSASHA256:
+#if defined(HAVE_EVP_SHA256) || !USE_EVP
+                       *funcp = &opensslrsa_functions;
+#endif
+                       break;
+               case DST_ALG_RSASHA512:
+#if defined(HAVE_EVP_SHA512) || !USE_EVP
+                       *funcp = &opensslrsa_functions;
+#endif
+                       break;
+               default:
+                       *funcp = &opensslrsa_functions;
+                       break;
+               }
+       }
        return (ISC_R_SUCCESS);
 }