Browse Source

[trac936] use botan-provided version macro

turns out botan had a check for exactly this, so we don't need to reinvent our own
Jelte Jansen 14 years ago
parent
commit
77def12e8d
2 changed files with 15 additions and 67 deletions
  1. 4 53
      configure.ac
  2. 11 14
      src/lib/cryptolink/crypto_hmac.cc

+ 4 - 53
configure.ac

@@ -432,20 +432,6 @@ LDFLAGS_SAVED="$LDFLAGS"
 LDFLAGS="$BOTAN_LDFLAGS $LDFLAGS"
 
 AC_CHECK_HEADERS([botan/botan.h],,AC_MSG_ERROR([Missing required header files.]))
-
-# Find out which API version we have
-# We use this in cyptolink implementations
-# The defined value will have six numbers, XXYYZZ, where XX is major
-# version, YY is minor version, and ZZ is patch level
-# We do not ask for the specific function, but try out a specific
-# api call known to belong to a specific function. Therefore ZZ should,
-# at least in theory, not be relevant (and always 0). But you never know.
-# (We do assume that none of the version parts will be higher than 99)
-
-# Set to 0 so we can error if we find no compatible versions
-BOTAN_API_VERSION=0
-
-# API for 1.8
 AC_LINK_IFELSE(
         [AC_LANG_PROGRAM([#include <botan/botan.h>
                           #include <botan/hash.h>
@@ -453,46 +439,11 @@ AC_LINK_IFELSE(
                          [using namespace Botan;
                           LibraryInitializer::initialize();
                           HashFunction *h = get_hash("MD5");
-                          // 1.8 has HASH_BLOCK_SIZE
-                          size_t s = h->HASH_BLOCK_SIZE;
-                         ])
-        ],
-        [
-            AC_MSG_RESULT([checking for Botan library 1.8... yes])
-            BOTAN_API_VERSION="1.8"
-            AC_DEFINE(BOTAN_API_VERSION, [100800], [Botan API version 1.8])
-        ],
-        [
-            AC_MSG_RESULT([checking for Botan library 1.8... no])
-        ]
+                         ])],
+        [AC_MSG_RESULT([checking for Botan library... yes])],
+        [AC_MSG_RESULT([checking for Botan library... no])
+         AC_MSG_ERROR([Needs Botan library 1.8 or higher])]
 )
-
-# API for 1.9
-AC_LINK_IFELSE(
-        [AC_LANG_PROGRAM([#include <botan/botan.h>
-                          #include <botan/hash.h>
-                         ],
-                         [using namespace Botan;
-                          LibraryInitializer::initialize();
-                          HashFunction *h = get_hash("MD5");
-                          // 1.9 has hash_block_size()
-                          size_t s = h->hash_block_size();
-                         ])
-        ],
-        [
-            AC_MSG_RESULT([checking for Botan library 1.9... yes])
-            BOTAN_API_VERSION="1.9"
-            AC_DEFINE(BOTAN_API_VERSION, [100900], [Botan API version 1.9 (or higher)])
-        ],
-        [
-            AC_MSG_RESULT([checking for Botan library 1.9... no])
-        ]
-)
-
-if test "$BOTAN_API_VERSION" = "0"; then
-    AC_MSG_ERROR([Botan linking failed, need botan-1.8 or higher, and the libraries it links to])
-fi
-
 CPPFLAGS=$CPPFLAGS_SAVED
 LDFLAGS=$LDFLAGS_SAVED
 

+ 11 - 14
src/lib/cryptolink/crypto_hmac.cc

@@ -19,13 +19,12 @@
 
 #include <boost/scoped_ptr.hpp>
 
+#include <botan/version.h>
 #include <botan/botan.h>
 #include <botan/hmac.h>
 #include <botan/hash.h>
 #include <botan/types.h>
 
-// [XX] remove
-#include <iostream>
 namespace {
 const char*
 getBotanHashAlgorithmName(isc::cryptolink::HashAlgorithm algorithm) {
@@ -76,17 +75,15 @@ public:
         try {
             // use a temp var so we don't have blocks spanning
             // preprocessor directives
-            size_t block_length;
-#if (BOTAN_API_VERSION >= 100900)
-            block_length = hash->hash_block_size();
-#elif (BOTAN_API_VERSION >= 100800)
-            block_length = hash->HASH_BLOCK_SIZE;
+#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,0)
+            size_t block_length = hash->hash_block_size();
+#elif BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,8,0)
+            size_t block_length = hash->HASH_BLOCK_SIZE;
 #else
-#error "Unsupported BOTAN_API_VERSION"
+#error "Unsupported BOTAN_API_VERSION (need 1.8 or higher)"
             // added to suppress irrelevant compiler errors
-            block_length = 0;
+            size_t block_length = 0;
 #endif
-
             if (secret_len > block_length) {
                 Botan::SecureVector<Botan::byte> hashed_key =
                     hash->process(static_cast<const Botan::byte*>(secret),
@@ -95,7 +92,7 @@ public:
             } else {
                 // Apparently 1.9 considers 0 a valid secret length.
                 // We do not.
-#if (BOTAN_API_VERSION >= 100900)
+#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,0)
                 if (secret_len == 0) {
                     isc_throw(BadKey, "Bad HMAC secret length: 0");
                 }
@@ -113,12 +110,12 @@ public:
     ~HMACImpl() { }
 
     size_t getOutputLength() const {
-#if (BOTAN_API_VERSION >= 100900)
+#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,0)
         return (hmac_->output_length());
-#elif (BOTAN_API_VERSION >= 100800)
+#elif BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,8,0)
         return (hmac_->OUTPUT_LENGTH);
 #else
-#error "Unsupported BOTAN_API_VERSION"
+#error "Unsupported BOTAN_API_VERSION (need 1.8 or higher)"
         // added to suppress irrelevant compiler errors
         return 0;
 #endif