aboutsummaryrefslogtreecommitdiff
path: root/src/hash/md5/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash/md5/tests')
-rw-r--r--src/hash/md5/tests/CMakeLists.txt7
-rw-r--r--src/hash/md5/tests/md5cmp.c38
2 files changed, 45 insertions, 0 deletions
diff --git a/src/hash/md5/tests/CMakeLists.txt b/src/hash/md5/tests/CMakeLists.txt
new file mode 100644
index 0000000..8b03af4
--- /dev/null
+++ b/src/hash/md5/tests/CMakeLists.txt
@@ -0,0 +1,7 @@
+
+add_executable(md5cmp md5cmp.c)
+target_link_libraries(md5cmp md5)
+
+add_test(NAME md5_hash_test
+ COMMAND md5cmp ABCDEF 8827a41122a5028b9808c7bf84b9fcf6
+ ) \ No newline at end of file
diff --git a/src/hash/md5/tests/md5cmp.c b/src/hash/md5/tests/md5cmp.c
new file mode 100644
index 0000000..a34de3a
--- /dev/null
+++ b/src/hash/md5/tests/md5cmp.c
@@ -0,0 +1,38 @@
+/**
+ * Compares the hash of a given string against a
+ * given hash
+ *
+ * Used for testing to ensure we don't run into
+ * Windows weirdness again
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "md5.h"
+
+
+int main(int argc, char** argv)
+{
+ if (argc < 3)
+ {
+ puts("md5cmp input expected-hash");
+ return 1;
+ }
+
+ MD5_CTX context;
+ MD5_Init(&context);
+ MD5_Update(&context, argv[1], strlen(argv[1]));
+
+ unsigned char digest[16];
+ MD5_Final(digest, &context);
+
+ char md5string[33];
+ for(int i = 0; i < 16; ++i)
+ snprintf(&md5string[i*2], 3, "%02x", (unsigned int)digest[i]);
+
+ if (!strncmp(md5string, argv[2], sizeof(md5string)))
+ return 0;
+
+ return 1;
+} \ No newline at end of file