Permalink
Browse files

stupid sha1 fix

  • Loading branch information...
1 parent f5a7cc6 commit 608c55da0d4dcaab5a72545d47584c3c02d6bed7 @albertz committed Mar 6, 2011
Showing with 22 additions and 4 deletions.
  1. +19 −1 Sha1.cpp
  2. +3 −3 Sha1.h
View
@@ -76,7 +76,7 @@ A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
-/* #define SHA1HANDSOFF */
+#define SHA1HANDSOFF
#include <cstdio>
#include <cstring>
@@ -258,3 +258,21 @@ std::string Sha1Context::final()
return std::string((char*)digest, SHA1_DIGEST_SIZE);
}
+
+/*
+ // OpenSSL code
+
+#include <openssl/sha.h>
+
+std::string calc_sha1(const char* data, size_t size) {
+ std::string s(SHA_DIGEST_LENGTH, 0);
+ SHA1((const unsigned char*) data, size, (unsigned char*) &s[0]);
+ return s;
+}
+*/
+
+std::string calc_sha1(const char* data, size_t size) {
+ Sha1Context c;
+ c.update(data, size);
+ return c.final();
+}
View
6 Sha1.h
@@ -19,10 +19,10 @@ struct Sha1Context {
std::string final();
};
+std::string calc_sha1(const char* data, size_t s);
+
inline std::string calc_sha1(const std::string& data) {
- Sha1Context c;
- c.update(&data[0], data.size());
- return c.final();
+ return calc_sha1(&data[0], data.size());
}
#endif /* __SHA1_H */

0 comments on commit 608c55d

Please sign in to comment.