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
50
ConstBufferPtr
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
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
CryptoPP
Copyright (c) 2013-2014 Regents of the University of California.
Definition:
oid.hpp:29
ndn::ndn_digestSha256
void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
Compute the sha-256 digest of data.
Definition:
crypto.cpp:30
ndn::crypto::SHA256_DIGEST_SIZE
static const size_t SHA256_DIGEST_SIZE
number of octets in a SHA256 digest
Definition:
crypto.hpp:43
crypto.hpp
ndn::OBufferStream::buf
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Definition:
buffer-stream.hpp:96
ndn::OBufferStream
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
Definition:
buffer-stream.hpp:79
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition:
buffer.hpp:33
ndn::crypto::sha256
ConstBufferPtr sha256(const uint8_t *data, size_t dataLength)
Compute the sha-256 digest of data.
Definition:
crypto.cpp:51
ndnSIM
ndn-cxx
src
util
crypto.cpp
Generated on Fri Feb 23 2018 12:30:55 for ndnSIM by
1.8.14