Commit Diff


commit - /dev/null
commit + 923eb99132a317b8a4b6b9a8849d26fc528f23ba
blob - /dev/null
blob + 8071fbc4ad1d1dbf0a8c2642c1a50d4f8cb05c12 (mode 644)
--- /dev/null
+++ Makefile
@@ -0,0 +1,17 @@
+PROG=pass-calculator
+SRCS=pass-calculator.c
+
+NOMAN=1
+
+# taken from pkg-config --cflags gtk+-2.0
+CFLAGS=-I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/pango-1.0 -I/usr/local/include/gio-unix-2.0/ -I/usr/X11R6/include -I/usr/local/include/cairo -I/usr/local/include/atk-1.0 -I/usr/X11R6/include/pixman-1 -I/usr/local/include/libpng16 -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/harfbuzz -pthread -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -I/usr/X11R6/include/freetype2 -I/usr/include -L/usr/local/lib -L/usr/X11R6/lib -Wl,-rpath-link,/usr/X11R6/lib
+
+# taken from pkg-config --libs gtk+-2.0
+LDFLAGS=-I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/local/include/pango-1.0 -I/usr/local/include/gio-unix-2.0/ -I/usr/X11R6/include -I/usr/local/include/cairo -I/usr/local/include/atk-1.0 -I/usr/X11R6/include/pixman-1 -I/usr/local/include/libpng16 -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/harfbuzz -pthread -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -I/usr/X11R6/include/freetype2 -I/usr/include -L/usr/local/lib -L/usr/X11R6/lib -Wl,-rpath-link,/usr/X11R6/lib
+
+# taken from pkg-config --libs gtk+-2.0
+LDADD=-lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -lXrender -lXinerama -lXi -lXrandr -lXcursor -lXcomposite -lXdamage -lXfixes -lX11 -lXext -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lm -lgobject-2.0 -lglib-2.0 -lintl -lfontconfig -lfreetype -lz -lcrypto -lssl
+
+NOMAN=1
+
+.include <bsd.prog.mk>
blob - /dev/null
blob + db2a1b557aff1deac719a0fd364f68529f5ec1bf (mode 644)
--- /dev/null
+++ pass-calculator.c
@@ -0,0 +1,171 @@
+/* 
+ * Copyright (c) 2019 Peter J. Philipp
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <resolv.h>
+
+#include <openssl/sha.h>
+#include <gtk/gtk.h>
+
+char *output = NULL;
+GtkWidget *window, *label, *result, *vbox, *table;
+GtkWidget *passphrase ;
+GtkWidget *calcwindow, *exit_window, *button, *spin_int;
+
+static void destroy(GtkWidget*, gpointer);
+static void calculate(GtkWidget*, gpointer);
+char * shaproc(char *input);
+
+int
+main(int argc, char *argv[])
+{
+
+
+	output = calloc(1, 200);
+	if (output == NULL) {
+		perror("calloc");
+		exit(1);
+	}
+
+	gtk_init(&argc, &argv);
+
+	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+	gtk_window_set_title(GTK_WINDOW(window), "Pass Calculator");
+	gtk_container_set_border_width(GTK_CONTAINER(window), 25);
+	
+	gtk_widget_set_size_request(window, 600, 400);
+
+	vbox = gtk_vbox_new(FALSE, 5);
+
+	/* top entry */
+	result = gtk_entry_new();
+	gtk_box_pack_start_defaults(GTK_BOX(vbox), result);
+
+	/* table here */
+	table = gtk_table_new(2, 2, TRUE);
+	label = gtk_label_new("Enter your pass-phrase");
+	passphrase = gtk_entry_new();
+	
+	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, 
+		GTK_EXPAND, GTK_SHRINK, 0, 0);
+
+	gtk_table_attach(GTK_TABLE(table), passphrase, 1, 2, 1, 2, 
+		GTK_EXPAND, GTK_SHRINK, 0, 0);
+
+	gtk_table_set_row_spacings(GTK_TABLE(table), 5);
+	gtk_table_set_col_spacings(GTK_TABLE(table), 5);
+
+	gtk_box_pack_start_defaults(GTK_BOX(vbox), table);
+	
+	/* spin button */
+
+	spin_int = gtk_spin_button_new_with_range(0.0, 1000000000.0, 1.0);
+	gtk_box_pack_start_defaults(GTK_BOX(vbox), spin_int);
+	
+	button = gtk_button_new_with_mnemonic("Calculate");
+	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(calculate), NULL);
+
+	gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
+
+	gtk_box_pack_start_defaults(GTK_BOX(vbox), button);
+
+
+	/* exit window */
+
+	exit_window = gtk_button_new_with_mnemonic("Exit");
+
+	gtk_signal_connect(G_OBJECT(exit_window), "destroy", G_CALLBACK(destroy), NULL);
+	gtk_button_set_relief(GTK_BUTTON(exit_window), GTK_RELIEF_NONE);
+	
+	g_signal_connect_swapped(G_OBJECT(exit_window), "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer)window);
+	
+
+	gtk_box_pack_start_defaults(GTK_BOX(vbox), exit_window);
+
+	gtk_container_add(GTK_CONTAINER(window), vbox);
+	gtk_widget_show_all(window);
+
+	gtk_main();
+	
+	return (0);
+}
+
+static void
+destroy(GtkWidget *window, gpointer data)
+{
+	gtk_main_quit();
+}
+
+static void
+calculate(GtkWidget *window, gpointer data)
+{
+	char *p, *q;
+	int i;
+
+
+	p = shaproc(gtk_entry_get_text(GTK_ENTRY(passphrase)));
+	for (i = 0; i < (int)gtk_spin_button_get_value(spin_int); i++) {
+		q = strdup(p);
+		if (q == NULL) 
+			exit(1);
+		p = shaproc(q);
+		free(q);
+	}
+
+	snprintf(output, 199, "%s", p);
+
+	gtk_entry_set_text(GTK_ENTRY(result), output);
+	gtk_widget_show_all(window);
+}
+
+char *
+shaproc(char *input)
+{
+	SHA256_CTX ctx;
+	char shabuf[32];
+	static char buf[512];
+	int len;
+
+	SHA256_Init(&ctx);
+
+	SHA256_Update(&ctx, input, strlen(input));
+	
+	SHA256_Final((u_char *)&shabuf, &ctx);
+
+	len = b64_ntop(shabuf, sizeof(shabuf), buf, sizeof(buf));
+	
+	buf[len] = '\0';
+
+	return ((char *)&buf);
+}