]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
make libsodium optimal
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 8 Mar 2015 14:16:15 +0000 (15:16 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 8 Mar 2015 14:16:15 +0000 (15:16 +0100)
pdns/dnsdist.cc
pdns/dnsdistdist/configure.ac
pdns/sodcrypto.cc
pdns/sodcrypto.hh

index 26fe837acda06482d474d072bb5fbcbfd23d2bbf..93f0308f40c54767dd1b65eb4f37a31565684203 100644 (file)
@@ -36,7 +36,6 @@
 #include "dnswriter.hh"
 #include "base64.hh"
 #include <fstream>
-#include <sodium.h>
 #include "sodcrypto.hh"
 #undef L
 
@@ -912,10 +911,12 @@ try
   openlog("dnsdist", LOG_PID, LOG_DAEMON);
   g_console=true;
 
+#ifdef HAVE_LIBSODIUM
   if (sodium_init() == -1) {
     cerr<<"Unable to initialize crypto library"<<endl;
     exit(EXIT_FAILURE);
   }
+#endif
 
   po::options_description desc("Allowed options"), hidden, alloptions;
   desc.add_options()
index 48abba9e39efd701d7f826689e9945e9b6fcc6c2..b6699b6edd6413f7bb12fc926a92900cb534030d 100644 (file)
@@ -5,11 +5,12 @@ AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_HEADERS([config.h])
 AC_PROG_CC
 AC_PROG_CXX
+PKG_CHECK_MODULES([libsodium], [libsodium], [AC_DEFINE([HAVE_LIBSODIUM], [1], [Define to 1 if you have libsodium])], [true])
 AC_PROG_LIBTOOL
 BOOST_REQUIRE([1.35])
 BOOST_FOREACH
 BOOST_PROGRAM_OPTIONS([mt])
-PKG_CHECK_MODULES([libsodium], [libsodium])
+
 
 PDNS_WITH_LUA
 AX_CXX_COMPILE_STDCXX_11(ext,mandatory)
index c82e5b09f69c5ff03cfe97604016b61c0afb5bfd..f212958018493a90390f146075252a28bdabb36c 100644 (file)
@@ -5,6 +5,8 @@
 #include "sodcrypto.hh"
 
 
+#ifdef HAVE_LIBSODIUM
+
 string newKey()
 {
   unsigned char key[crypto_secretbox_KEYBYTES];
@@ -32,6 +34,23 @@ std::string sodDecryptSym(const std::string& msg, const std::string& key, Sodium
   nonce.increment();
   return string((char*)decrypted, sizeof(decrypted));
 }
+#else
+std::string sodEncryptSym(const std::string& msg, const std::string& key, SodiumNonce& nonce)
+{
+  return msg;
+}
+std::string sodDecryptSym(const std::string& msg, const std::string& key, SodiumNonce& nonce)
+{
+  return msg;
+}
+
+string newKey()
+{
+  return "\"plaintext\"";
+}
+
+
+#endif
 
 
 #include "base64.hh"
index 35f2227ff415a0a9a7da6faea1f053f0c2344932..6bffcc3ae0befc3e641668584efbfeb63bd70e3c 100644 (file)
@@ -1,19 +1,19 @@
 #pragma once
+#include "config.h"
 #include <string>
 #include <stdint.h>
-#include <sodium.h>
-#include <arpa/inet.h>
-void sodTest();
-std::string newKeypair();
-
-std::string sodEncryptAsym(const std::string& msg, const std::string& secretSource,
-                      const std::string& publicDest);
-
-
-std::string sodDecryptAsym(const std::string& msg, const std::string& publicSource,
-                      const std::string& secretDest);
 
+#include <arpa/inet.h>
 
+#ifndef HAVE_LIBSODIUM
+struct SodiumNonce
+{
+       void init(){};
+       void increment(){};
+       unsigned char value[1];
+};
+#else
+#include <sodium.h>
 
 struct SodiumNonce
 {
@@ -36,7 +36,8 @@ struct SodiumNonce
 
   unsigned char value[crypto_secretbox_NONCEBYTES];
 };
-
+#endif
+std::string newKeypair();
 std::string sodEncryptSym(const std::string& msg, const std::string& key, SodiumNonce&);
 std::string sodDecryptSym(const std::string& msg, const std::string& key, SodiumNonce&);
 std::string newKey();