Added initial pwcrypt.c and Makefile
authorHansjürg Wenger <wgh1@bfh.ch>
Sat, 1 Oct 2016 13:07:29 +0000 (15:07 +0200)
committerHansjürg Wenger <wgh1@bfh.ch>
Sat, 1 Oct 2016 13:07:29 +0000 (15:07 +0200)
Makefile [new file with mode: 0644]
pwcrypt.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..2079467
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,46 @@
+#
+# Makefile for pwcrypt
+#
+# (c) 2016 WGH1@BFH
+#
+#
+
+# Compiler to use
+CC=gcc
+
+# Password generator to use (for demo)
+PG=pwgen
+
+all:           pwcrypt test demo
+
+# Compile pwcrypt
+pwcrypt:       pwcrypt.c
+               $(CC) pwcrypt.c -l crypt -o pwcrypt
+
+# Test with SHA-512 encryption (first $ masks second $)
+test=$(shell ./pwcrypt '$$6$$__Salt__$$' '& __Pepper__')
+test:          pwcrypt
+               @echo 'Hash: $(test)'
+
+# Demo with SHA-512 ("pwgen" required for random salt & pepper)
+demo=$(shell ./pwcrypt '$(salt)' '$(pepper)')
+demo:          pwcrypt salt pepper 
+               @echo 'Hash: $(demo)'
+
+# Salt for demo
+salt:=$$6$$$(shell $(PG) -1)$$
+salt:          pwgen
+               @echo 'Salt: $(salt)'
+
+# Pepper (Password) for demo
+pepper:=$(shell $(PG) -1 12)
+pepper:                pwgen
+               @echo 'Pass: $(pepper)'
+
+# Check if pwgen is installed on the system
+pwgen: 
+       @which $(PG) > /dev/null ||  echo Install "$(PG)" first
+
+# remove pwcrypt binary
+clean:
+               -rm pwcrypt
diff --git a/pwcrypt.c b/pwcrypt.c
new file mode 100644 (file)
index 0000000..30abe77
--- /dev/null
+++ b/pwcrypt.c
@@ -0,0 +1,30 @@
+/*
+ * (c) 1994-2015 WGH1@BFH
+ *
+ * demonstrates the UNIX/Linux 
+ * password encryption function crypt()
+ *
+ * more infos see "man 3 crypt"
+ *
+ */
+
+#include <stdio.h>
+#define _XOPEN_SOURCE
+#define __USE_XOPEN
+#include <unistd.h>
+
+char * crypt();
+
+int main(int argc, char * argv[])
+{
+       if (argc != 3)
+       {
+               printf("Usage: pwcrypt salt password\n");
+       }
+       else
+       {
+               printf("%s",crypt(argv[2],argv[1]));
+               printf("\n");
+       }
+       return (0);
+}