]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Bump minimum required polarssl version to 1.3
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 31 Jul 2015 11:02:10 +0000 (13:02 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 31 Jul 2015 11:02:10 +0000 (13:02 +0200)
m4/pdns_with_system_polarssl.m4
pdns/dnssecinfra.cc
pdns/polarrsakeyinfra.cc
pdns/sha.hh

index 959e7b60f960172df0ce4f6e791e62cc55132b9c..942b81b6306acd3023f2dc7c2828ae235959af01 100644 (file)
@@ -14,12 +14,12 @@ AC_DEFUN([PDNS_WITH_SYSTEM_POLARSSL],[
     LIBS=""
     AC_SEARCH_LIBS([sha1_hmac], [mbedtls polarssl],[
       POLARSSL_LIBS=$LIBS
-      AC_MSG_CHECKING([for PolarSSL version >= 1.1])
+      AC_MSG_CHECKING([for PolarSSL version >= 1.3])
       AC_COMPILE_IFELSE([
         AC_LANG_PROGRAM(
           [[#include <polarssl/version.h>]],
           [[
-            #if POLARSSL_VERSION_NUMBER < 0x01010000
+            #if POLARSSL_VERSION_NUMBER < 0x01030000
             #error invalid version
             #endif
           ]]
index cf7abc7f3673ee85034506347cf9c532bbdd1d8e..5db7895ebb15d4d6b1c1e09d3209d5284a0f3f10 100644 (file)
@@ -502,25 +502,25 @@ string calculateSHAHMAC(const std::string& key, const std::string& text, TSIGHas
   };
   case TSIG_SHA224:
   {
-      sha2_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 1);
+      sha256_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 1);
       res.assign(reinterpret_cast<const char*>(hash), 28);
       break;
   };
   case TSIG_SHA256:
   {
-      sha2_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 0);
+      sha256_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 0);
       res.assign(reinterpret_cast<const char*>(hash), 32);
       break;
   };
   case TSIG_SHA384:
   {
-      sha4_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 1);
+      sha512_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 1);
       res.assign(reinterpret_cast<const char*>(hash), 48);
       break;
   };
   case TSIG_SHA512:
   {
-      sha4_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 0);
+      sha512_hmac(reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), reinterpret_cast<const unsigned char*>(text.c_str()), text.size(), hash, 0);
       res.assign(reinterpret_cast<const char*>(hash), 64);
       break;
   };
index bba0193960cb1fa9e95f384f3c8a5dec7203db23..eb7da34863c18de33f2a99a6e5becb365ccf299a 100644 (file)
@@ -141,11 +141,11 @@ std::string RSADNSCryptoKeyEngine::sign(const std::string& msg) const
   md_type_t hashKind;
 
   if(hash.size()==20)
-    hashKind= SIG_RSA_SHA1;
+    hashKind= POLARSSL_MD_SHA1;
   else if(hash.size()==32) 
-    hashKind= SIG_RSA_SHA256;
+    hashKind= POLARSSL_MD_SHA256;
   else
-    hashKind = SIG_RSA_SHA512;
+    hashKind = POLARSSL_MD_SHA512;
   
   int ret=rsa_pkcs1_sign(const_cast<rsa_context*>(&d_context), NULL, NULL, RSA_PRIVATE, 
     hashKind,
@@ -164,16 +164,14 @@ bool RSADNSCryptoKeyEngine::verify(const std::string& msg, const std::string& si
   md_type_t hashKind;
   string hash=this->hash(msg);
   if(hash.size()==20)
-    hashKind= SIG_RSA_SHA1;
+    hashKind= POLARSSL_MD_SHA1;
   else if(hash.size()==32) 
-    hashKind= SIG_RSA_SHA256;
+    hashKind= POLARSSL_MD_SHA256;
   else
-    hashKind = SIG_RSA_SHA512;
+    hashKind = POLARSSL_MD_SHA512;
   
   int ret=rsa_pkcs1_verify(const_cast<rsa_context*>(&d_context),
-#if POLARSSL_VERSION_NUMBER >= 0x01020900
     NULL, NULL,
-#endif
     RSA_PUBLIC,
     hashKind,
     hash.size(),
@@ -191,20 +189,12 @@ std::string RSADNSCryptoKeyEngine::hash(const std::string& toHash) const
   } 
   else if(d_algorithm == 8) { // RSASHA256
     unsigned char hash[32];
-#if POLARSSL_VERSION_NUMBER >= 0x01030000
     sha256((unsigned char*)toHash.c_str(), toHash.length(), hash, 0);
-#else
-    sha2((unsigned char*)toHash.c_str(), toHash.length(), hash, 0);
-#endif
     return string((char*)hash, sizeof(hash));
   } 
   else if(d_algorithm == 10) { // RSASHA512
     unsigned char hash[64];
-#if POLARSSL_VERSION_NUMBER >= 0x01030000
     sha512((unsigned char*)toHash.c_str(), toHash.length(), hash, 0);
-#else
-    sha4((unsigned char*)toHash.c_str(), toHash.length(), hash, 0);
-#endif
     return string((char*)hash, sizeof(hash));
   }
   throw runtime_error("PolarSSL hashing method can't hash algorithm "+lexical_cast<string>(d_algorithm));
index cea5f52e30f643f1b6f1296e8204f26ffdbd716c..56e5484c3c858e17b95b10f8da57889672a26860 100644 (file)
@@ -3,40 +3,9 @@
 
 #include <string>
 #include <stdint.h>
-#include <polarssl/version.h>
-#if POLARSSL_VERSION_NUMBER >= 0x01030000
-  #include <polarssl/sha1.h>
-  #include <polarssl/sha256.h>
-  #include <polarssl/sha512.h>
-  typedef sha256_context sha2_context;
-  typedef sha512_context sha4_context;
-  #define sha2_finish sha256_finish
-  #define sha2_hmac sha256_hmac
-  #define sha2_hmac_finish sha256_hmac_finish
-  #define sha2_hmac_starts sha256_hmac_starts
-  #define sha2_hmac_update sha256_hmac_update
-  #define sha2_starts sha256_starts
-  #define sha2_update sha256_update
-  #define sha4_finish sha512_finish
-  #define sha4_hmac sha512_hmac
-  #define sha4_hmac_finish sha512_hmac_finish
-  #define sha4_hmac_starts sha512_hmac_starts
-  #define sha4_hmac_update sha512_hmac_update
-  #define sha4_starts sha512_starts
-  #define sha4_update sha512_update
-  #define POLARSSL_SHA2_C POLARSSL_SHA256_C
-  #define POLARSSL_SHA4_C POLARSSL_SHA512_C
-  #define SIG_RSA_SHA1    POLARSSL_MD_SHA1
-  #define SIG_RSA_SHA224  POLARSSL_MD_SHA224
-  #define SIG_RSA_SHA256  POLARSSL_MD_SHA256
-  #define SIG_RSA_SHA384  POLARSSL_MD_SHA384
-  #define SIG_RSA_SHA512  POLARSSL_MD_SHA512
-#else
-  #include <polarssl/sha1.h>
-  #include <polarssl/sha2.h>
-  #include <polarssl/sha4.h>
-  typedef int md_type_t;
-#endif
+#include <polarssl/sha1.h>
+#include <polarssl/sha256.h>
+#include <polarssl/sha512.h>
 
 class SHA1Summer
 {
@@ -60,77 +29,77 @@ private:
 class SHA224Summer
 {
 public:
-   SHA224Summer() { sha2_starts(&d_context, 1); };
+   SHA224Summer() { sha256_starts(&d_context, 1); };
    void feed(const std::string &str) { feed(str.c_str(), str.length()); };
-   void feed(const char *ptr, size_t len) { sha2_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
+   void feed(const char *ptr, size_t len) { sha256_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
    const std::string get() const { 
-     sha2_context ctx2;
+     sha256_context ctx2;
      unsigned char result[32] = {0};
      ctx2=d_context;
-     sha2_finish(&ctx2, result);
+     sha256_finish(&ctx2, result);
      return std::string(result, result + 28);
    };
 private:
    SHA224Summer(const SHA1Summer&);
    SHA224Summer& operator=(const SHA1Summer&);
-   sha2_context d_context;
+   sha256_context d_context;
 };
 
 class SHA256Summer
 {
 public:
-   SHA256Summer() { sha2_starts(&d_context, 0); };
+   SHA256Summer() { sha256_starts(&d_context, 0); };
    void feed(const std::string &str) { feed(str.c_str(), str.length()); };
-   void feed(const char *ptr, size_t len) { sha2_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
+   void feed(const char *ptr, size_t len) { sha256_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
    const std::string get() const {
-     sha2_context ctx2;
+     sha256_context ctx2;
      unsigned char result[32] = {0};
      ctx2=d_context;
-     sha2_finish(&ctx2, result);
+     sha256_finish(&ctx2, result);
      return std::string(result, result + 32);
    };
 private:
    SHA256Summer(const SHA1Summer&);
    SHA256Summer& operator=(const SHA1Summer&);
-   sha2_context d_context;
+   sha256_context d_context;
 };
 
 class SHA384Summer
 {
 public:
-   SHA384Summer() { sha4_starts(&d_context, 1); };
+   SHA384Summer() { sha512_starts(&d_context, 1); };
    void feed(const std::string &str) { feed(str.c_str(), str.length()); };
-   void feed(const char *ptr, size_t len) { sha4_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
+   void feed(const char *ptr, size_t len) { sha512_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
    const std::string get() const {
-     sha4_context ctx2;
+     sha512_context ctx2;
      unsigned char result[64] = {0};
      ctx2 = d_context;
-     sha4_finish(&ctx2, result);
+     sha512_finish(&ctx2, result);
      return std::string(result, result + 48);
    };
 private:
    SHA384Summer(const SHA1Summer&);
    SHA384Summer& operator=(const SHA1Summer&);
-   sha4_context d_context;
+   sha512_context d_context;
 };
 
 class SHA512Summer
 {
 public:
-   SHA512Summer() { sha4_starts(&d_context, 0); };
+   SHA512Summer() { sha512_starts(&d_context, 0); };
    void feed(const std::string &str) { feed(str.c_str(), str.length()); };
-   void feed(const char *ptr, size_t len) { sha4_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
+   void feed(const char *ptr, size_t len) { sha512_update(&d_context, reinterpret_cast<const unsigned char*>(ptr), len); };
    const std::string get() const {
-     sha4_context ctx2;
+     sha512_context ctx2;
      unsigned char result[64] = {0};
      ctx2=d_context;
-     sha4_finish(&ctx2, result);
+     sha512_finish(&ctx2, result);
      return std::string(result, result + sizeof result);
    };
 private:
    SHA512Summer(const SHA1Summer&);
    SHA512Summer& operator=(const SHA1Summer&);
-   sha4_context d_context;
+   sha512_context d_context;
 };
 
 #endif /* sha.hh */