summaryrefslogtreecommitdiffstats
path: root/Source/cmCryptoHash.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-11-16 01:32:43 (GMT)
committerBrad King <brad.king@kitware.com>2011-11-16 15:15:44 (GMT)
commit38771d3bdf51b81d46578e0c81ebddbdea0ce3b2 (patch)
treecb83e9ed3b723144b427a5acf083fdc384953761 /Source/cmCryptoHash.cxx
parent73efd4a5044d2346e14d019197e2ddced3f9b7a8 (diff)
downloadCMake-38771d3bdf51b81d46578e0c81ebddbdea0ce3b2.zip
CMake-38771d3bdf51b81d46578e0c81ebddbdea0ce3b2.tar.gz
CMake-38771d3bdf51b81d46578e0c81ebddbdea0ce3b2.tar.bz2
Add file(SHA*) commands to compute cryptographic hashes
Add a file() command API for SHA1, SHA224, SHA256, SHA384, and SHA512.
Diffstat (limited to 'Source/cmCryptoHash.cxx')
-rw-r--r--Source/cmCryptoHash.cxx21
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 3a73398..411da58 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -12,6 +12,7 @@
#include "cmCryptoHash.h"
#include <cmsys/MD5.h>
+#include "cm_sha2.h"
//----------------------------------------------------------------------------
std::string cmCryptoHash::HashString(const char* input)
@@ -88,3 +89,23 @@ std::string cmCryptoHashMD5::Finalize()
cmsysMD5_FinalizeHex(this->MD5, md5out);
return std::string(md5out, 32);
}
+
+
+#define cmCryptoHash_SHA_CLASS_IMPL(SHA) \
+cmCryptoHash##SHA::cmCryptoHash##SHA(): SHA(new SHA_CTX) {} \
+cmCryptoHash##SHA::~cmCryptoHash##SHA() { delete this->SHA; } \
+void cmCryptoHash##SHA::Initialize() { SHA##_Init(this->SHA); } \
+void cmCryptoHash##SHA::Append(unsigned char const* buf, int sz) \
+{ SHA##_Update(this->SHA, buf, sz); } \
+std::string cmCryptoHash##SHA::Finalize() \
+{ \
+ char out[SHA##_DIGEST_STRING_LENGTH]; \
+ SHA##_End(this->SHA, out); \
+ return std::string(out, SHA##_DIGEST_STRING_LENGTH-1); \
+}
+
+cmCryptoHash_SHA_CLASS_IMPL(SHA1)
+cmCryptoHash_SHA_CLASS_IMPL(SHA224)
+cmCryptoHash_SHA_CLASS_IMPL(SHA256)
+cmCryptoHash_SHA_CLASS_IMPL(SHA384)
+cmCryptoHash_SHA_CLASS_IMPL(SHA512)