summaryrefslogtreecommitdiff
path: root/usr.bin/tcfs/gentcfskey.c
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2000-06-18 22:07:26 +0000
committerNiels Provos <provos@cvs.openbsd.org>2000-06-18 22:07:26 +0000
commit48893562fdfa12c4f376d2556da18e817a34484f (patch)
tree033e9aaa47f5617ba6ffbcf7e071ffb8f8f71b07 /usr.bin/tcfs/gentcfskey.c
parent47bc7a26b81967e77c0f021899f1544966df67e2 (diff)
Initial import of very much rewritten TCFS userland. This code is still
nasty.
Diffstat (limited to 'usr.bin/tcfs/gentcfskey.c')
-rw-r--r--usr.bin/tcfs/gentcfskey.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/usr.bin/tcfs/gentcfskey.c b/usr.bin/tcfs/gentcfskey.c
new file mode 100644
index 00000000000..ffc45b9f3c7
--- /dev/null
+++ b/usr.bin/tcfs/gentcfskey.c
@@ -0,0 +1,51 @@
+/*
+ * Transparent Cryptographic File System (TCFS) for NetBSD
+ * Author and mantainer: Luigi Catuogno [luicat@tcfs.unisa.it]
+ *
+ * references: http://tcfs.dia.unisa.it
+ * tcfs-bsd@tcfs.unisa.it
+ */
+
+/*
+ * Base utility set v0.1
+ */
+
+#include <stdio.h>
+#include <sys/time.h>
+#include <termios.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <err.h>
+#include <md5.h>
+
+#include <miscfs/tcfs/tcfs.h>
+#include "tcfsdefines.h"
+
+u_char *
+gentcfskey (void)
+{
+ u_char *buff;
+ MD5_CTX ctx, ctx2;
+ u_int32_t tmp[KEYSIZE];
+ u_char digest[16];
+ int i;
+
+ buff = (u_char *)calloc(KEYSIZE + 1, sizeof(char));
+
+ /* Generate random key */
+ for (i = 0; i < KEYSIZE; i ++)
+ tmp[i] = arc4random();
+
+ MD5Init(&ctx);
+ for (i = 0; i < KEYSIZE; i += 16) {
+ MD5Update(&ctx, (u_char *)tmp, sizeof(tmp));
+ ctx2 = ctx;
+ MD5Final(digest, &ctx2);
+ memcpy(buff + i, digest, KEYSIZE - i > 16 ? 16 : KEYSIZE - i);
+ }
+ buff[KEYSIZE] = '\0';
+ memset(&ctx, 0, sizeof(ctx));
+
+ return (buff);
+}