security: Add SignatureSha256
Change-Id: Id9a61f898d12a6b289a24adb594471b26d3513d6
diff --git a/src/util/crypto.cpp b/src/util/crypto.cpp
index 8967523..b0767fa 100644
--- a/src/util/crypto.cpp
+++ b/src/util/crypto.cpp
@@ -1,21 +1,54 @@
/**
* Copyright (C) 2013 Regents of the University of California.
- * @author: Jeff Thompson <jefft0@remap.ucla.edu>
* See COPYING for copyright and distribution information.
*/
-#include "common.hpp"
+#include "../common.hpp"
#include "crypto.hpp"
+#include <cryptopp/sha.h>
+#include <cryptopp/filters.h>
+#include <cryptopp/files.h>
namespace ndn {
void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
{
- SHA256_CTX sha256;
- SHA256_Init(&sha256);
- SHA256_Update(&sha256, data, dataLength);
- SHA256_Final(digest, &sha256);
+ try
+ {
+ using namespace CryptoPP;
+
+ CryptoPP::SHA256 hash;
+ OBufferStream os;
+ StringSource(data, dataLength, true, new HashFilter(hash, new ArraySink(digest, crypto::SHA256_DIGEST_LENGTH)));
+ }
+ catch(CryptoPP::Exception& e)
+ {
+ return;
+ }
+
}
+namespace crypto {
+
+ConstBufferPtr
+sha256(const uint8_t *data, size_t dataLength)
+{
+ try
+ {
+ using namespace CryptoPP;
+
+ SHA256 hash;
+ OBufferStream os;
+ StringSource(data, dataLength, true, new HashFilter(hash, new FileSink(os)));
+ return os.buf();
+ }
+ catch(CryptoPP::Exception& e)
+ {
+ return ConstBufferPtr();
+ }
+}
+
+} // namespace crypto
+
} // namespace ndn