From 4066382ce5f76ca4c35356972387e30c65911697 Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Thu, 1 Jun 2023 10:53:25 -0400 Subject: [PATCH] init --- Makefile | 10 +++++ README | 26 ++++++++++++ config.mk | 5 +++ src/config.h | 11 ++++++ src/ecrypt.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 config.mk create mode 100644 src/config.h create mode 100644 src/ecrypt.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f5271da --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +include config.mk + +all: + $(CC) src/ecrypt.c $(CFLAGS) $(LDFLAGS) -lecrypt -o src/ecrypt + +install: + install src/ecrypt $(PREFIX)/bin + +clean: + rm src/ecrypt diff --git a/README b/README new file mode 100644 index 0000000..e818358 --- /dev/null +++ b/README @@ -0,0 +1,26 @@ ++ ecrypt - a simple password and key generator + +ecrypt is an extremely simple and basic encryption tool. It does not aim to provide +advanced encryption features that tools such as OpenSSL may offer, it simply acts as +a random string generator and comparison tool. + ++ Dependencies + + - libecrypt 2.2.0 + ++ Installation + +Clone this repository: + (user)$ git clone https://git.everestlinux.org/EverestLinux/ecrypt + +Review src/config.h: + (user)$ $EDITOR src/config.h + +Review config.mk: + (user)$ $EDITOR config.mk + +Run make: + (user)$ make + +Install: + (root)# make install diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..0fffc4a --- /dev/null +++ b/config.mk @@ -0,0 +1,5 @@ +# config.mk + +CC = cc +CFLAGS = -O3 -fstack-protector-strong -static -pie +LDFLAGS = diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..fc4952a --- /dev/null +++ b/src/config.h @@ -0,0 +1,11 @@ +/* config.h - define configuration values */ + +#ifndef CONFIG_H_ +#define CONFIG_H_ + +/* Length of string to be outputted */ +#define ECRYPT_STR_LEN 30 + +#define ECRYPT_VERSION "3.0.0" + +#endif diff --git a/src/ecrypt.c b/src/ecrypt.c new file mode 100644 index 0000000..0bf49fe --- /dev/null +++ b/src/ecrypt.c @@ -0,0 +1,110 @@ +/* + ecrypt.c - string generation and comparison tool + + This file is part of ecrypt. + + ecrypt is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + ecrypt is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with ecrypt. If not, see . +*/ + +#include +#include +#include +#include +#include +#include + +#include "config.h" + +static void +usage(char *argv[]) +{ + printf("%s - string generator and checker\n", argv[0]); + printf("usage: %s [-h] [-v] [-s] [-g] [-c]\n", argv[0]); + printf("\n"); + printf("%s {-h} Show this message\n", argv[0]); + printf("%s {-v} Show the current version\n", argv[0]); + printf("%s {-s} View compile-time settings\n", argv[0]); + printf("%s {-g} Generate a string\n", argv[0]); + printf("%s {-c} Compare 2 files\n", argv[0]); + printf("\n"); + printf("Ecrypt is free software.\n"); + printf("See the GNU GPL version 3 for details.\n"); +} + +static void +usage_small(char *argv[]) +{ + printf("usage: %s [-h] [-v] [-s] [-g] [-c]\n", argv[0]); +} + +static void +view_compile_time_settings(char *argv[]) +{ + printf("Compile-time settings for %s\n", argv[0]); + printf("String length: %i\n", ECRYPT_STR_LEN); +} + +static void +view_version(char *argv[]) +{ + printf("%s\n", argv[0]); + printf(ECRYPT_VERSION); + printf("\n"); + printf("Compiled against libecrypt\n"); +} + +int +main(int argc, char *argv[]) +{ + + if (argc < 2) { + usage_small(argv); + exit(1); + } + + int opt; + + while ((opt = getopt(argc, argv, ":if:hvsgc")) != -1) { + switch(opt) { + case 'h': + usage(argv); + exit(0); + break; + case 'v': + view_version(argv); + exit(0); + break; + case 's': + view_compile_time_settings(argv); + exit(0); + break; + case 'g': + ecrypt_gen(ECRYPT_STR_LEN); + printf("\n"); + exit(0); + break; + case 'c': + if (argc < 4) { + printf("not enough arguments\n"); + exit(1); + } + ecrypt_check(argv[2], argv[3]); + break; + case '?': + usage_small(argv); + exit(1); + break; + } + } +}