update crypto helper
Change-Id: I59718964ce305888a8fc3947cde68c937a3ba64a
diff --git a/tests/unit-tests/ca-memory.t.cpp b/tests/unit-tests/ca-memory.t.cpp
index b2de610..0dcbd03 100644
--- a/tests/unit-tests/ca-memory.t.cpp
+++ b/tests/unit-tests/ca-memory.t.cpp
@@ -52,7 +52,8 @@
// update operation
CaState request2(Name("/ndn/site1"), "123", RequestType::NEW, Status::CHALLENGE, cert1,
- "email", "test", time::system_clock::now(), 3, time::seconds(3600), std::move(json), makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"));
+ "email", "test", time::system_clock::now(), 3, time::seconds(3600),
+ std::move(json), makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"), 0);
storage.updateRequest(request2);
result = storage.getRequest("123");
BOOST_CHECK_EQUAL(request2.m_cert, result.m_cert);
diff --git a/tests/unit-tests/ca-sqlite.t.cpp b/tests/unit-tests/ca-sqlite.t.cpp
index 3f98bdb..9bdc30e 100644
--- a/tests/unit-tests/ca-sqlite.t.cpp
+++ b/tests/unit-tests/ca-sqlite.t.cpp
@@ -50,7 +50,8 @@
JsonSection json;
json.put("test", "4567");
CaState request2(Name("/ndn/site1"), "123", RequestType::NEW, Status::CHALLENGE, cert1,
- "email", "test", time::system_clock::now(), 3, time::seconds(3600), std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key));
+ "email", "test", time::system_clock::now(), 3, time::seconds(3600),
+ std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
storage.updateRequest(request2);
result = storage.getRequest("123");
BOOST_CHECK_EQUAL(request2.m_cert, result.m_cert);
diff --git a/tests/unit-tests/challenge-email.t.cpp b/tests/unit-tests/challenge-email.t.cpp
index 4bac092..b73d22e 100644
--- a/tests/unit-tests/challenge-email.t.cpp
+++ b/tests/unit-tests/challenge-email.t.cpp
@@ -117,7 +117,7 @@
json.put(ChallengeEmail::PARAMETER_KEY_CODE, "4567");
CaState request(Name("/ndn/site1"), "123", RequestType::NEW, Status::CHALLENGE, cert,
"email", ChallengeEmail::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key));
+ 3, time::seconds(3600), std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
@@ -139,7 +139,7 @@
json.put(ChallengeEmail::PARAMETER_KEY_CODE, "4567");
CaState request(Name("/ndn/site1"), "123", RequestType::NEW, Status::CHALLENGE, cert,
"email", ChallengeEmail::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key));
+ 3, time::seconds(3600), std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
diff --git a/tests/unit-tests/challenge-pin.t.cpp b/tests/unit-tests/challenge-pin.t.cpp
index 3655cca..fd61bef 100644
--- a/tests/unit-tests/challenge-pin.t.cpp
+++ b/tests/unit-tests/challenge-pin.t.cpp
@@ -57,7 +57,7 @@
secret.add(ChallengePin::PARAMETER_KEY_CODE, "12345");
CaState request(Name("/ndn/site1"), "123", RequestType::NEW, Status::CHALLENGE, cert,
"pin", ChallengePin::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(secret), makeEmptyBlock(ndn::tlv::ContentType_Key));
+ 3, time::seconds(3600), std::move(secret), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
@@ -79,7 +79,7 @@
secret.add(ChallengePin::PARAMETER_KEY_CODE, "12345");
CaState request(Name("/ndn/site1"), "123", RequestType::NEW, Status::CHALLENGE, cert,
"pin", ChallengePin::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(secret), makeEmptyBlock(ndn::tlv::ContentType_Key));
+ 3, time::seconds(3600), std::move(secret), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
diff --git a/tests/unit-tests/crypto-helper.t.cpp b/tests/unit-tests/crypto-helper.t.cpp
index 10e56cf..6e448c1 100644
--- a/tests/unit-tests/crypto-helper.t.cpp
+++ b/tests/unit-tests/crypto-helper.t.cpp
@@ -295,14 +295,45 @@
plaintext, plaintext + sizeof(plaintext));
}
+BOOST_AUTO_TEST_CASE(AesIV)
+{
+ const uint8_t key[] = {0xbc, 0x22, 0xf3, 0xf0, 0x5c, 0xc4, 0x0d, 0xb9,
+ 0x31, 0x1e, 0x41, 0x92, 0x96, 0x6f, 0xee, 0x92};
+ const std::string plaintext = "alongstringalongstringalongstringalongstringalongstringalongstringalongstringalongstring";
+ const std::string associatedData = "test";
+ uint32_t counter = 0;
+ auto block = encodeBlockWithAesGcm128(ndn::tlv::Content, key, (uint8_t*)plaintext.c_str(), plaintext.size(),
+ (uint8_t*)associatedData.c_str(), associatedData.size(), counter);
+ block.parse();
+ auto ivBlock = block.get(tlv::InitializationVector);
+ Buffer ivBuf(ivBlock.value(), ivBlock.value_size());
+ BOOST_CHECK_EQUAL(ivBuf.size(), 12);
+ BOOST_CHECK(ivBuf[0] >= 128);
+ BOOST_CHECK_EQUAL(ivBuf[8] + ivBuf[9] + ivBuf[10] + ivBuf[11], 0);
+ BOOST_CHECK_EQUAL(counter, 11);
+ counter = 300;
+ block = encodeBlockWithAesGcm128(ndn::tlv::ApplicationParameters, key, (uint8_t*)plaintext.c_str(), plaintext.size(),
+ (uint8_t*)associatedData.c_str(), associatedData.size(), counter);
+ block.parse();
+ ivBlock = block.get(tlv::InitializationVector);
+ Buffer ivBuf2(ivBlock.value(), ivBlock.value_size());
+ BOOST_CHECK_EQUAL(ivBuf2.size(), 12);
+ BOOST_CHECK(ivBuf2[0] < 128);
+ BOOST_CHECK_EQUAL(ivBuf2[8] + ivBuf2[9], 0);
+ BOOST_CHECK_EQUAL(ivBuf2[10], 1);
+ BOOST_CHECK_EQUAL(ivBuf2[11], 44);
+ BOOST_CHECK_EQUAL(counter, 311);
+}
+
BOOST_AUTO_TEST_CASE(BlockEncodingDecoding)
{
const uint8_t key[] = {0xbc, 0x22, 0xf3, 0xf0, 0x5c, 0xc4, 0x0d, 0xb9,
0x31, 0x1e, 0x41, 0x92, 0x96, 0x6f, 0xee, 0x92};
const std::string plaintext = "alongstringalongstringalongstringalongstringalongstringalongstringalongstringalongstring";
const std::string associatedData = "test";
+ uint32_t counter = 0;
auto block = encodeBlockWithAesGcm128(ndn::tlv::Content, key, (uint8_t*)plaintext.c_str(), plaintext.size(),
- (uint8_t*)associatedData.c_str(), associatedData.size());
+ (uint8_t*)associatedData.c_str(), associatedData.size(), counter);
auto decoded = decodeBlockWithAesGcm128(block, key, (uint8_t*)associatedData.c_str(), associatedData.size());
BOOST_CHECK_EQUAL(plaintext, std::string((char*)decoded.get<uint8_t>(), decoded.size()));
}