Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 1 | /** |
| 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 Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 7 | #include "security/key-chain.hpp" |
| 8 | #include "security/validator.hpp" |
| 9 | |
Junxiao Shi | 482ccc5 | 2014-03-31 13:05:24 -0700 | [diff] [blame] | 10 | #include "security/cryptopp.hpp" |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 11 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 12 | #include "boost-test.hpp" |
| 13 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 14 | using namespace std; |
| 15 | namespace ndn { |
| 16 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 17 | BOOST_AUTO_TEST_SUITE(SecurityTestSignatureSha256) |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 18 | |
| 19 | string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4"); |
| 20 | |
| 21 | BOOST_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 | |
| 33 | BOOST_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 Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 41 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 42 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain; |
| 43 | keychain.signWithSha256(testData); |
| 44 | |
| 45 | testData.wireEncode(); |
| 46 | |
| 47 | SignatureSha256 sig(testData.getSignature()); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 48 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 49 | BOOST_REQUIRE(Validator::verifySignature(testData, sig)); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_SUITE_END() |
| 53 | |
| 54 | } // namespace ndn |