blob: 3aa114a35b976ff7b25bbb9d8f6fb694d1655048 [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"
Yingdi Yu21157162014-02-28 13:02:34 -08009#include <cryptopp/sha.h>
10#include <cryptopp/filters.h>
11#include <cryptopp/files.h>
Alexander Afanasyevd409d592014-01-28 18:36:38 -080012
13namespace ndn {
Jeff Thompson3af7e792013-08-23 14:22:11 -070014
Jeff Thompson97223af2013-09-24 17:01:27 -070015void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
Jeff Thompson3af7e792013-08-23 14:22:11 -070016{
Yingdi Yu21157162014-02-28 13:02:34 -080017 try
18 {
19 using namespace CryptoPP;
20
21 CryptoPP::SHA256 hash;
22 OBufferStream os;
Yingdi Yu110881d2014-03-04 18:27:29 -080023 StringSource(data, dataLength, true, new HashFilter(hash, new ArraySink(digest, crypto::SHA256_DIGEST_SIZE)));
Yingdi Yu21157162014-02-28 13:02:34 -080024 }
25 catch(CryptoPP::Exception& e)
26 {
27 return;
28 }
29
Jeff Thompson3af7e792013-08-23 14:22:11 -070030}
Alexander Afanasyevd409d592014-01-28 18:36:38 -080031
Yingdi Yu21157162014-02-28 13:02:34 -080032namespace crypto {
33
34ConstBufferPtr
35sha256(const uint8_t *data, size_t dataLength)
36{
37 try
38 {
39 using namespace CryptoPP;
40
41 SHA256 hash;
42 OBufferStream os;
43 StringSource(data, dataLength, true, new HashFilter(hash, new FileSink(os)));
44 return os.buf();
45 }
46 catch(CryptoPP::Exception& e)
47 {
48 return ConstBufferPtr();
49 }
50}
51
52} // namespace crypto
53
Alexander Afanasyevd409d592014-01-28 18:36:38 -080054} // namespace ndn