Jeff Thompson | 3af7e79 | 2013-08-23 14:22:11 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
Jeff Thompson | 3af7e79 | 2013-08-23 14:22:11 -0700 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 6 | #include "../common.hpp" |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 7 | |
| 8 | #include "crypto.hpp" |
Junxiao Shi | 482ccc5 | 2014-03-31 13:05:24 -0700 | [diff] [blame^] | 9 | #include "../security/cryptopp.hpp" |
Alexander Afanasyev | d409d59 | 2014-01-28 18:36:38 -0800 | [diff] [blame] | 10 | |
| 11 | namespace ndn { |
Jeff Thompson | 3af7e79 | 2013-08-23 14:22:11 -0700 | [diff] [blame] | 12 | |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 13 | void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest) |
Jeff Thompson | 3af7e79 | 2013-08-23 14:22:11 -0700 | [diff] [blame] | 14 | { |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 15 | try |
| 16 | { |
| 17 | using namespace CryptoPP; |
| 18 | |
| 19 | CryptoPP::SHA256 hash; |
| 20 | OBufferStream os; |
Yingdi Yu | 110881d | 2014-03-04 18:27:29 -0800 | [diff] [blame] | 21 | StringSource(data, dataLength, true, new HashFilter(hash, new ArraySink(digest, crypto::SHA256_DIGEST_SIZE))); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 22 | } |
| 23 | catch(CryptoPP::Exception& e) |
| 24 | { |
| 25 | return; |
| 26 | } |
| 27 | |
Jeff Thompson | 3af7e79 | 2013-08-23 14:22:11 -0700 | [diff] [blame] | 28 | } |
Alexander Afanasyev | d409d59 | 2014-01-28 18:36:38 -0800 | [diff] [blame] | 29 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 30 | namespace crypto { |
| 31 | |
| 32 | ConstBufferPtr |
| 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 | |
Alexander Afanasyev | d409d59 | 2014-01-28 18:36:38 -0800 | [diff] [blame] | 52 | } // namespace ndn |