aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2013-04-16 08:38:51 +0200
committerGravatar Christian Hesse <mail@eworm.de>2013-04-16 08:38:51 +0200
commite56ed2ffea0245eee3c08edd97d5e560a964c78d (patch)
treee0c2bad22282e9a0777a268831d668e5d77e9efd
parent7d38cb8a72cb9d864d753b15f47026a3d97a124f (diff)
downloadnthash-0.1.0.tar.gz
nthash-0.1.0.tar.zst
initial commit0.1.0
-rw-r--r--.gitignore3
-rw-r--r--Makefile11
-rw-r--r--nthash.c42
3 files changed, 56 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4a79314
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*~
+*.o
+nthash
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8c11863
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+# nthash - Generate NT Hash
+
+CC := gcc
+CFLAGS += $(shell pkg-config --cflags --libs nettle)
+VERSION = $(shell git describe --tags --long)
+
+all: nthash.c
+ $(CC) $(CFLAGS) -o nthash nthash.c
+
+clean:
+ /bin/rm -f *.o *~ nthash
diff --git a/nthash.c b/nthash.c
new file mode 100644
index 0000000..16afe60
--- /dev/null
+++ b/nthash.c
@@ -0,0 +1,42 @@
+/* (c) 2012-2013 Christian Hesse <mail@eworm.de>
+ * Base on an example from:
+ * http://www.lysator.liu.se/~nisse/nettle/nettle.html#Example */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nettle/md4.h>
+
+#define BUF_SIZE 1024
+
+int main(int argc, char **argv) {
+ struct md4_ctx ctx;
+ uint8_t buffer[BUF_SIZE], buffernull[2*BUF_SIZE];
+ uint8_t digest[MD4_DIGEST_SIZE];
+ int i, done;
+
+ md4_init(&ctx);
+ for (;;) {
+ done = fread(buffer, 1, sizeof(buffer), stdin);
+ // add null bytes to string
+ for (i = 0; i < done; i++) {
+ if (buffer[i] == 0xa)
+ fprintf(stderr, "Warning: Password contains line break!\n");
+ buffernull[i*2] = buffer[i];
+ buffernull[i*2+1] = 0;
+ }
+ md4_update(&ctx, done*2, buffernull);
+ if (done < sizeof(buffer))
+ break;
+ }
+ if (ferror(stdin))
+ return EXIT_FAILURE;
+
+ md4_digest(&ctx, MD4_DIGEST_SIZE, digest);
+
+ for (i = 0; i < MD4_DIGEST_SIZE; i++)
+ printf("%02x ", digest[i]);
+ printf("\n");
+
+ return EXIT_SUCCESS;
+}