|
@@ -13,8 +13,16 @@
|
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
#include <config.h>
|
|
|
+
|
|
|
+#include <string>
|
|
|
+#include <vector>
|
|
|
+
|
|
|
+#include <boost/lexical_cast.hpp>
|
|
|
+
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
+#include <util/encode/hex.h>
|
|
|
+
|
|
|
#include <cryptolink/cryptolink.h>
|
|
|
#include <cryptolink/crypto_hmac.h>
|
|
|
|
|
@@ -23,7 +31,9 @@
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
+using namespace boost;
|
|
|
using namespace isc::util;
|
|
|
+using namespace isc::util::encode;
|
|
|
using namespace isc::cryptolink;
|
|
|
|
|
|
namespace {
|
|
@@ -340,77 +350,158 @@ TEST(CryptoLinkTest, DISABLED_HMAC_SHA1_RFC2202_SIGN_TRUNCATED) {
|
|
|
//
|
|
|
// Test values taken from RFC 4231
|
|
|
//
|
|
|
-TEST(CryptoLinkTest, HMAC_SHA256_RFC2202_SIGN) {
|
|
|
- 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, SHA256, hmac_expected, 32);
|
|
|
-
|
|
|
- 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, SHA256,
|
|
|
- hmac_expected2, 32);
|
|
|
+// Test data from RFC4231, including secret key
|
|
|
+// and source data, they are common for sha224/256/384/512
|
|
|
+// so put them together within the separate function.
|
|
|
+void
|
|
|
+doRFC4231Tests(HashAlgorithm hash_algorithm,
|
|
|
+ const std::vector<std::vector<uint8_t> >& hmac_list)
|
|
|
+{
|
|
|
+ std::vector<std::string> data_list;
|
|
|
+ std::vector<std::string> secret_list;
|
|
|
+
|
|
|
+ data_list.push_back("Hi There");
|
|
|
+ data_list.push_back("what do ya want for nothing?");
|
|
|
+ data_list.push_back(std::string(50, 0xdd));
|
|
|
+ data_list.push_back(std::string(50, 0xcd));
|
|
|
+ data_list.push_back("Test With Truncation");
|
|
|
+ data_list.push_back("Test Using Larger Than Block-Size Key - "
|
|
|
+ "Hash Key First");
|
|
|
+ data_list.push_back("This is a test using a larger than block-size "
|
|
|
+ "key and a larger than block-size data. The key "
|
|
|
+ "needs to be hashed before being used by the HMAC "
|
|
|
+ "algorithm.");
|
|
|
+
|
|
|
+ secret_list.push_back(std::string(20, 0x0b));
|
|
|
+ secret_list.push_back("Jefe");
|
|
|
+ secret_list.push_back(std::string(20, 0xaa));
|
|
|
+ const uint8_t secret_array[] = {
|
|
|
+ 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
|
|
|
+ };
|
|
|
+ secret_list.push_back(std::string(secret_array,
|
|
|
+ secret_array + sizeof(secret_array)));
|
|
|
+ secret_list.push_back(std::string(20, 0x0c));
|
|
|
+ secret_list.push_back(std::string(131, 0xaa));
|
|
|
+ secret_list.push_back(std::string(131, 0xaa));
|
|
|
+
|
|
|
+ // Make sure we provide a consistent size of test data
|
|
|
+ ASSERT_EQ(secret_list.size(), data_list.size());
|
|
|
+ ASSERT_EQ(secret_list.size(), hmac_list.size());
|
|
|
+
|
|
|
+ for (int i = 0; i < data_list.size(); ++i) {
|
|
|
+ SCOPED_TRACE("RFC4231 HMAC test for algorithm ID: " +
|
|
|
+ lexical_cast<std::string>(hash_algorithm) +
|
|
|
+ ", data ID: " + lexical_cast<std::string>(i));
|
|
|
+ // Until #920 is resolved we have to skip truncation cases.
|
|
|
+ if (data_list[i] == "Test With Truncation") {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ doHMACTest(data_list[i], secret_list[i].c_str(), secret_list[i].size(),
|
|
|
+ hash_algorithm, &hmac_list[i][0], hmac_list[i].size());
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- 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(std::string(50, 0xdd), secret3, 20, SHA256, hmac_expected3, 32);
|
|
|
+TEST(CryptoLinkTest, HMAC_SHA256_RFC4231_SIGN) {
|
|
|
+ std::vector<std::vector<uint8_t> > hmac_expected_list(7);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ decodeHex(
|
|
|
+ "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex(
|
|
|
+ "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex(
|
|
|
+ "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex(
|
|
|
+ "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex("a3b6167473100ee06e0c796c2955552b", hmac_expected_list[i++]);
|
|
|
+ decodeHex(
|
|
|
+ "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex(
|
|
|
+ "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+
|
|
|
+ doRFC4231Tests(SHA256, hmac_expected_list);
|
|
|
+}
|
|
|
|
|
|
- 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(std::string(50, 0xcd), secret4, 25, SHA256, hmac_expected4, 32);
|
|
|
-
|
|
|
- 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",
|
|
|
- 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,
|
|
|
- 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"
|
|
|
- " 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, SHA256, hmac_expected7, 32);
|
|
|
+//
|
|
|
+// Test values taken from RFC 4231, test optional algorithm 224,384,512
|
|
|
+//
|
|
|
+TEST(CryptoLinkTest, HMAC_SHA224_RFC4231_SIGN) {
|
|
|
+ std::vector<std::vector<uint8_t> > hmac_expected_list(7);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ decodeHex("896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex("a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex("7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex("6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex("0e2aea68a90c8d37c988bcdb9fca6fa8", hmac_expected_list[i++]);
|
|
|
+ decodeHex("95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+ decodeHex("3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1",
|
|
|
+ hmac_expected_list[i++]);
|
|
|
+
|
|
|
+ doRFC4231Tests(SHA224, hmac_expected_list);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(CryptoLinkTest, HMAC_SHA384_RFC4231_SIGN) {
|
|
|
+ std::vector<std::vector<uint8_t> > hmac_expected_list(7);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ decodeHex("afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc5"
|
|
|
+ "9cfaea9ea9076ede7f4af152e8b2fa9cb6", hmac_expected_list[i++]);
|
|
|
+ decodeHex("af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec373632244"
|
|
|
+ "5e8e2240ca5e69e2c78b3239ecfab21649", hmac_expected_list[i++]);
|
|
|
+ decodeHex("88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e5596614"
|
|
|
+ "4b2a5ab39dc13814b94e3ab6e101a34f27", hmac_expected_list[i++]);
|
|
|
+ decodeHex("3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b"
|
|
|
+ "4e6801dd23c4a7d679ccf8a386c674cffb", hmac_expected_list[i++]);
|
|
|
+ decodeHex("3abf34c3503b2a23a46efc619baef897", hmac_expected_list[i++]);
|
|
|
+ decodeHex("4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05033ac4"
|
|
|
+ "c60c2ef6ab4030fe8296248df163f44952", hmac_expected_list[i++]);
|
|
|
+ decodeHex("6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82461e99"
|
|
|
+ "c5a678cc31e799176d3860e6110c46523e", hmac_expected_list[i++]);
|
|
|
+
|
|
|
+ doRFC4231Tests(SHA384, hmac_expected_list);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(CryptoLinkTest, HMAC_SHA512_RFC4231_SIGN) {
|
|
|
+ std::vector<std::vector<uint8_t> > hmac_expected_list(7);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ decodeHex("87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17c"
|
|
|
+ "dedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a12"
|
|
|
+ "6854", hmac_expected_list[i++]);
|
|
|
+ decodeHex("164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505"
|
|
|
+ "549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bc"
|
|
|
+ "e737", hmac_expected_list[i++]);
|
|
|
+ decodeHex("fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d"
|
|
|
+ "39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e132"
|
|
|
+ "92fb", hmac_expected_list[i++]);
|
|
|
+ decodeHex("b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3"
|
|
|
+ "dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a2"
|
|
|
+ "98dd", hmac_expected_list[i++]);
|
|
|
+ decodeHex("415fad6271580a531d4179bc891d87a6", hmac_expected_list[i++]);
|
|
|
+ decodeHex("80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3"
|
|
|
+ "526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d78"
|
|
|
+ "6598", hmac_expected_list[i++]);
|
|
|
+ decodeHex("e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc9"
|
|
|
+ "44b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c"
|
|
|
+ "6a58", hmac_expected_list[i++]);
|
|
|
+
|
|
|
+ doRFC4231Tests(SHA512, hmac_expected_list);
|
|
|
}
|
|
|
|
|
|
TEST(CryptoLinkTest, DISABLED_HMAC_SHA256_RFC2202_SIGN_TRUNCATED) {
|