BIND 10 trac781, updated. 6c274fd95d3c2bcc99113108f5a68aa0364f924c [trac781] move hash algorithm enum to cryptolink.h

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Apr 26 09:30:50 UTC 2011


The branch, trac781 has been updated
       via  6c274fd95d3c2bcc99113108f5a68aa0364f924c (commit)
      from  a1703e5ae5fc9458c066fb4aab7666bf4e5fdb8a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6c274fd95d3c2bcc99113108f5a68aa0364f924c
Author: Jelte Jansen <jelte at isc.org>
Date:   Tue Apr 26 11:20:45 2011 +0200

    [trac781] move hash algorithm enum to cryptolink.h
    
    also made the friend declaration more specific

-----------------------------------------------------------------------

Summary of changes:
 src/lib/cryptolink/crypto_hmac.cc            |   17 ++--
 src/lib/cryptolink/crypto_hmac.h             |   24 +----
 src/lib/cryptolink/cryptolink.cc             |   16 +---
 src/lib/cryptolink/cryptolink.h              |   21 +++-
 src/lib/cryptolink/tests/crypto_unittests.cc |  144 +++++++++++++-------------
 5 files changed, 106 insertions(+), 116 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/cryptolink/crypto_hmac.cc b/src/lib/cryptolink/crypto_hmac.cc
index 9e20c1a..595dd9a 100644
--- a/src/lib/cryptolink/crypto_hmac.cc
+++ b/src/lib/cryptolink/crypto_hmac.cc
@@ -13,6 +13,7 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <cryptolink.h>
+#include <cryptolink/crypto_hmac.h>
 
 #include <boost/scoped_ptr.hpp>
 
@@ -23,18 +24,18 @@
 
 namespace {
 const char*
-getBotanHashAlgorithmName(isc::cryptolink::HMAC::HashAlgorithm algorithm) {
+getBotanHashAlgorithmName(isc::cryptolink::HashAlgorithm algorithm) {
     switch (algorithm) {
-    case isc::cryptolink::HMAC::MD5:
+    case isc::cryptolink::MD5:
         return ("MD5");
         break;
-    case isc::cryptolink::HMAC::SHA1:
+    case isc::cryptolink::SHA1:
         return ("SHA-1");
         break;
-    case isc::cryptolink::HMAC::SHA256:
+    case isc::cryptolink::SHA256:
         return ("SHA-256");
         break;
-    case isc::cryptolink::HMAC::UNKNOWN:
+    case isc::cryptolink::UNKNOWN_HASH:
         return ("Unknown");
         break;
     }
@@ -52,7 +53,7 @@ namespace cryptolink {
 class HMACImpl {
 public:
     explicit HMACImpl(const void* secret, size_t secret_len,
-                      const HMAC::HashAlgorithm hash_algorithm) {
+                      const HashAlgorithm hash_algorithm) {
         Botan::HashFunction* hash;
         try {
             hash = Botan::get_hash(
@@ -202,7 +203,7 @@ HMAC::verify(const void* sig, const size_t len) {
 
 void
 signHMAC(const void* data, size_t data_len, const void* secret,
-         size_t secret_len, const HMAC::HashAlgorithm hash_algorithm,
+         size_t secret_len, const HashAlgorithm hash_algorithm,
          isc::dns::OutputBuffer& result, size_t len)
 {
     boost::scoped_ptr<HMAC> hmac(
@@ -216,7 +217,7 @@ signHMAC(const void* data, size_t data_len, const void* secret,
 
 bool
 verifyHMAC(const void* data, const size_t data_len, const void* secret,
-           size_t secret_len, const HMAC::HashAlgorithm hash_algorithm,
+           size_t secret_len, const HashAlgorithm hash_algorithm,
            const void* sig, const size_t sig_len)
 {
     boost::scoped_ptr<HMAC> hmac(
diff --git a/src/lib/cryptolink/crypto_hmac.h b/src/lib/cryptolink/crypto_hmac.h
index c042def..ddaa4a9 100644
--- a/src/lib/cryptolink/crypto_hmac.h
+++ b/src/lib/cryptolink/crypto_hmac.h
@@ -33,24 +33,7 @@ class HMACImpl;
 /// can be created with CryptoLink::createHMAC()
 ///
 class HMAC : private boost::noncopyable {
-public:
-    enum HashAlgorithm {
-        MD5 = 0,            ///< MD5
-        SHA1 = 1,           ///< SHA-1
-        SHA256 = 2,         ///< SHA-256
-        UNKNOWN = 3         ///< This value can be used in conversion
-                            ///  functions, to be returned when the
-                            ///  input is unknown (but a value MUST be
-                            ///  returned), for instance when the input
-                            ///  is a Name or a string, and the return
-                            ///  value is a HashAlgorithm.
-    };
-
 private:
-    /// Since HMAC objects cannot be created directly, the factory
-    /// class CryptoLink is a friend
-    friend class CryptoLink;
-
     /// \brief Constructor from a secret and a hash algorithm
     ///
     /// \exception UnsupportedAlgorithmException if the given algorithm
@@ -70,6 +53,9 @@ private:
     HMAC(const void* secret, size_t secret_len,
          const HashAlgorithm hash_algorithm);
 
+    friend HMAC* CryptoLink::createHMAC(const void*, size_t,
+                                        const HashAlgorithm);
+
 public:
     /// \brief Destructor
     ~HMAC();
@@ -175,7 +161,7 @@ void signHMAC(const void* data,
               const size_t data_len,
               const void* secret,
               size_t secret_len,
-              const HMAC::HashAlgorithm hash_algorithm,
+              const HashAlgorithm hash_algorithm,
               isc::dns::OutputBuffer& result,
               size_t len = 0);
 
@@ -209,7 +195,7 @@ bool verifyHMAC(const void* data,
                 const size_t data_len,
                 const void* secret,
                 size_t secret_len,
-                const HMAC::HashAlgorithm hash_algorithm,
+                const HashAlgorithm hash_algorithm,
                 const void* sig,
                 const size_t sig_len);
 
diff --git a/src/lib/cryptolink/cryptolink.cc b/src/lib/cryptolink/cryptolink.cc
index 2f2aeef..eb5d756 100644
--- a/src/lib/cryptolink/cryptolink.cc
+++ b/src/lib/cryptolink/cryptolink.cc
@@ -12,7 +12,8 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include "cryptolink.h"
+#include <cryptolink/cryptolink.h>
+#include <cryptolink/crypto_hmac.h>
 
 #include <botan/botan.h>
 
@@ -64,22 +65,11 @@ CryptoLink::initialize() {
 
 HMAC*
 CryptoLink::createHMAC(const void* secret, size_t secret_len,
-                       const HMAC::HashAlgorithm hash_algorithm)
+                       const HashAlgorithm hash_algorithm)
 {
     return (new HMAC(secret, secret_len, hash_algorithm));
 }
 
-auto_ptr<HMAC>
-CryptoLink::createHMAC2(const void* secret, size_t secret_len,
-                        const HMAC::HashAlgorithm hash_algorithm)
-{
-    std::auto_ptr<HMAC> asdf(new HMAC(secret, secret_len, hash_algorithm));
-    return asdf;
-    //return asdf;
-    //HMAC* h = createHMAC(secret, secret_len, hash_algorithm);
-    //return (boost::scoped_ptr<HMAC>(h));
-}
-
 } // namespace cryptolink
 } // namespace isc
 
diff --git a/src/lib/cryptolink/cryptolink.h b/src/lib/cryptolink/cryptolink.h
index 77b55e9..44db8ac 100644
--- a/src/lib/cryptolink/cryptolink.h
+++ b/src/lib/cryptolink/cryptolink.h
@@ -22,13 +22,26 @@
 #include <boost/noncopyable.hpp>
 #include <boost/scoped_ptr.hpp>
 
-#include <cryptolink/crypto_hmac.h>
-
 #include <memory>
 
 namespace isc {
 namespace cryptolink {
 
+enum HashAlgorithm {
+    MD5 = 0,            ///< MD5
+    SHA1 = 1,           ///< SHA-1
+    SHA256 = 2,         ///< SHA-256
+    UNKNOWN_HASH = 3    ///< This value can be used in conversion
+                        ///  functions, to be returned when the
+                        ///  input is unknown (but a value MUST be
+                        ///  returned), for instance when the input
+                        ///  is a Name or a string, and the return
+                        ///  value is a HashAlgorithm.
+};
+
+// Forward declaration for createHMAC()
+class HMAC;
+
 /// General exception class that is the base for all crypto-related
 /// exceptions
 class CryptoLinkError : public Exception {
@@ -158,9 +171,7 @@ public:
     /// \param secret_len The length of the secret
     /// \param hash_algorithm The hash algorithm
     HMAC* createHMAC(const void* secret, size_t secret_len,
-                     const HMAC::HashAlgorithm hash_algorithm);
-    std::auto_ptr<HMAC> createHMAC2(const void* secret, size_t secret_len,
-                     const HMAC::HashAlgorithm hash_algorithm);
+                     const HashAlgorithm hash_algorithm);
 
 private:
     // To enable us to use an optional explicit initialization call,
diff --git a/src/lib/cryptolink/tests/crypto_unittests.cc b/src/lib/cryptolink/tests/crypto_unittests.cc
index 4202bb9..cf40270 100644
--- a/src/lib/cryptolink/tests/crypto_unittests.cc
+++ b/src/lib/cryptolink/tests/crypto_unittests.cc
@@ -16,6 +16,8 @@
 #include <gtest/gtest.h>
 
 #include <cryptolink/cryptolink.h>
+#include <cryptolink/crypto_hmac.h>
+
 #include <dns/buffer.h>
 #include <exceptions/exceptions.h>
 
@@ -44,7 +46,7 @@ namespace {
     void doHMACTestConv(const std::string& data,
                         const void* secret,
                         size_t secret_len,
-                        const HMAC::HashAlgorithm hash_algorithm,
+                        const HashAlgorithm hash_algorithm,
                         const uint8_t* expected_hmac,
                         size_t hmac_len) {
         OutputBuffer data_buf(data.size());
@@ -77,7 +79,7 @@ namespace {
     void doHMACTestDirect(const std::string& data,
                           const void* secret,
                           size_t secret_len,
-                          const HMAC::HashAlgorithm hash_algorithm,
+                          const HashAlgorithm hash_algorithm,
                           const uint8_t* expected_hmac,
                           size_t hmac_len) {
         OutputBuffer data_buf(data.size());
@@ -113,7 +115,7 @@ namespace {
     void doHMACTestVector(const std::string& data,
                           const void* secret,
                           size_t secret_len,
-                          const HMAC::HashAlgorithm hash_algorithm,
+                          const HashAlgorithm hash_algorithm,
                           const uint8_t* expected_hmac,
                           size_t hmac_len) {
         CryptoLink& crypto = CryptoLink::getCryptoLink();
@@ -138,7 +140,7 @@ namespace {
     void doHMACTestArray(const std::string& data,
                          const void* secret,
                          size_t secret_len,
-                         const HMAC::HashAlgorithm hash_algorithm,
+                         const HashAlgorithm hash_algorithm,
                          const uint8_t* expected_hmac,
                          size_t hmac_len) {
         CryptoLink& crypto = CryptoLink::getCryptoLink();
@@ -170,7 +172,7 @@ namespace {
     void doHMACTest(const std::string& data,
                     const void* secret,
                     size_t secret_len,
-                    const HMAC::HashAlgorithm hash_algorithm,
+                    const HashAlgorithm hash_algorithm,
                     const uint8_t* expected_hmac,
                     size_t hmac_len) {
         doHMACTestConv(data, secret, secret_len, hash_algorithm,
@@ -195,13 +197,13 @@ TEST(CryptoLinkTest, HMAC_MD5_RFC2202_SIGN) {
                                       0x38, 0xbb, 0x1c, 0x13, 0xf4,
                                       0x8e, 0xf8, 0x15, 0x8b, 0xfc,
                                       0x9d };
-    doHMACTest("Hi There", secret, 16, HMAC::MD5, hmac_expected, 16);
+    doHMACTest("Hi There", secret, 16, MD5, hmac_expected, 16);
 
     const uint8_t hmac_expected2[] = { 0x75, 0x0c, 0x78, 0x3e, 0x6a,
                                        0xb0, 0xb5, 0x03, 0xea, 0xa8,
                                        0x6e, 0x31, 0x0a, 0x5d, 0xb7,
                                        0x38 };
-    doHMACTest("what do ya want for nothing?", "Jefe", 4, HMAC::MD5,
+    doHMACTest("what do ya want for nothing?", "Jefe", 4, MD5,
                hmac_expected2, 16);
 
     const uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
@@ -211,7 +213,7 @@ TEST(CryptoLinkTest, HMAC_MD5_RFC2202_SIGN) {
                                        0x14, 0x4c, 0x88, 0xdb, 0xb8,
                                        0xc7, 0x33, 0xf0, 0xe8, 0xb3,
                                        0xf6};
-    doHMACTest(std::string(50, 0xdd), secret3, 16, HMAC::MD5, hmac_expected3, 16);
+    doHMACTest(std::string(50, 0xdd), secret3, 16, MD5, hmac_expected3, 16);
 
     const std::string data4(50, 0xcd);
     const uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
@@ -223,7 +225,7 @@ TEST(CryptoLinkTest, HMAC_MD5_RFC2202_SIGN) {
                                        0x3a, 0x3a, 0xea, 0x3a, 0x75,
                                        0x16, 0x47, 0x46, 0xff, 0xaa,
                                        0x79 };
-    doHMACTest(data4, secret4, 25, HMAC::MD5, hmac_expected4, 16);
+    doHMACTest(data4, secret4, 25, MD5, hmac_expected4, 16);
 
     const uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
                                 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
@@ -232,9 +234,9 @@ TEST(CryptoLinkTest, HMAC_MD5_RFC2202_SIGN) {
                                        0x2e, 0xdc, 0x00, 0xf9, 0xba,
                                        0xb9, 0x95, 0x69, 0x0e, 0xfd,
                                        0x4c };
-    doHMACTest("Test With Truncation", secret5, 16, HMAC::MD5,
+    doHMACTest("Test With Truncation", secret5, 16, MD5,
                hmac_expected5, 16);
-    doHMACTest("Test With Truncation", secret5, 16, HMAC::MD5,
+    doHMACTest("Test With Truncation", secret5, 16, MD5,
                hmac_expected5, 12);
 
     const uint8_t hmac_expected6[] = { 0x6b, 0x1a, 0xb7, 0xfe, 0x4b,
@@ -242,7 +244,7 @@ TEST(CryptoLinkTest, HMAC_MD5_RFC2202_SIGN) {
                                        0xe6, 0xce, 0x61, 0xb9, 0xd0,
                                        0xcd };
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
-               std::string(80, 0xaa).c_str(), 80, HMAC::MD5, hmac_expected6, 16);
+               std::string(80, 0xaa).c_str(), 80, MD5, hmac_expected6, 16);
 
     const uint8_t hmac_expected7[] = { 0x6f, 0x63, 0x0f, 0xad, 0x67,
                                        0xcd, 0xa0, 0xee, 0x1f, 0xb1,
@@ -250,7 +252,7 @@ TEST(CryptoLinkTest, HMAC_MD5_RFC2202_SIGN) {
                                        0x3e };
     doHMACTest("Test Using Larger Than Block-Size Key and Larger Than "
                "One Block-Size Data",
-               std::string(80, 0xaa).c_str(), 80, HMAC::MD5, hmac_expected7, 16);
+               std::string(80, 0xaa).c_str(), 80, MD5, hmac_expected7, 16);
 }
 
 //
@@ -264,13 +266,13 @@ TEST(CryptoLinkTest, HMAC_SHA1_RFC2202_SIGN) {
                                       0x05, 0x72, 0x64, 0xe2, 0x8b,
                                       0xc0, 0xb6, 0xfb, 0x37, 0x8c,
                                       0x8e, 0xf1, 0x46, 0xbe, 0x00 };
-    doHMACTest("Hi There", secret, 20, HMAC::SHA1, hmac_expected, 20);
+    doHMACTest("Hi There", secret, 20, SHA1, hmac_expected, 20);
 
     const uint8_t hmac_expected2[] = { 0xef, 0xfc, 0xdf, 0x6a, 0xe5,
                                        0xeb, 0x2f, 0xa2, 0xd2, 0x74,
                                        0x16, 0xd5, 0xf1, 0x84, 0xdf,
                                        0x9c, 0x25, 0x9a, 0x7c, 0x79 };
-    doHMACTest("what do ya want for nothing?", "Jefe", 4, HMAC::SHA1,
+    doHMACTest("what do ya want for nothing?", "Jefe", 4, SHA1,
                hmac_expected2, 20);
 
     const uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
@@ -281,7 +283,7 @@ TEST(CryptoLinkTest, HMAC_SHA1_RFC2202_SIGN) {
                                        0xac, 0x11, 0xcd, 0x91, 0xa3,
                                        0x9a, 0xf4, 0x8a, 0xa1, 0x7b,
                                        0x4f, 0x63, 0xf1, 0x75, 0xd3 };
-    doHMACTest(std::string(50, 0xdd), secret3, 20, HMAC::SHA1, hmac_expected3, 20);
+    doHMACTest(std::string(50, 0xdd), secret3, 20, SHA1, hmac_expected3, 20);
 
     const uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
                                 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
@@ -292,7 +294,7 @@ TEST(CryptoLinkTest, HMAC_SHA1_RFC2202_SIGN) {
                                        0x62, 0x50, 0xc6, 0xbc, 0x84,
                                        0x14, 0xf9, 0xbf, 0x50, 0xc8,
                                        0x6c, 0x2d, 0x72, 0x35, 0xda };
-    doHMACTest(std::string(50, 0xcd), secret4, 25, HMAC::SHA1, hmac_expected4, 20);
+    doHMACTest(std::string(50, 0xcd), secret4, 25, SHA1, hmac_expected4, 20);
 
     const uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
                                 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
@@ -302,9 +304,9 @@ TEST(CryptoLinkTest, HMAC_SHA1_RFC2202_SIGN) {
                                        0x55, 0xe0, 0x7f, 0xe7, 0xf2,
                                        0x7b, 0xe1, 0xd5, 0x8b, 0xb9,
                                        0x32, 0x4a, 0x9a, 0x5a, 0x04 };
-    doHMACTest("Test With Truncation", secret5, 20, HMAC::SHA1,
+    doHMACTest("Test With Truncation", secret5, 20, SHA1,
                hmac_expected5, 20);
-    doHMACTest("Test With Truncation", secret5, 20, HMAC::SHA1,
+    doHMACTest("Test With Truncation", secret5, 20, SHA1,
                hmac_expected5, 12);
 
     const uint8_t hmac_expected6[] = { 0xaa, 0x4a, 0xe5, 0xe1, 0x52,
@@ -312,7 +314,7 @@ TEST(CryptoLinkTest, HMAC_SHA1_RFC2202_SIGN) {
                                        0x56, 0x37, 0xce, 0x8a, 0x3b,
                                        0x55, 0xed, 0x40, 0x21, 0x12 };
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
-               std::string(80, 0xaa).c_str(), 80, HMAC::SHA1, hmac_expected6, 20);
+               std::string(80, 0xaa).c_str(), 80, SHA1, hmac_expected6, 20);
 
     const uint8_t hmac_expected7[] = { 0xe8, 0xe9, 0x9d, 0x0f, 0x45,
                                        0x23, 0x7d, 0x78, 0x6d, 0x6b,
@@ -320,7 +322,7 @@ TEST(CryptoLinkTest, HMAC_SHA1_RFC2202_SIGN) {
                                        0x08, 0xbb, 0xff, 0x1a, 0x91 };
     doHMACTest("Test Using Larger Than Block-Size Key and Larger Than "
                "One Block-Size Data",
-               std::string(80, 0xaa).c_str(), 80, HMAC::SHA1, hmac_expected7, 20);
+               std::string(80, 0xaa).c_str(), 80, SHA1, hmac_expected7, 20);
 }
 
 //
@@ -337,7 +339,7 @@ TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
                                       0xc9, 0x83, 0x3d, 0xa7, 0x26,
                                       0xe9, 0x37, 0x6c, 0x2e, 0x32,
                                       0xcf, 0xf7 };
-    doHMACTest("Hi There", secret, 20, HMAC::SHA256, hmac_expected, 32);
+    doHMACTest("Hi There", secret, 20, SHA256, hmac_expected, 32);
 
     const uint8_t hmac_expected2[] = { 0x5b, 0xdc, 0xc1, 0x46, 0xbf,
                                        0x60, 0x75, 0x4e, 0x6a, 0x04,
@@ -346,7 +348,7 @@ TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
                                        0x9d, 0x27, 0x39, 0x83, 0x9d,
                                        0xec, 0x58, 0xb9, 0x64, 0xec,
                                        0x38, 0x43 };
-    doHMACTest("what do ya want for nothing?", "Jefe", 4, HMAC::SHA256,
+    doHMACTest("what do ya want for nothing?", "Jefe", 4, SHA256,
                hmac_expected2, 32);
 
     const uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
@@ -360,7 +362,7 @@ TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
                                        0x3e, 0xf8, 0xc1, 0x22, 0xd9,
                                        0x63, 0x55, 0x14, 0xce, 0xd5,
                                        0x65, 0xfe };
-    doHMACTest(std::string(50, 0xdd), secret3, 20, HMAC::SHA256, hmac_expected3, 32);
+    doHMACTest(std::string(50, 0xdd), secret3, 20, SHA256, hmac_expected3, 32);
 
     const uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
                                 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
@@ -374,7 +376,7 @@ TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
                                        0xe5, 0x78, 0xf8, 0x07, 0x7a,
                                        0x2e, 0x3f, 0xf4, 0x67, 0x29,
                                        0x66, 0x5b };
-    doHMACTest(std::string(50, 0xcd), secret4, 25, HMAC::SHA256, hmac_expected4, 32);
+    doHMACTest(std::string(50, 0xcd), secret4, 25, SHA256, hmac_expected4, 32);
 
     const uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
                                 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
@@ -384,7 +386,7 @@ TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
                                        0x10, 0x0e, 0xe0, 0x6e, 0x0c,
                                        0x79, 0x6c, 0x29, 0x55, 0x55,
                                        0x2b };
-    doHMACTest("Test With Truncation", secret5, 20, HMAC::SHA256,
+    doHMACTest("Test With Truncation", secret5, 20, SHA256,
                hmac_expected5, 16);
 
     const uint8_t hmac_expected6[] = { 0x60, 0xe4, 0x31, 0x59, 0x1e,
@@ -395,7 +397,7 @@ TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
                                        0x46, 0x04, 0x0f, 0x0e, 0xe3,
                                        0x7f, 0x54 };
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
-               std::string(131, 0xaa).c_str(), 131, HMAC::SHA256, hmac_expected6, 32);
+               std::string(131, 0xaa).c_str(), 131, SHA256, hmac_expected6, 32);
 
     const uint8_t hmac_expected7[] = { 0x9b, 0x09, 0xff, 0xa7, 0x1b,
                                        0x94, 0x2f, 0xcb, 0x27, 0x63,
@@ -407,12 +409,12 @@ TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
     doHMACTest("This is a test using a larger than block-size key and a"
                " larger than block-size data. The key needs to be hashe"
                "d before being used by the HMAC algorithm.",
-               std::string(131, 0xaa).c_str(), 131, HMAC::SHA256, hmac_expected7, 32);
+               std::string(131, 0xaa).c_str(), 131, SHA256, hmac_expected7, 32);
 }
 
 namespace {
     size_t
-    sigVectorLength(HMAC::HashAlgorithm alg, size_t len) {
+    sigVectorLength(HashAlgorithm alg, size_t len) {
         std::auto_ptr<HMAC> hmac_sign(
             CryptoLink::getCryptoLink().createHMAC("asdf", 4, alg));
         //boost::scoped_ptr<HMAC> hmac_sign(
@@ -423,7 +425,7 @@ namespace {
     }
 
     size_t
-    sigBufferLength(HMAC::HashAlgorithm alg, size_t len) {
+    sigBufferLength(HashAlgorithm alg, size_t len) {
         boost::scoped_ptr<HMAC> hmac_sign(
             CryptoLink::getCryptoLink().createHMAC("asdf", 4, alg));
         hmac_sign->update("asdf", 4);
@@ -436,41 +438,41 @@ namespace {
 TEST(CryptoLinkTest, HMACSigLengthArgument) {
     std::vector<uint8_t> sig;
 
-    EXPECT_EQ(16, sigVectorLength(HMAC::MD5, 0));
-    EXPECT_EQ(8, sigVectorLength(HMAC::MD5, 8));
-    EXPECT_EQ(16, sigVectorLength(HMAC::MD5, 16));
-    EXPECT_EQ(16, sigVectorLength(HMAC::MD5, 40));
-    EXPECT_EQ(16, sigVectorLength(HMAC::MD5, 2000));
-
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 0));
-    EXPECT_EQ(8, sigBufferLength(HMAC::SHA1, 8));
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 20));
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 40));
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 2000));
-
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 0));
-    EXPECT_EQ(8, sigBufferLength(HMAC::SHA256, 8));
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 32));
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 40));
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 3200));
-
-    EXPECT_EQ(16, sigBufferLength(HMAC::MD5, 0));
-    EXPECT_EQ(8, sigBufferLength(HMAC::MD5, 8));
-    EXPECT_EQ(16, sigBufferLength(HMAC::MD5, 16));
-    EXPECT_EQ(16, sigBufferLength(HMAC::MD5, 40));
-    EXPECT_EQ(16, sigBufferLength(HMAC::MD5, 2000));
-
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 0));
-    EXPECT_EQ(8, sigBufferLength(HMAC::SHA1, 8));
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 20));
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 40));
-    EXPECT_EQ(20, sigBufferLength(HMAC::SHA1, 2000));
-
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 0));
-    EXPECT_EQ(8, sigBufferLength(HMAC::SHA256, 8));
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 32));
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 40));
-    EXPECT_EQ(32, sigBufferLength(HMAC::SHA256, 3200));
+    EXPECT_EQ(16, sigVectorLength(MD5, 0));
+    EXPECT_EQ(8, sigVectorLength(MD5, 8));
+    EXPECT_EQ(16, sigVectorLength(MD5, 16));
+    EXPECT_EQ(16, sigVectorLength(MD5, 40));
+    EXPECT_EQ(16, sigVectorLength(MD5, 2000));
+
+    EXPECT_EQ(20, sigBufferLength(SHA1, 0));
+    EXPECT_EQ(8, sigBufferLength(SHA1, 8));
+    EXPECT_EQ(20, sigBufferLength(SHA1, 20));
+    EXPECT_EQ(20, sigBufferLength(SHA1, 40));
+    EXPECT_EQ(20, sigBufferLength(SHA1, 2000));
+
+    EXPECT_EQ(32, sigBufferLength(SHA256, 0));
+    EXPECT_EQ(8, sigBufferLength(SHA256, 8));
+    EXPECT_EQ(32, sigBufferLength(SHA256, 32));
+    EXPECT_EQ(32, sigBufferLength(SHA256, 40));
+    EXPECT_EQ(32, sigBufferLength(SHA256, 3200));
+
+    EXPECT_EQ(16, sigBufferLength(MD5, 0));
+    EXPECT_EQ(8, sigBufferLength(MD5, 8));
+    EXPECT_EQ(16, sigBufferLength(MD5, 16));
+    EXPECT_EQ(16, sigBufferLength(MD5, 40));
+    EXPECT_EQ(16, sigBufferLength(MD5, 2000));
+
+    EXPECT_EQ(20, sigBufferLength(SHA1, 0));
+    EXPECT_EQ(8, sigBufferLength(SHA1, 8));
+    EXPECT_EQ(20, sigBufferLength(SHA1, 20));
+    EXPECT_EQ(20, sigBufferLength(SHA1, 40));
+    EXPECT_EQ(20, sigBufferLength(SHA1, 2000));
+
+    EXPECT_EQ(32, sigBufferLength(SHA256, 0));
+    EXPECT_EQ(8, sigBufferLength(SHA256, 8));
+    EXPECT_EQ(32, sigBufferLength(SHA256, 32));
+    EXPECT_EQ(32, sigBufferLength(SHA256, 40));
+    EXPECT_EQ(32, sigBufferLength(SHA256, 3200));
 }
 
 TEST(CryptoLinkTest, BadKey) {
@@ -478,20 +480,20 @@ TEST(CryptoLinkTest, BadKey) {
     OutputBuffer hmac_sig(0);
     CryptoLink& crypto = CryptoLink::getCryptoLink();
 
-    EXPECT_THROW(crypto.createHMAC(NULL, 0, HMAC::MD5), BadKey);
-    EXPECT_THROW(crypto.createHMAC(NULL, 0, HMAC::UNKNOWN), UnsupportedAlgorithm);
+    EXPECT_THROW(crypto.createHMAC(NULL, 0, MD5), BadKey);
+    EXPECT_THROW(crypto.createHMAC(NULL, 0, UNKNOWN_HASH), UnsupportedAlgorithm);
 
     EXPECT_THROW(signHMAC(data_buf.getData(), data_buf.getLength(),
-                          NULL, 0, HMAC::MD5, hmac_sig), BadKey);
+                          NULL, 0, MD5, hmac_sig), BadKey);
     EXPECT_THROW(signHMAC(data_buf.getData(), data_buf.getLength(),
-                          NULL, 0, HMAC::UNKNOWN, hmac_sig),
+                          NULL, 0, UNKNOWN_HASH, hmac_sig),
                           UnsupportedAlgorithm);
 
     EXPECT_THROW(verifyHMAC(data_buf.getData(), data_buf.getLength(),
-                            NULL, 0, HMAC::MD5, hmac_sig.getData(),
+                            NULL, 0, MD5, hmac_sig.getData(),
                             hmac_sig.getLength()), BadKey);
     EXPECT_THROW(verifyHMAC(data_buf.getData(), data_buf.getLength(),
-                            NULL, 0, HMAC::UNKNOWN, hmac_sig.getData(),
+                            NULL, 0, UNKNOWN_HASH, hmac_sig.getData(),
                             hmac_sig.getLength()),
                             UnsupportedAlgorithm);
 }




More information about the bind10-changes mailing list