All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
crypto.cpp
Go to the documentation of this file.
1 
6 #include "../common.hpp"
7 
8 #include "crypto.hpp"
9 #include "../security/cryptopp.hpp"
10 
11 namespace ndn {
12 
13 void ndn_digestSha256(const uint8_t* data, size_t dataLength, uint8_t* digest)
14 {
15  try
16  {
17  using namespace CryptoPP;
18 
19  CryptoPP::SHA256 hash;
20  OBufferStream os;
21  StringSource(data, dataLength, true, new HashFilter(hash, new ArraySink(digest, crypto::SHA256_DIGEST_SIZE)));
22  }
23  catch (CryptoPP::Exception& e)
24  {
25  return;
26  }
27 
28 }
29 
30 namespace crypto {
31 
33 sha256(const uint8_t* data, size_t dataLength)
34 {
35  try
36  {
37  using namespace CryptoPP;
38 
39  SHA256 hash;
40  OBufferStream os;
41  StringSource(data, dataLength, true, new HashFilter(hash, new FileSink(os)));
42  return os.buf();
43  }
44  catch (CryptoPP::Exception& e)
45  {
46  return ConstBufferPtr();
47  }
48 }
49 
50 } // namespace crypto
51 
52 } // namespace ndn
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
Definition: buffer.hpp:176
void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
Compute the sha-256 digest of data.
Definition: crypto.cpp:13
static const size_t SHA256_DIGEST_SIZE
number of octets in a SHA256 digest
Definition: crypto.hpp:26
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:17
ConstBufferPtr sha256(const uint8_t *data, size_t dataLength)
Compute the sha-256 digest of data.
Definition: crypto.cpp:33