1994-05-19 20:13:11 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
#include <dos.h>
|
|
|
|
#endif
|
1994-10-19 01:03:45 +01:00
|
|
|
#ifdef unix
|
1994-05-19 20:13:11 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <termios.h>
|
1994-10-19 01:03:45 +01:00
|
|
|
#include <signal.h>
|
1994-05-19 20:13:11 +02:00
|
|
|
#endif
|
1994-10-19 01:03:45 +01:00
|
|
|
|
|
|
|
#include "skey.h"
|
|
|
|
#include "mdx.h"
|
1994-05-19 20:13:11 +02:00
|
|
|
|
|
|
|
/* Crunch a key:
|
|
|
|
* concatenate the seed and the password, run through MD4 and
|
|
|
|
* collapse to 64 bits. This is defined as the user's starting key.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
keycrunch(result,seed,passwd)
|
1994-10-19 01:03:45 +01:00
|
|
|
char *result; /* 8-byte result */
|
|
|
|
char *seed; /* Seed, any length */
|
|
|
|
char *passwd; /* Password, any length */
|
1994-05-19 20:13:11 +02:00
|
|
|
{
|
|
|
|
char *buf;
|
1994-10-19 01:03:45 +01:00
|
|
|
MDX_CTX md;
|
|
|
|
u_long results[4];
|
1994-05-19 20:13:11 +02:00
|
|
|
unsigned int buflen;
|
|
|
|
|
|
|
|
buflen = strlen(seed) + strlen(passwd);
|
|
|
|
if((buf = malloc(buflen+1)) == NULL)
|
|
|
|
return -1;
|
|
|
|
strcpy(buf,seed);
|
|
|
|
strcat(buf,passwd);
|
|
|
|
|
1994-10-19 01:03:45 +01:00
|
|
|
/* Crunch the key through MD[45] */
|
1994-05-19 20:13:11 +02:00
|
|
|
sevenbit(buf);
|
1994-10-19 01:03:45 +01:00
|
|
|
MDXInit(&md);
|
|
|
|
MDXUpdate(&md,(unsigned char *)buf,buflen);
|
|
|
|
MDXFinal((unsigned char *)results,&md);
|
1994-05-19 20:13:11 +02:00
|
|
|
free(buf);
|
|
|
|
|
1994-10-19 01:03:45 +01:00
|
|
|
results[0] ^= results[2];
|
|
|
|
results[1] ^= results[3];
|
1994-05-19 20:13:11 +02:00
|
|
|
|
1994-10-19 01:03:45 +01:00
|
|
|
memcpy(result,(char *)results,8);
|
1994-05-19 20:13:11 +02: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 01:03:45 +01:00
|
|
|
MDX_CTX md;
|
|
|
|
u_long results[4];
|
1994-05-19 20:13:11 +02:00
|
|
|
|
1994-10-19 01:03:45 +01:00
|
|
|
MDXInit(&md);
|
|
|
|
MDXUpdate(&md,(unsigned char *)x,8);
|
|
|
|
MDXFinal((unsigned char *)results,&md);
|
1994-05-19 20:13:11 +02:00
|
|
|
/* Fold 128 to 64 bits */
|
1994-10-19 01:03:45 +01:00
|
|
|
results[0] ^= results[2];
|
|
|
|
results[1] ^= results[3];
|
1994-05-19 20:13:11 +02:00
|
|
|
|
|
|
|
/* Only works on byte-addressed little-endian machines!! */
|
1994-10-19 01:03:45 +01:00
|
|
|
memcpy(x,(char *)results,8);
|
1994-05-19 20:13:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Strip trailing cr/lf from a line of text */
|
|
|
|
void
|
|
|
|
rip(buf)
|
|
|
|
char *buf;
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if((cp = strchr(buf,'\r')) != NULL)
|
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
if((cp = strchr(buf,'\n')) != NULL)
|
|
|
|
*cp = '\0';
|
|
|
|
}
|
|
|
|
/************************/
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
char *
|
|
|
|
readpass(buf,n)
|
|
|
|
char *buf;
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
for(cp=buf,i = 0; i < n ; i++)
|
|
|
|
if ((*cp++ = bdos(7,0,0)) == '\r')
|
|
|
|
break;
|
|
|
|
*cp = '\0';
|
|
|
|
printf("\n");
|
|
|
|
rip(buf);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
#else
|
1994-10-19 01:03:45 +01:00
|
|
|
static struct termios saved_ttymode;
|
|
|
|
|
|
|
|
static void interrupt()
|
|
|
|
{
|
|
|
|
tcsetattr(0, TCSANOW, &saved_ttymode);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1994-05-19 20:13:11 +02:00
|
|
|
char *
|
|
|
|
readpass(buf,n)
|
|
|
|
char *buf;
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
struct termios noecho_ttymode;
|
1994-10-19 01:03:45 +01:00
|
|
|
void (*oldsig)();
|
1994-05-19 20:13:11 +02:00
|
|
|
|
|
|
|
/* Save normal line editing modes */
|
|
|
|
tcgetattr(0, &saved_ttymode);
|
1994-10-19 01:03:45 +01:00
|
|
|
if ((oldsig = signal(SIGINT, SIG_IGN)) != SIG_IGN)
|
|
|
|
signal(SIGINT, interrupt);
|
1994-05-19 20:13:11 +02: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 01:03:45 +01:00
|
|
|
if (oldsig != SIG_IGN)
|
|
|
|
signal(SIGINT, oldsig);
|
1994-05-19 20:13:11 +02: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
|
|
|
|
them.
|
|
|
|
*/
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
sevenbit(buf);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sevenbit(s)
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
/* make sure there are only 7 bit code in the line*/
|
|
|
|
while(*s){
|
|
|
|
*s = 0x7f & ( *s);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|