summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.bin/enigma/Makefile12
-rw-r--r--usr.bin/enigma/enigma.1115
-rw-r--r--usr.bin/enigma/enigma.c62
3 files changed, 156 insertions, 33 deletions
diff --git a/usr.bin/enigma/Makefile b/usr.bin/enigma/Makefile
index 7d54eb8..4044708 100644
--- a/usr.bin/enigma/Makefile
+++ b/usr.bin/enigma/Makefile
@@ -1,9 +1,7 @@
-all: enigma makekey
+PROG= enigma
+MAN1= enigma.1
-install: enigma makekey
- cp enigma makekey /usr/brlcad/bin/.
- cp makekey.8 /usr/brlcad/man/man1/.
- ln -s enigma /usr/brlcad/bin/crypt
+LINKS= ${BINDIR}/enigma ${BINDIR}/crypt
+MLINKS= enigma.1 crypt.1
-clean:
- rm -f enigma makekey *.o
+.include <bsd.prog.mk>
diff --git a/usr.bin/enigma/enigma.1 b/usr.bin/enigma/enigma.1
new file mode 100644
index 0000000..a8d05f3
--- /dev/null
+++ b/usr.bin/enigma/enigma.1
@@ -0,0 +1,115 @@
+.\"
+.\" enigma (aka. crypt) man page written by Joerg Wunsch.
+.\"
+.\" Since enigma itself is distributed in the Public Domain, this file
+.\" is also.
+.\"
+.\" $Id$
+.\" "
+.Dd October 30, 1998
+.Os
+.Dt enigma 1
+.Sh NAME
+.Nm enigma
+.Nd very simple file encryption
+.Sh SYNOPSIS
+.Nm
+.Op Fl s
+.Op Fl k
+.Op Ar password
+.Nm crypt
+.Op Fl s
+.Op Fl k
+.Op Ar password
+.Sh DESCRIPTION
+.Nm Enigma ,
+also known as
+.Nm crypt
+is a
+.Em very
+simple encryption program, working on a
+.Dq secret-key
+basis. It operates as a filter, i. e. it encrypts or decrypts a
+stream of data from standard input, and writes the result to standard
+output. It automatically detects whether the input data stream is
+already encrypted, and switches into decryption mode in this case.
+.Pp
+There are several ways to provide the secret key to the program. By
+default, the program prompts the user on the controlling terminal for
+the key, using
+.Xr getpass 3 .
+This is the only safe way of providing it.
+.Pp
+Alternatively, the key can be provided as the sole command-line
+argument
+.Ar password
+when starting the program. Obviously, this way the key can easily be
+spotted by other users running
+.Xr ps 1 .
+As yet another alternative,
+.Nm
+can be given the option
+.Fl k ,
+and it will take the key from the environment variable
+.Ev CrYpTkEy .
+While this at a first glance seems to be more secure than the previous
+option, it actually isn't since environment variables can also be
+examined with
+.Xr ps 1 .
+Thus this option is mainly provided for compatibility with other
+implementations of
+.Nm enigma .
+.Pp
+When specifying the option
+.Fl s ,
+.Nm
+modifies the encryption engine in a way that is supposed to make it a
+little more secure, but incompatible with other implementations.
+.Pp
+.Ss Warning
+The cryptographic value of
+.Nm
+is rather small. This program is only provided here for compatibility
+with other operating systems that also provide an implementation. For
+real encryption, refer to
+.Xr bdes 1
+(from the DES distribution package), or
+.Xr pgp 1
+(from the ports collection). Hoewever, restrictions for exporting,
+importing or using such tools might exist in some countries, so those
+stronger programs are not being shipped as part of the operating
+system by default.
+.Sh ENVIRONMENT
+.Bl -tag -offset indent -width "XXCrYpTkEy"
+.It Ev CrYpTkEy
+used to obtain the secret key when option
+.Fl k
+has been given
+.El
+.Sh EXAMPLES
+.Bd -literal -offset indent
+man enigma | enigma > encrypted
+Enter key: (XXX \(em key not echoed)
+.Ed
+.Pp
+This will create an encrypted form of this man page, and store it in
+the file
+.Ql encrypted .
+.Bd -literal -offset indent
+enigma XXX < encrypted
+.Ed
+.Pp
+This displays the previously created file on the terminal.
+.Sh SEE ALSO
+.Xr bdes 1 ,
+.Xr pgp 1 ,
+.Xr ps 1 ,
+.Xr getpass 3
+.Sh HISTORY
+Implementations of
+.Nm crypt
+are very common among
+.Ux
+operating systems. This implementation has been taken from the
+.Em Cryptbreakers Workbench
+which is in the public domain.
diff --git a/usr.bin/enigma/enigma.c b/usr.bin/enigma/enigma.c
index 3808cc7..3b1560c 100644
--- a/usr.bin/enigma/enigma.c
+++ b/usr.bin/enigma/enigma.c
@@ -10,23 +10,30 @@
* Upgraded to function properly on 64-bit machines.
*/
-#define ECHO 010
+#include <sys/types.h>
+#include <sys/wait.h>
+
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define MINUSKVAR "CrYpTkEy"
+
+#define ECHO 010
#define ROTORSZ 256
#define MASK 0377
char t1[ROTORSZ];
char t2[ROTORSZ];
char t3[ROTORSZ];
char deck[ROTORSZ];
-char *getpass();
char buf[13];
-void shuffle();
-void puth();
+void shuffle(char *);
void
setup(pw)
-char *pw;
+ char *pw;
{
int ic, i, k, temp, pf[2], pid;
unsigned random;
@@ -97,18 +104,32 @@ char *pw;
t2[t1[i]&MASK] = i;
}
+int
main(argc, argv)
-char *argv[];
+ char *argv[];
{
register int i, n1, n2, nr1, nr2;
- int secureflg = 0;
+ int secureflg = 0, kflag = 0;
+ char *cp;
- if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 's') {
- argc--;
- argv++;
- secureflg = 1;
+ if (argc > 1 && argv[1][0] == '-') {
+ if (argv[1][1] == 's') {
+ argc--;
+ argv++;
+ secureflg = 1;
+ } else if (argv[1][1] == 'k') {
+ argc--;
+ argv++;
+ kflag = 1;
+ }
}
- if (argc != 2){
+ if (kflag) {
+ if ((cp = getenv(MINUSKVAR)) == NULL) {
+ fprintf(stderr, "%s not set\n", MINUSKVAR);
+ exit(1);
+ }
+ setup(cp);
+ } else if (argc != 2) {
setup(getpass("Enter key:"));
}
else
@@ -117,7 +138,7 @@ char *argv[];
n2 = 0;
nr2 = 0;
- while((i=getchar()) >=0) {
+ while((i=getchar()) != -1) {
if (secureflg) {
nr1 = deck[n1]&MASK;
nr2 = deck[nr1]&MASK;
@@ -138,6 +159,8 @@ char *argv[];
}
}
}
+
+ return 0;
}
void
@@ -158,16 +181,3 @@ shuffle(deck)
deck[ic] = temp;
}
}
-
-void
-puth( title, cp, len )
-char *title;
-char *cp;
-int len;
-{
- fprintf( stderr, "%s = ", title);
- while( len-- > 0 ) {
- fprintf(stderr, "%2.2x ", (*cp++) & 0xFF );
- }
- fprintf(stderr,"\n");
-}
OpenPOWER on IntegriCloud