blob: 4491f13ad7c1ba0834f8643e11381c8572a0f386 [file] [log] [blame]
Yingdi Yu21157162014-02-28 13:02:34 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Yingdi Yu <yingdi0@cs.ucla.edu>
4 * See COPYING for copyright and distribution information.
5 */
6
Yingdi Yu21157162014-02-28 13:02:34 -08007#include "security/key-chain.hpp"
8#include "security/validator.hpp"
9
Junxiao Shi482ccc52014-03-31 13:05:24 -070010#include "security/cryptopp.hpp"
Yingdi Yu21157162014-02-28 13:02:34 -080011
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070012#include "boost-test.hpp"
13
Yingdi Yu21157162014-02-28 13:02:34 -080014using namespace std;
15namespace ndn {
16
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070017BOOST_AUTO_TEST_SUITE(SecurityTestSignatureSha256)
Yingdi Yu21157162014-02-28 13:02:34 -080018
19string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
20
21BOOST_AUTO_TEST_CASE (Sha256)
22{
23 using namespace CryptoPP;
24
25 char content[6] = "1234\n";
26 ConstBufferPtr buf = crypto::sha256(reinterpret_cast<uint8_t*>(content), 5);
27 string result;
28 StringSource(buf->buf(), buf->size(), true, new HexEncoder(new StringSink(result), false));
29
30 BOOST_REQUIRE_EQUAL(SHA256_RESULT, result);
31}
32
33BOOST_AUTO_TEST_CASE (Signature)
34{
35 using namespace CryptoPP;
36
37 Name name("/TestSignatureSha/Basic");
38 Data testData(name);
39 char content[5] = "1234";
40 testData.setContent(reinterpret_cast<uint8_t*>(content), 5);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070041
Yingdi Yu21157162014-02-28 13:02:34 -080042 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain;
43 keychain.signWithSha256(testData);
44
45 testData.wireEncode();
46
47 SignatureSha256 sig(testData.getSignature());
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070048
Yingdi Yu21157162014-02-28 13:02:34 -080049 BOOST_REQUIRE(Validator::verifySignature(testData, sig));
50}
51
52BOOST_AUTO_TEST_SUITE_END()
53
54} // namespace ndn