Browse Source

[trac781] constify

Jelte Jansen 14 years ago
parent
commit
006b2ea9da
2 changed files with 179 additions and 173 deletions
  1. 9 4
      src/lib/crypto/crypto.h
  2. 170 169
      src/lib/crypto/tests/crypto_unittests.cc

+ 9 - 4
src/lib/crypto/crypto.h

@@ -85,10 +85,15 @@ class HMACImpl;
 class HMAC : private boost::noncopyable {
 class HMAC : private boost::noncopyable {
 public:
 public:
     enum HashAlgorithm {
     enum HashAlgorithm {
-        MD5 = 0,
-        SHA1 = 1,
-        SHA256 = 2,
-        UNKNOWN = 3
+        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.
     };
     };
 
 
     /// \brief Constructor from a secret and a hash algorithm
     /// \brief Constructor from a secret and a hash algorithm

+ 170 - 169
src/lib/crypto/tests/crypto_unittests.cc

@@ -23,17 +23,19 @@ using namespace isc::dns;
 using namespace isc::crypto;
 using namespace isc::crypto;
 
 
 namespace {
 namespace {
-    void checkData(const uint8_t* data1, const uint8_t* data2, size_t len) {
+    void checkData(const uint8_t* data, const uint8_t* expected,
+                   size_t len) {
         for (size_t i = 0; i < len; ++i) {
         for (size_t i = 0; i < len; ++i) {
-            ASSERT_EQ(data1[i], data2[i]);
+            ASSERT_EQ(expected[i], data[i]);
         }
         }
     }
     }
 
 
-    void checkBuffer(const OutputBuffer& buf, const uint8_t* data,
+    void checkBuffer(const OutputBuffer& buf, const uint8_t* expected,
                      size_t len)
                      size_t len)
     {
     {
         ASSERT_EQ(len, buf.getLength());
         ASSERT_EQ(len, buf.getLength());
-        checkData(static_cast<const uint8_t*>(buf.getData()), data, len);
+        checkData(static_cast<const uint8_t*>(buf.getData()), expected,
+                  len);
     }
     }
 
 
     // Sign and verify with the convenience functions
     // Sign and verify with the convenience functions
@@ -130,7 +132,10 @@ namespace {
         HMAC hmac_sign(secret, secret_len, hash_algorithm);
         HMAC hmac_sign(secret, secret_len, hash_algorithm);
         hmac_sign.update(data.c_str(), data.size());
         hmac_sign.update(data.c_str(), data.size());
 
 
-        uint8_t sig[hmac_len];
+        // note: this is not exception-safe, and will leak, but
+        // if there is an unexpected exception in the code below we
+        // have more important things to fix.
+        uint8_t* sig = new uint8_t[hmac_len];
 
 
         hmac_sign.sign(sig, hmac_len);
         hmac_sign.sign(sig, hmac_len);
         checkData(sig, expected_hmac, hmac_len);
         checkData(sig, expected_hmac, hmac_len);
@@ -141,6 +146,8 @@ namespace {
 
 
         sig[0] = ~sig[0];
         sig[0] = ~sig[0];
         EXPECT_FALSE(hmac_verify.verify(sig, hmac_len));
         EXPECT_FALSE(hmac_verify.verify(sig, hmac_len));
+
+        delete[] sig;
     }
     }
 
 
     void doHMACTest(const std::string& data,
     void doHMACTest(const std::string& data,
@@ -164,70 +171,69 @@ namespace {
 // Test values taken from RFC 2202
 // Test values taken from RFC 2202
 //
 //
 TEST(CryptoTest, HMAC_MD5_RFC2202_SIGN) {
 TEST(CryptoTest, HMAC_MD5_RFC2202_SIGN) {
-    uint8_t secret[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
-                         0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
-                         0x0b, 0x0b };
-    uint8_t hmac_expected[] = { 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38,
-                                0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8,
-                                0x15, 0x8b, 0xfc, 0x9d };
+    const uint8_t secret[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+                               0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+                               0x0b, 0x0b };
+    const uint8_t hmac_expected[] = { 0x92, 0x94, 0x72, 0x7a, 0x36,
+                                      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, HMAC::MD5, hmac_expected, 16);
 
 
-    uint8_t hmac_expected2[] = { 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0,
-                                 0xb5, 0x03, 0xea, 0xa8, 0x6e, 0x31,
-                                 0x0a, 0x5d, 0xb7, 0x38 };
+    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, HMAC::MD5,
                hmac_expected2, 16);
                hmac_expected2, 16);
 
 
-    std::string data3;
-    for (int i = 0; i < 50; ++i) {
-        data3.push_back(0xdd);
-    }
-    uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
-                          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
-                          0xaa, 0xaa };
-    uint8_t hmac_expected3[] = { 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14,
-                                 0x4c, 0x88, 0xdb, 0xb8, 0xc7, 0x33,
-                                 0xf0, 0xe8, 0xb3, 0xf6};
+    const std::string data3(50, 0xdd);
+    const uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa, 0xaa, 0xaa };
+    const uint8_t hmac_expected3[] = { 0x56, 0xbe, 0x34, 0x52, 0x1d,
+                                       0x14, 0x4c, 0x88, 0xdb, 0xb8,
+                                       0xc7, 0x33, 0xf0, 0xe8, 0xb3,
+                                       0xf6};
     doHMACTest(data3, secret3, 16, HMAC::MD5, hmac_expected3, 16);
     doHMACTest(data3, secret3, 16, HMAC::MD5, hmac_expected3, 16);
 
 
-    std::string data4;
-    for (int i = 0; i < 50; ++i) {
-        data4.push_back(0xcd);
-    }
-    uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
-                          0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
-                          0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
-                          0x16, 0x17, 0x18, 0x19 };
-    uint8_t hmac_expected4[] = { 0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a,
-                                 0x3a, 0xea, 0x3a, 0x75, 0x16, 0x47,
-                                 0x46, 0xff, 0xaa, 0x79 };
+    const std::string data4(50, 0xcd);
+    const uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+                                0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
+                                0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
+                                0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+                                0x19 };
+    const uint8_t hmac_expected4[] = { 0x69, 0x7e, 0xaf, 0x0a, 0xca,
+                                       0x3a, 0x3a, 0xea, 0x3a, 0x75,
+                                       0x16, 0x47, 0x46, 0xff, 0xaa,
+                                       0x79 };
     doHMACTest(data4, secret4, 25, HMAC::MD5, hmac_expected4, 16);
     doHMACTest(data4, secret4, 25, HMAC::MD5, hmac_expected4, 16);
 
 
-    uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
-                          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
-                          0x0c, 0x0c };
-    uint8_t hmac_expected5[] = { 0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e,
-                                 0xdc, 0x00, 0xf9, 0xba, 0xb9, 0x95,
-                                 0x69, 0x0e, 0xfd, 0x4c };
+    const uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c, 0x0c, 0x0c };
+    const uint8_t hmac_expected5[] = { 0x56, 0x46, 0x1e, 0xf2, 0x34,
+                                       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, HMAC::MD5,
                hmac_expected5, 16);
                hmac_expected5, 16);
     doHMACTest("Test With Truncation", secret5, 16, HMAC::MD5,
     doHMACTest("Test With Truncation", secret5, 16, HMAC::MD5,
                hmac_expected5, 12);
                hmac_expected5, 12);
 
 
-    std::string secret6;
-    for (int i = 0; i < 80; ++i) {
-        secret6.push_back(0xaa);
-    }
-    uint8_t hmac_expected6[] = { 0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7,
-                                 0xbf, 0x8f, 0x0b, 0x62, 0xe6, 0xce,
-                                 0x61, 0xb9, 0xd0, 0xcd };
+    const std::string secret6(80, 0xaa);
+    const uint8_t hmac_expected6[] = { 0x6b, 0x1a, 0xb7, 0xfe, 0x4b,
+                                       0xd7, 0xbf, 0x8f, 0x0b, 0x62,
+                                       0xe6, 0xce, 0x61, 0xb9, 0xd0,
+                                       0xcd };
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
                secret6.c_str(), 80, HMAC::MD5, hmac_expected6, 16);
                secret6.c_str(), 80, HMAC::MD5, hmac_expected6, 16);
 
 
     // same secret as for test 6
     // same secret as for test 6
-    uint8_t hmac_expected7[] = { 0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd,
-                                 0xa0, 0xee, 0x1f, 0xb1, 0xf5, 0x62,
-                                 0xdb, 0x3a, 0xa5, 0x3e };
+    const uint8_t hmac_expected7[] = { 0x6f, 0x63, 0x0f, 0xad, 0x67,
+                                       0xcd, 0xa0, 0xee, 0x1f, 0xb1,
+                                       0xf5, 0x62, 0xdb, 0x3a, 0xa5,
+                                       0x3e };
     doHMACTest("Test Using Larger Than Block-Size Key and Larger Than "
     doHMACTest("Test Using Larger Than Block-Size Key and Larger Than "
                "One Block-Size Data",
                "One Block-Size Data",
                secret6.c_str(), 80, HMAC::MD5, hmac_expected7, 16);
                secret6.c_str(), 80, HMAC::MD5, hmac_expected7, 16);
@@ -237,77 +243,71 @@ TEST(CryptoTest, HMAC_MD5_RFC2202_SIGN) {
 // Test values taken from RFC 2202
 // Test values taken from RFC 2202
 //
 //
 TEST(CryptoTest, HMAC_SHA1_RFC2202_SIGN) {
 TEST(CryptoTest, HMAC_SHA1_RFC2202_SIGN) {
-    uint8_t secret[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
-                         0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
-                         0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
-    uint8_t hmac_expected[] = { 0xb6, 0x17, 0x31, 0x86, 0x55, 0x05,
-                                0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6,
-                                0xfb, 0x37, 0x8c, 0x8e, 0xf1, 0x46,
-                                0xbe, 0x00 };
+    const uint8_t secret[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+                               0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+                               0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
+    const uint8_t hmac_expected[] = { 0xb6, 0x17, 0x31, 0x86, 0x55,
+                                      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, HMAC::SHA1, hmac_expected, 20);
 
 
-    uint8_t hmac_expected2[] = { 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb,
-                                 0x2f, 0xa2, 0xd2, 0x74, 0x16, 0xd5,
-                                 0xf1, 0x84, 0xdf, 0x9c, 0x25, 0x9a,
-                                 0x7c, 0x79 };
+    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, HMAC::SHA1,
                hmac_expected2, 20);
                hmac_expected2, 20);
 
 
-    std::string data3;
-    for (int i = 0; i < 50; ++i) {
-        data3.push_back(0xdd);
-    }
-    uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
-                          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
-                          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa };
-    uint8_t hmac_expected3[] = { 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac,
-                                 0x11, 0xcd, 0x91, 0xa3, 0x9a, 0xf4,
-                                 0x8a, 0xa1, 0x7b, 0x4f, 0x63, 0xf1,
-                                 0x75, 0xd3 };
+    const std::string data3(50, 0xdd);
+    const uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa };
+    const uint8_t hmac_expected3[] = { 0x12, 0x5d, 0x73, 0x42, 0xb9,
+                                       0xac, 0x11, 0xcd, 0x91, 0xa3,
+                                       0x9a, 0xf4, 0x8a, 0xa1, 0x7b,
+                                       0x4f, 0x63, 0xf1, 0x75, 0xd3 };
     doHMACTest(data3, secret3, 20, HMAC::SHA1, hmac_expected3, 20);
     doHMACTest(data3, secret3, 20, HMAC::SHA1, hmac_expected3, 20);
 
 
-    std::string data4;
-    for (int i = 0; i < 50; ++i) {
-        data4.push_back(0xcd);
-    }
-    uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
-                          0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
-                          0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
-                          0x16, 0x17, 0x18, 0x19 };
-    uint8_t hmac_expected4[] = { 0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62,
-                                 0x50, 0xc6, 0xbc, 0x84, 0x14, 0xf9,
-                                 0xbf, 0x50, 0xc8, 0x6c, 0x2d, 0x72,
-                                 0x35, 0xda };
+    const std::string data4(50, 0xcd);
+    const uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+                                0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
+                                0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
+                                0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+                                0x19 };
+    const uint8_t hmac_expected4[] = { 0x4c, 0x90, 0x07, 0xf4, 0x02,
+                                       0x62, 0x50, 0xc6, 0xbc, 0x84,
+                                       0x14, 0xf9, 0xbf, 0x50, 0xc8,
+                                       0x6c, 0x2d, 0x72, 0x35, 0xda };
     doHMACTest(data4, secret4, 25, HMAC::SHA1, hmac_expected4, 20);
     doHMACTest(data4, secret4, 25, HMAC::SHA1, hmac_expected4, 20);
 
 
-    uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
-                          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
-                          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c };
-    uint8_t hmac_expected5[] = { 0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55,
-                                 0xe0, 0x7f, 0xe7, 0xf2, 0x7b, 0xe1,
-                                 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a,
-                                 0x5a, 0x04 };
+    const uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c };
+    const uint8_t hmac_expected5[] = { 0x4c, 0x1a, 0x03, 0x42, 0x4b,
+                                       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, HMAC::SHA1,
                hmac_expected5, 20);
                hmac_expected5, 20);
     doHMACTest("Test With Truncation", secret5, 20, HMAC::SHA1,
     doHMACTest("Test With Truncation", secret5, 20, HMAC::SHA1,
                hmac_expected5, 12);
                hmac_expected5, 12);
 
 
-    std::string secret6;
-    for (int i = 0; i < 80; ++i) {
-        secret6.push_back(0xaa);
-    }
-    uint8_t hmac_expected6[] = { 0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72,
-                                 0xd0, 0x0e, 0x95, 0x70, 0x56, 0x37,
-                                 0xce, 0x8a, 0x3b, 0x55, 0xed, 0x40,
-                                 0x21, 0x12 };
+    const std::string secret6(80, 0xaa);
+    const uint8_t hmac_expected6[] = { 0xaa, 0x4a, 0xe5, 0xe1, 0x52,
+                                       0x72, 0xd0, 0x0e, 0x95, 0x70,
+                                       0x56, 0x37, 0xce, 0x8a, 0x3b,
+                                       0x55, 0xed, 0x40, 0x21, 0x12 };
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
                secret6.c_str(), 80, HMAC::SHA1, hmac_expected6, 20);
                secret6.c_str(), 80, HMAC::SHA1, hmac_expected6, 20);
 
 
     // same secret as for test 6
     // same secret as for test 6
-    uint8_t hmac_expected7[] = { 0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23,
-                                 0x7d, 0x78, 0x6d, 0x6b, 0xba, 0xa7,
-                                 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff,
-                                 0x1a, 0x91 };
+    const uint8_t hmac_expected7[] = { 0xe8, 0xe9, 0x9d, 0x0f, 0x45,
+                                       0x23, 0x7d, 0x78, 0x6d, 0x6b,
+                                       0xba, 0xa7, 0x96, 0x5c, 0x78,
+                                       0x08, 0xbb, 0xff, 0x1a, 0x91 };
     doHMACTest("Test Using Larger Than Block-Size Key and Larger Than "
     doHMACTest("Test Using Larger Than Block-Size Key and Larger Than "
                "One Block-Size Data",
                "One Block-Size Data",
                secret6.c_str(), 80, HMAC::SHA1, hmac_expected7, 20);
                secret6.c_str(), 80, HMAC::SHA1, hmac_expected7, 20);
@@ -317,86 +317,87 @@ TEST(CryptoTest, HMAC_SHA1_RFC2202_SIGN) {
 // Test values taken from RFC 4231
 // Test values taken from RFC 4231
 //
 //
 TEST(CryptoTest, HMAC_SHA256_RFC2202_SIGN) {
 TEST(CryptoTest, HMAC_SHA256_RFC2202_SIGN) {
-    uint8_t secret[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
-                         0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
-                         0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
-    uint8_t hmac_expected[] = { 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb,
-                                0x38, 0x53, 0x5c, 0xa8, 0xaf, 0xce,
-                                0xaf, 0x0b, 0xf1, 0x2b, 0x88, 0x1d,
-                                0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
-                                0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32,
-                                0xcf, 0xf7 };
+    const uint8_t secret[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+                               0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+                               0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
+    const uint8_t hmac_expected[] = { 0xb0, 0x34, 0x4c, 0x61, 0xd8,
+                                      0xdb, 0x38, 0x53, 0x5c, 0xa8,
+                                      0xaf, 0xce, 0xaf, 0x0b, 0xf1,
+                                      0x2b, 0x88, 0x1d, 0xc2, 0x00,
+                                      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, HMAC::SHA256, hmac_expected, 32);
 
 
-    uint8_t hmac_expected2[] = { 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60,
-                                 0x75, 0x4e, 0x6a, 0x04, 0x24, 0x26,
-                                 0x08, 0x95, 0x75, 0xc7, 0x5a, 0x00,
-                                 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
-                                 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec,
-                                 0x38, 0x43 };
+    const uint8_t hmac_expected2[] = { 0x5b, 0xdc, 0xc1, 0x46, 0xbf,
+                                       0x60, 0x75, 0x4e, 0x6a, 0x04,
+                                       0x24, 0x26, 0x08, 0x95, 0x75,
+                                       0xc7, 0x5a, 0x00, 0x3f, 0x08,
+                                       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, HMAC::SHA256,
                hmac_expected2, 32);
                hmac_expected2, 32);
 
 
-    std::string data3;
-    for (int i = 0; i < 50; ++i) {
-        data3.push_back(0xdd);
-    }
-    uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
-                          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
-                          0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa };
-    uint8_t hmac_expected3[] = { 0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80,
-                                 0x0e, 0x46, 0x85, 0x4d, 0xb8, 0xeb,
-                                 0xd0, 0x91, 0x81, 0xa7, 0x29, 0x59,
-                                 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22,
-                                 0xd9, 0x63, 0x55, 0x14, 0xce, 0xd5,
-                                 0x65, 0xfe };
+    const std::string data3(50, 0xdd);
+    const uint8_t secret3[] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
+                                0xaa, 0xaa };
+    const uint8_t hmac_expected3[] = { 0x77, 0x3e, 0xa9, 0x1e, 0x36,
+                                       0x80, 0x0e, 0x46, 0x85, 0x4d,
+                                       0xb8, 0xeb, 0xd0, 0x91, 0x81,
+                                       0xa7, 0x29, 0x59, 0x09, 0x8b,
+                                       0x3e, 0xf8, 0xc1, 0x22, 0xd9,
+                                       0x63, 0x55, 0x14, 0xce, 0xd5,
+                                       0x65, 0xfe };
     doHMACTest(data3, secret3, 20, HMAC::SHA256, hmac_expected3, 32);
     doHMACTest(data3, secret3, 20, HMAC::SHA256, hmac_expected3, 32);
 
 
-    std::string data4;
-    for (int i = 0; i < 50; ++i) {
-        data4.push_back(0xcd);
-    }
-    uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
-                          0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
-                          0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
-                          0x16, 0x17, 0x18, 0x19 };
-    uint8_t hmac_expected4[] = { 0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44,
-                                 0x3c, 0x0e, 0xa4, 0xcc, 0x81, 0x98,
-                                 0x99, 0xf2, 0x08, 0x3a, 0x85, 0xf0,
-                                 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07,
-                                 0x7a, 0x2e, 0x3f, 0xf4, 0x67, 0x29,
-                                 0x66, 0x5b };
+    const std::string data4(50, 0xcd);
+    const uint8_t secret4[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+                                0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
+                                0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
+                                0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+                                0x19 };
+    const uint8_t hmac_expected4[] = { 0x82, 0x55, 0x8a, 0x38, 0x9a,
+                                       0x44, 0x3c, 0x0e, 0xa4, 0xcc,
+                                       0x81, 0x98, 0x99, 0xf2, 0x08,
+                                       0x3a, 0x85, 0xf0, 0xfa, 0xa3,
+                                       0xe5, 0x78, 0xf8, 0x07, 0x7a,
+                                       0x2e, 0x3f, 0xf4, 0x67, 0x29,
+                                       0x66, 0x5b };
     doHMACTest(data4, secret4, 25, HMAC::SHA256, hmac_expected4, 32);
     doHMACTest(data4, secret4, 25, HMAC::SHA256, hmac_expected4, 32);
 
 
-    uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
-                          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
-                          0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c };
-    uint8_t hmac_expected5[] = { 0xa3, 0xb6, 0x16, 0x74, 0x73, 0x10,
-                                 0x0e, 0xe0, 0x6e, 0x0c, 0x79, 0x6c,
-                                 0x29, 0x55, 0x55, 0x2b };
+    const uint8_t secret5[] = { 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
+                                0x0c, 0x0c };
+    const uint8_t hmac_expected5[] = { 0xa3, 0xb6, 0x16, 0x74, 0x73,
+                                       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, HMAC::SHA256,
                hmac_expected5, 16);
                hmac_expected5, 16);
 
 
-    std::string secret6;
-    for (int i = 0; i < 131; ++i) {
-        secret6.push_back(0xaa);
-    }
-    uint8_t hmac_expected6[] = { 0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0,
-                                 0xb6, 0x7f, 0x0d, 0x8a, 0x26, 0xaa,
-                                 0xcb, 0xf5, 0xb7, 0x7f, 0x8e, 0x0b,
-                                 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14,
-                                 0x05, 0x46, 0x04, 0x0f, 0x0e, 0xe3,
-                                 0x7f, 0x54 };
+    const std::string secret6(131, 0xaa);
+    const uint8_t hmac_expected6[] = { 0x60, 0xe4, 0x31, 0x59, 0x1e,
+                                       0xe0, 0xb6, 0x7f, 0x0d, 0x8a,
+                                       0x26, 0xaa, 0xcb, 0xf5, 0xb7,
+                                       0x7f, 0x8e, 0x0b, 0xc6, 0x21,
+                                       0x37, 0x28, 0xc5, 0x14, 0x05,
+                                       0x46, 0x04, 0x0f, 0x0e, 0xe3,
+                                       0x7f, 0x54 };
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
     doHMACTest("Test Using Larger Than Block-Size Key - Hash Key First",
                secret6.c_str(), 131, HMAC::SHA256, hmac_expected6, 32);
                secret6.c_str(), 131, HMAC::SHA256, hmac_expected6, 32);
 
 
     // Same secret as test 6
     // Same secret as test 6
-    uint8_t hmac_expected7[] = { 0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94,
-                                 0x2f, 0xcb, 0x27, 0x63, 0x5f, 0xbc,
-                                 0xd5, 0xb0, 0xe9, 0x44, 0xbf, 0xdc,
-                                 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93,
-                                 0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a,
-                                 0x35, 0xe2 };
+    const uint8_t hmac_expected7[] = { 0x9b, 0x09, 0xff, 0xa7, 0x1b,
+                                       0x94, 0x2f, 0xcb, 0x27, 0x63,
+                                       0x5f, 0xbc, 0xd5, 0xb0, 0xe9,
+                                       0x44, 0xbf, 0xdc, 0x63, 0x64,
+                                       0x4f, 0x07, 0x13, 0x93, 0x8a,
+                                       0x7f, 0x51, 0x53, 0x5c, 0x3a,
+                                       0x35, 0xe2 };
     doHMACTest("This is a test using a larger than block-size key and a"
     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"
                " larger than block-size data. The key needs to be hashe"
                "d before being used by the HMAC algorithm.",
                "d before being used by the HMAC algorithm.",
@@ -408,7 +409,7 @@ namespace {
     sigVectorLength(HMAC::HashAlgorithm alg, size_t len) {
     sigVectorLength(HMAC::HashAlgorithm alg, size_t len) {
         HMAC hmac_sign("asdf", 4, alg);
         HMAC hmac_sign("asdf", 4, alg);
         hmac_sign.update("asdf", 4);
         hmac_sign.update("asdf", 4);
-        std::vector<uint8_t> sig = hmac_sign.sign(len);
+        const std::vector<uint8_t> sig = hmac_sign.sign(len);
         return sig.size();
         return sig.size();
     }
     }
     size_t
     size_t