summaryrefslogtreecommitdiff
path: root/hash/ed2k.cpp
diff options
context:
space:
mode:
authorzyp <zyp@localhost>2006-01-26 20:07:15 +0100
committerzyp <zyp@localhost>2006-01-26 20:07:15 +0100
commit21559e9f4bd58b1504cc0fda7b0dceee0c833862 (patch)
tree119240a883b5bda7e4c11f60dc39206e87b1e04f /hash/ed2k.cpp
[project @ zyp-20060126190715-557e941315671b81]
[project @ 18] Moved disccat and pyanidb to the right location. Added pyqtmpc and ophidia.
Diffstat (limited to 'hash/ed2k.cpp')
-rw-r--r--hash/ed2k.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/hash/ed2k.cpp b/hash/ed2k.cpp
new file mode 100644
index 0000000..92e7b15
--- /dev/null
+++ b/hash/ed2k.cpp
@@ -0,0 +1,41 @@
+#include "ed2k.h"
+
+template<class T>
+inline T min(T a, T b) {
+ return (a > b) ? b : a;
+}
+
+Ed2k::Ed2k() {
+ MD4_Init(&md4_partial);
+ MD4_Init(&md4_final);
+ size_total = 0;
+}
+
+void Ed2k::update(const char* data, int length) {
+ while(length) {
+ if(!(size_total % (9500 * 1024)) && size_total) {
+ unsigned char digest[16];
+ MD4_Final(digest, &md4_partial);
+ MD4_Update(&md4_final, digest, 16);
+ MD4_Init(&md4_partial);
+ }
+ int size = min<int>(length, (9500 * 1024) - (size_total % (9500 * 1024)));
+ MD4_Update(&md4_partial, data, size);
+ length -= size;
+ data += size;
+ size_total += size;
+ };
+}
+
+char* Ed2k::digest() {
+ char* digest = new char[16];
+ if(size_total > (9500 * 1024)) {
+ unsigned char digest_partial[16];
+ MD4_Final(digest_partial, &md4_partial);
+ MD4_Update(&md4_final, digest_partial, 16);
+ MD4_Final((unsigned char*)digest, &md4_final);
+ } else {
+ MD4_Final((unsigned char*)digest, &md4_partial);
+ }
+ return digest;
+}