aboutsummaryrefslogtreecommitdiff
path: root/src/hash/md5/tests/md5cmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash/md5/tests/md5cmp.c')
-rw-r--r--src/hash/md5/tests/md5cmp.c38
1 files changed, 38 insertions, 0 deletions
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