1998-02-27 22:36:51 +00:00
|
|
|
#include <err.h>
|
1994-05-19 18:13:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <termios.h>
|
1994-10-19 00:03:45 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "skey.h"
|
|
|
|
#include "mdx.h"
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
/* Crunch a key:
|
1995-06-11 19:33:05 +00:00
|
|
|
* concatenate the seed and the password, run through MDX and
|
1994-05-19 18:13:11 +00:00
|
|
|
* collapse to 64 bits. This is defined as the user's starting key.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
keycrunch(result,seed,passwd)
|
1994-10-19 00:03:45 +00:00
|
|
|
char *result; /* 8-byte result */
|
1998-02-27 22:36:51 +00:00
|
|
|
const char *seed; /* Seed, any length */
|
|
|
|
const char *passwd; /* Password, any length */
|
1994-05-19 18:13:11 +00:00
|
|
|
{
|
|
|
|
char *buf;
|
1994-10-19 00:03:45 +00:00
|
|
|
MDX_CTX md;
|
|
|
|
u_long results[4];
|
1994-05-19 18:13:11 +00:00
|
|
|
unsigned int buflen;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1994-05-19 18:13:11 +00:00
|
|
|
buflen = strlen(seed) + strlen(passwd);
|
|
|
|
if((buf = malloc(buflen+1)) == NULL)
|
|
|
|
return -1;
|
|
|
|
strcpy(buf,seed);
|
|
|
|
strcat(buf,passwd);
|
|
|
|
|
1994-10-19 00:03:45 +00:00
|
|
|
/* Crunch the key through MD[45] */
|
1994-05-19 18:13:11 +00:00
|
|
|
sevenbit(buf);
|
1994-10-19 00:03:45 +00:00
|
|
|
MDXInit(&md);
|
|
|
|
MDXUpdate(&md,(unsigned char *)buf,buflen);
|
|
|
|
MDXFinal((unsigned char *)results,&md);
|
1994-05-19 18:13:11 +00:00
|
|
|
free(buf);
|
|
|
|
|
1994-10-19 00:03:45 +00:00
|
|
|
results[0] ^= results[2];
|
|
|
|
results[1] ^= results[3];
|
1994-05-19 18:13:11 +00:00
|
|
|
|
1994-10-19 00:03:45 +00:00
|
|
|
memcpy(result,(char *)results,8);
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The one-way function f(). Takes 8 bytes and returns 8 bytes in place */
|
|
|
|
void
|
|
|
|
f(x)
|
|
|
|
char *x;
|
|
|
|
{
|
1994-10-19 00:03:45 +00:00
|
|
|
MDX_CTX md;
|
|
|
|
u_long results[4];
|
1994-05-19 18:13:11 +00:00
|
|
|
|
1994-10-19 00:03:45 +00:00
|
|
|
MDXInit(&md);
|
|
|
|
MDXUpdate(&md,(unsigned char *)x,8);
|
|
|
|
MDXFinal((unsigned char *)results,&md);
|
1994-05-19 18:13:11 +00:00
|
|
|
/* Fold 128 to 64 bits */
|
1994-10-19 00:03:45 +00:00
|
|
|
results[0] ^= results[2];
|
|
|
|
results[1] ^= results[3];
|
1994-05-19 18:13:11 +00:00
|
|
|
|
1994-10-19 00:03:45 +00:00
|
|
|
memcpy(x,(char *)results,8);
|
1994-05-19 18:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Strip trailing cr/lf from a line of text */
|
|
|
|
void
|
|
|
|
rip(buf)
|
|
|
|
char *buf;
|
|
|
|
{
|
1995-06-11 19:33:05 +00:00
|
|
|
buf[strcspn(buf, "\r\n")] = 0;
|
1994-05-19 18:13:11 +00:00
|
|
|
}
|
1995-06-11 19:33:05 +00:00
|
|
|
|
1994-10-19 00:03:45 +00:00
|
|
|
static struct termios saved_ttymode;
|
|
|
|
|
1998-10-26 11:54:36 +00:00
|
|
|
static void interrupt __P((int));
|
|
|
|
|
1995-06-11 19:33:05 +00:00
|
|
|
static void interrupt(sig)
|
|
|
|
int sig;
|
1994-10-19 00:03:45 +00:00
|
|
|
{
|
|
|
|
tcsetattr(0, TCSANOW, &saved_ttymode);
|
1998-02-27 22:36:51 +00:00
|
|
|
err(1, "interrupted by signal %s", sys_siglist[sig]);
|
1994-10-19 00:03:45 +00:00
|
|
|
}
|
|
|
|
|
1994-05-19 18:13:11 +00:00
|
|
|
char *
|
|
|
|
readpass(buf,n)
|
|
|
|
char *buf;
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
struct termios noecho_ttymode;
|
1998-10-26 11:54:36 +00:00
|
|
|
void (*oldsig) __P((int));
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
/* Save normal line editing modes */
|
|
|
|
tcgetattr(0, &saved_ttymode);
|
1994-10-19 00:03:45 +00:00
|
|
|
if ((oldsig = signal(SIGINT, SIG_IGN)) != SIG_IGN)
|
|
|
|
signal(SIGINT, interrupt);
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
/* Turn off echoing */
|
|
|
|
tcgetattr(0, &noecho_ttymode);
|
|
|
|
noecho_ttymode.c_lflag &= ~ECHO;
|
|
|
|
tcsetattr(0, TCSANOW, &noecho_ttymode);
|
|
|
|
fgets(buf,n,stdin);
|
|
|
|
rip(buf);
|
|
|
|
|
|
|
|
/* Restore previous tty modes */
|
|
|
|
tcsetattr(0, TCSANOW, &saved_ttymode);
|
1994-10-19 00:03:45 +00:00
|
|
|
if (oldsig != SIG_IGN)
|
|
|
|
signal(SIGINT, oldsig);
|
1994-05-19 18:13:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
after the secret key is taken from the keyboard, the line feed is
|
|
|
|
written to standard error instead of standard output. That means that
|
|
|
|
anyone using the program from a terminal won't notice, but capturing
|
|
|
|
standard output will get the key words without a newline in front of
|
1995-05-30 05:51:47 +00:00
|
|
|
them.
|
1994-05-19 18:13:11 +00:00
|
|
|
*/
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
sevenbit(buf);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
1996-07-12 18:57:58 +00:00
|
|
|
void
|
1994-05-19 18:13:11 +00:00
|
|
|
sevenbit(s)
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
/* make sure there are only 7 bit code in the line*/
|
|
|
|
while(*s){
|
1995-06-11 19:33:05 +00:00
|
|
|
*s &= 0x7f;
|
1994-05-19 18:13:11 +00:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|