blob: 77e5baef5b6741a758c19b47c2bf6cd24e0b8fab [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Yingdi Yu21157162014-02-28 13:02:34 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Yingdi Yu21157162014-02-28 13:02:34 -080011 */
12
Yingdi Yu21157162014-02-28 13:02:34 -080013#include "security/key-chain.hpp"
14#include "security/validator.hpp"
15
Junxiao Shi482ccc52014-03-31 13:05:24 -070016#include "security/cryptopp.hpp"
Yingdi Yu21157162014-02-28 13:02:34 -080017
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070018#include "boost-test.hpp"
19
Yingdi Yu21157162014-02-28 13:02:34 -080020using namespace std;
21namespace ndn {
22
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070023BOOST_AUTO_TEST_SUITE(SecurityTestSignatureSha256)
Yingdi Yu21157162014-02-28 13:02:34 -080024
25string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
26
27BOOST_AUTO_TEST_CASE (Sha256)
28{
29 using namespace CryptoPP;
30
31 char content[6] = "1234\n";
32 ConstBufferPtr buf = crypto::sha256(reinterpret_cast<uint8_t*>(content), 5);
33 string result;
34 StringSource(buf->buf(), buf->size(), true, new HexEncoder(new StringSink(result), false));
35
36 BOOST_REQUIRE_EQUAL(SHA256_RESULT, result);
37}
38
39BOOST_AUTO_TEST_CASE (Signature)
40{
41 using namespace CryptoPP;
42
43 Name name("/TestSignatureSha/Basic");
44 Data testData(name);
45 char content[5] = "1234";
46 testData.setContent(reinterpret_cast<uint8_t*>(content), 5);
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070047
Yingdi Yu21157162014-02-28 13:02:34 -080048 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain;
49 keychain.signWithSha256(testData);
50
51 testData.wireEncode();
52
53 SignatureSha256 sig(testData.getSignature());
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070054
Yingdi Yu21157162014-02-28 13:02:34 -080055 BOOST_REQUIRE(Validator::verifySignature(testData, sig));
56}
57
58BOOST_AUTO_TEST_SUITE_END()
59
60} // namespace ndn