]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[trac3471] cryptolink code cleanup
authorFrancis Dupont <fdupont@isc.org>
Wed, 17 Sep 2014 09:41:04 +0000 (11:41 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 17 Sep 2014 09:41:04 +0000 (11:41 +0200)
ChangeLog
src/lib/cryptolink/Makefile.am
src/lib/cryptolink/botan_common.h [new file with mode: 0644]
src/lib/cryptolink/botan_hash.cc
src/lib/cryptolink/botan_hmac.cc
src/lib/cryptolink/openssl_common.h [new file with mode: 0644]
src/lib/cryptolink/openssl_hash.cc
src/lib/cryptolink/openssl_hmac.cc

index 4bf8d71f143c76ac93219cf5326511f69f997565..93c0fffe0252c379c62a40f845b37917334e7561 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+836.   [bug]           fdupont
+       Moved duplicated getXXXHashAlgorithm() function to new
+       xxx_common.h include files in the cryptolink library.
+       (Trac #3471, git xxx)
+
 835.   [build]         fdupont
        The configure script checks if OpenSSL supports SHA-2, in order
        to avoid very old (and likely subject to unfixed security bugs)
index 3aa9fa51f1081d095cc8618302e6ac49c4c4aa75..005db8379ca3bb50e78b7d87012a7cdf7ddc1ea0 100644 (file)
@@ -13,11 +13,13 @@ libkea_cryptolink_la_SOURCES += crypto_hash.h crypto_hash.cc
 libkea_cryptolink_la_SOURCES += crypto_hmac.h crypto_hmac.cc
 if HAVE_BOTAN
 libkea_cryptolink_la_SOURCES += botan_link.cc
+libkea_cryptolink_la_SOURCES += botan_common.h
 libkea_cryptolink_la_SOURCES += botan_hash.cc
 libkea_cryptolink_la_SOURCES += botan_hmac.cc
 endif
 if HAVE_OPENSSL
 libkea_cryptolink_la_SOURCES += openssl_link.cc
+libkea_cryptolink_la_SOURCES += openssl_common.h
 libkea_cryptolink_la_SOURCES += openssl_hash.cc
 libkea_cryptolink_la_SOURCES += openssl_hmac.cc
 endif
diff --git a/src/lib/cryptolink/botan_common.h b/src/lib/cryptolink/botan_common.h
new file mode 100644 (file)
index 0000000..0434c3a
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (C) 2014  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.
+
+namespace isc {
+namespace cryptolink {
+
+/// @brief Decode the HashAlgorithm enum into a name usable by Botan
+///
+/// @param algorithm algorithm to be converted
+/// @return static text representation of the algorithm name
+const char*
+getBotanHashAlgorithmName(isc::cryptolink::HashAlgorithm algorithm);
+
+} // namespace cryptolink
+} // namespace isc
index 2df255d35e70346c2abcae12e17cadc2314d5145..e033b93301cd8577ee020404213929a20d6dcb8c 100644 (file)
 #include <botan/hash.h>
 #include <botan/types.h>
 
+#include <cryptolink/botan_common.h>
+
 #include <cstring>
 
-namespace {
+namespace isc {
+namespace cryptolink {
+
 /// @brief Decode the HashAlgorithm enum into a name usable by Botan
 ///
 /// @param algorithm algorithm to be converted
@@ -52,12 +56,6 @@ getBotanHashAlgorithmName(isc::cryptolink::HashAlgorithm algorithm) {
     return ("Unknown");
 }
 
-} // local namespace
-
-
-namespace isc {
-namespace cryptolink {
-
 /// @brief Botan implementation of Hash. Each method is the counterpart
 /// of the Hash corresponding method.
 class HashImpl {
index 5346bdec18f1a7d52d0fc055c17a0c375903b2ab..174985ccfe39d88d765ab0d3d1769a0aeb1222f7 100644 (file)
 #include <botan/hash.h>
 #include <botan/types.h>
 
-#include <cstring>
-
-namespace {
-
-/// @brief Decode the HashAlgorithm enum into a name usable by Botan
-///
-/// @param algorithm algorithm to be converted
-/// @return text representation of the algorithm name
-const char*
-getBotanHashAlgorithmName(isc::cryptolink::HashAlgorithm algorithm) {
-    switch (algorithm) {
-    case isc::cryptolink::MD5:
-        return ("MD5");
-    case isc::cryptolink::SHA1:
-        return ("SHA-1");
-    case isc::cryptolink::SHA256:
-        return ("SHA-256");
-    case isc::cryptolink::SHA224:
-        return ("SHA-224");
-    case isc::cryptolink::SHA384:
-        return ("SHA-384");
-    case isc::cryptolink::SHA512:
-        return ("SHA-512");
-    case isc::cryptolink::UNKNOWN_HASH:
-        return ("Unknown");
-    }
-    // compiler should have prevented us to reach this, since we have
-    // no default. But we need a return value anyway
-    return ("Unknown");
-}
-
-} // local namespace
+#include <cryptolink/botan_common.h>
 
+#include <cstring>
 
 namespace isc {
 namespace cryptolink {
diff --git a/src/lib/cryptolink/openssl_common.h b/src/lib/cryptolink/openssl_common.h
new file mode 100644 (file)
index 0000000..fb6ed4b
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (C) 2014  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.
+
+namespace isc {
+namespace cryptolink {
+
+/// @brief Decode the HashAlgorithm enum into an EVP_MD pointer (or 0)
+///
+/// EVP_MD pointer is a OpenSSL's way of identifying hash algorithms
+/// @param algorithm algorithm to be converted
+/// @return pointer to a static EVP_MD which identifies the algorithm
+const EVP_MD*
+getOpenSSLHashAlgorithm(isc::cryptolink::HashAlgorithm algorithm);
+
+} // namespace cryptolink
+} // namespace isc
index b0ebe73c669ca9fad53e209c8fb0120fe16183f1..dfc870c400a8a74f38d168c5214b76d3e9147902 100644 (file)
 
 #include <openssl/evp.h>
 
+#include <cryptolink/openssl_common.h>
+
 #include <cstring>
 
-namespace {
+namespace isc {
+namespace cryptolink {
 
 /// @brief Decode the HashAlgorithm enum into an EVP_MD pointer (or 0)
 ///
@@ -51,12 +54,6 @@ getOpenSSLHashAlgorithm(isc::cryptolink::HashAlgorithm algorithm) {
     return (0);
 }
 
-} // local namespace
-
-
-namespace isc {
-namespace cryptolink {
-
 /// \brief OpenSSL implementation of Hash. Each method is the counterpart
 /// of the Hash corresponding method.
 class HashImpl {
index 34940d349ecfcc6a21d1133757ad20c8c1f2da8f..81ba92386b04a5422c154ae7d056764ed9787074 100644 (file)
 
 #include <openssl/hmac.h>
 
+#include <cryptolink/openssl_common.h>
+
 #include <cstring>
 
 namespace {
 
-/// @brief Decode the HashAlgorithm enum into an EVP_MD pointer (or 0)
-///
-/// EVP_MD pointer is a OpenSSL's way of identifying hash algorithms
-/// @param algorithm algorithm to be converted
-/// @return pointer to EVP_MD which identifies the algorithm
-const EVP_MD*
-getOpenSSLHashAlgorithm(isc::cryptolink::HashAlgorithm algorithm) {
-    switch (algorithm) {
-    case isc::cryptolink::MD5:
-        return (EVP_md5());
-    case isc::cryptolink::SHA1:
-        return (EVP_sha1());
-    case isc::cryptolink::SHA256:
-        return (EVP_sha256());
-    case isc::cryptolink::SHA224:
-        return (EVP_sha224());
-    case isc::cryptolink::SHA384:
-        return (EVP_sha384());
-    case isc::cryptolink::SHA512:
-        return (EVP_sha512());
-    case isc::cryptolink::UNKNOWN_HASH:
-        return (0);
-    }
-    // compiler should have prevented us to reach this, since we have
-    // no default. But we need a return value anyway
-    return (0);
-}
-
 /// Secure Buffers which are wiped out when released.
 template<typename T>
 struct SecBuf {