security: Add SignatureSha256

Change-Id: Id9a61f898d12a6b289a24adb594471b26d3513d6
diff --git a/src/security/validator.cpp b/src/security/validator.cpp
index cabd082..1e5aedc 100644
--- a/src/security/validator.cpp
+++ b/src/security/validator.cpp
@@ -10,12 +10,16 @@
 
 #include "validator.hpp"
 #include "../util/logging.hpp"
+#include "../util/crypto.hpp"
 
 #include <cryptopp/rsa.h>
+#include <cryptopp/files.h>
+#include <cryptopp/hex.h>
+
 
 using namespace std;
 
-INIT_LOGGER("ndn::Validator");
+INIT_LOGGER("ndn.Validator");
 
 namespace ndn {
 
@@ -137,7 +141,7 @@
 }
 
 bool
-Validator::verifySignature(const Interest &interest, const PublicKey &key)
+Validator::verifySignature(const Interest& interest, const PublicKey& key)
 {
   const Name &interestName = interest.getName();
 
@@ -181,7 +185,7 @@
 }
 
 bool
-Validator::verifySignature(const Buffer &data, const Signature &sig, const PublicKey &key)
+Validator::verifySignature(const Buffer& data, const Signature& sig, const PublicKey& key)
 {
   try
     {
@@ -207,7 +211,7 @@
 }
 
 bool
-Validator::verifySignature(const uint8_t* buf, const size_t size, const SignatureSha256WithRsa &sig, const PublicKey &key)
+Validator::verifySignature(const uint8_t* buf, const size_t size, const SignatureSha256WithRsa& sig, const PublicKey& key)
 {
   try
     {
@@ -229,4 +233,35 @@
     }
 }
 
+bool
+Validator::verifySignature(const uint8_t* buf, const size_t size, const SignatureSha256& sig)
+{
+  try
+    {
+      ConstBufferPtr buffer = crypto::sha256(buf, size);
+      const Block& sigValue = sig.getValue();
+
+      if(static_cast<bool>(buffer) 
+         && buffer->size() == sigValue.value_size()
+         && buffer->size() == crypto::SHA256_DIGEST_LENGTH)
+        {
+
+          const uint8_t* p1 = buffer->buf();
+          const uint8_t* p2 = sigValue.value();
+
+          for(int i = 0; i < crypto::SHA256_DIGEST_LENGTH; i++)
+            if(p1[i] != p2[i]) 
+              return false;
+          return true;
+        }
+      else
+        return false;
+    }
+  catch(CryptoPP::Exception& e)
+    {
+      _LOG_DEBUG("verifySignature: " << e.what());
+      return false;
+    }
+}
+
 } // namespace ndn