NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
crypto.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "../common.hpp"
23 
24 #include "crypto.hpp"
25 #include "../encoding/buffer-stream.hpp"
26 #include "../security/cryptopp.hpp"
27 
28 namespace ndn {
29 
30 void ndn_digestSha256(const uint8_t* data, size_t dataLength, uint8_t* digest)
31 {
32  try
33  {
34  using namespace CryptoPP;
35 
36  CryptoPP::SHA256 hash;
37  OBufferStream os;
38  StringSource(data, dataLength, true,
39  new HashFilter(hash, new ArraySink(digest, crypto::SHA256_DIGEST_SIZE)));
40  }
41  catch (CryptoPP::Exception& e)
42  {
43  return;
44  }
45 
46 }
47 
48 namespace crypto {
49 
51 sha256(const uint8_t* data, size_t dataLength)
52 {
53  try
54  {
55  using namespace CryptoPP;
56 
57  SHA256 hash;
58  OBufferStream os;
59  StringSource(data, dataLength, true, new HashFilter(hash, new FileSink(os)));
60  return os.buf();
61  }
62  catch (CryptoPP::Exception& e)
63  {
64  return ConstBufferPtr();
65  }
66 }
67 
68 } // namespace crypto
69 
70 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
Copyright (c) 2013-2014 Regents of the University of California.
Definition: oid.hpp:29
void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
Compute the sha-256 digest of data.
Definition: crypto.cpp:30
static const size_t SHA256_DIGEST_SIZE
number of octets in a SHA256 digest
Definition: crypto.hpp:43
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
ConstBufferPtr sha256(const uint8_t *data, size_t dataLength)
Compute the sha-256 digest of data.
Definition: crypto.cpp:51