blob: 162100516b55d63685e3bba3ff8d95e4dc316ebb [file] [log] [blame]
Jeff Thompson3af7e792013-08-23 14:22:11 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompson3af7e792013-08-23 14:22:11 -07003 * See COPYING for copyright and distribution information.
4 */
5
Yingdi Yu21157162014-02-28 13:02:34 -08006#include "../common.hpp"
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08007
8#include "crypto.hpp"
Junxiao Shi482ccc52014-03-31 13:05:24 -07009#include "../security/cryptopp.hpp"
Alexander Afanasyevd409d592014-01-28 18:36:38 -080010
11namespace ndn {
Jeff Thompson3af7e792013-08-23 14:22:11 -070012
Jeff Thompson97223af2013-09-24 17:01:27 -070013void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
Jeff Thompson3af7e792013-08-23 14:22:11 -070014{
Yingdi Yu21157162014-02-28 13:02:34 -080015 try
16 {
17 using namespace CryptoPP;
18
19 CryptoPP::SHA256 hash;
20 OBufferStream os;
Yingdi Yu110881d2014-03-04 18:27:29 -080021 StringSource(data, dataLength, true, new HashFilter(hash, new ArraySink(digest, crypto::SHA256_DIGEST_SIZE)));
Yingdi Yu21157162014-02-28 13:02:34 -080022 }
23 catch(CryptoPP::Exception& e)
24 {
25 return;
26 }
27
Jeff Thompson3af7e792013-08-23 14:22:11 -070028}
Alexander Afanasyevd409d592014-01-28 18:36:38 -080029
Yingdi Yu21157162014-02-28 13:02:34 -080030namespace crypto {
31
32ConstBufferPtr
33sha256(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
Alexander Afanasyevd409d592014-01-28 18:36:38 -080052} // namespace ndn