get rid of some horrible assumptions

This commit is contained in:
deraadt 1994-05-24 06:25:27 +00:00
parent 9400c4fae6
commit 8f7e2d213d

View File

@ -10,70 +10,22 @@
*
* S/KEY misc routines.
*
* $Id: skeysubr.c,v 1.1 1994/05/21 05:46:19 deraadt Exp $
* $Id: skeysubr.c,v 1.2 1994/05/24 06:25:27 deraadt Exp $
*/
#include <stdio.h>
#ifdef HAS_STD_LIB
#include <stdlib.h>
#else
#include <sys/types.h>
#endif
#include <string.h>
#include <signal.h>
#ifdef __MSDOS__
#include <dos.h>
#endif
#ifdef stty
# undef stty
#endif
#ifdef gtty
# undef gtty
#endif
#ifndef SYSV
# include <sgtty.h>
# define TTYSTRUCT sgttyb
#ifndef __NetBSD__
# define stty(fd,buf) ioctl((fd),TIOCSETN,(buf))
# define gtty(fd,buf) ioctl((fd),TIOCGETP,(buf))
#endif
#else
# include <termio.h>
# define TTYSTRUCT termio
# define stty(fd,buf) ioctl((fd),TCSETA,(buf))
# define gtty(fd,buf) ioctl((fd),TCGETA,(buf))
#endif
#ifdef SYSV
struct termio newtty;
struct termio oldtty;
#else
struct sgttyb newtty;
struct sgttyb oldtty;
struct tchars chars;
#endif
#ifdef SIGVOID
#define SIGTYPE void
#else
#define SIGTYPE void
#endif
SIGTYPE trapped();
#include <sys/termios.h>
#include "md4.h"
#include "skey.h"
#if (defined(__MSDOS__) || defined(MPU8086) || defined(MPU8080) \
|| defined(vax) || defined (MIPSEL))
#define LITTLE_ENDIAN
#endif
struct termios newtty;
struct termios oldtty;
void trapped();
/* Crunch a key:
* concatenate the seed and the password, run through MD4 and
@ -88,10 +40,8 @@ char *passwd; /* Password, any length */
char *buf;
MDstruct md;
unsigned int buflen;
#ifndef LITTLE_ENDIAN
int i;
register long tmp;
#endif
buflen = strlen(seed) + strlen(passwd);
if ((buf = (char *)malloc(buflen+1)) == NULL)
@ -110,10 +60,6 @@ char *passwd; /* Password, any length */
md.buffer[0] ^= md.buffer[2];
md.buffer[1] ^= md.buffer[3];
#ifdef LITTLE_ENDIAN
/* Only works on byte-addressed little-endian machines!! */
memcpy(result,(char *)md.buffer,8);
#else
/* Default (but slow) code that will convert to
* little-endian byte ordering on any machine
*/
@ -127,7 +73,6 @@ char *passwd; /* Password, any length */
tmp >>= 8;
*result++ = tmp;
}
#endif
return 0;
}
@ -137,9 +82,7 @@ void f (x)
char *x;
{
MDstruct md;
#ifndef LITTLE_ENDIAN
register long tmp;
#endif
MDbegin(&md);
MDupdate(&md,(unsigned char *)x,64);
@ -148,11 +91,6 @@ char *x;
md.buffer[0] ^= md.buffer[2];
md.buffer[1] ^= md.buffer[3];
#ifdef LITTLE_ENDIAN
/* Only works on byte-addressed little-endian machines!! */
memcpy(x,(char *)md.buffer,8);
#else
/* Default (but slow) code that will convert to
* little-endian byte ordering on any machine
*/
@ -173,7 +111,6 @@ char *x;
*x++ = tmp;
tmp >>= 8;
*x = tmp;
#endif
}
/* Strip trailing cr/lf from a line of text */
@ -189,85 +126,46 @@ char *buf;
*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';
putchar('\n');
rip(buf);
return buf;
}
#else
char *readpass (buf,n)
char *buf;
int n;
{
#ifndef USE_ECHO
set_term ();
echo_off ();
#endif
fgets (buf, n, stdin);
rip (buf);
printf ("\n");
printf ("\n\n");
sevenbit (buf);
#ifndef USE_ECHO
unset_term ();
#endif
return buf;
}
set_term ()
{
gtty (fileno(stdin), &newtty);
gtty (fileno(stdin), &oldtty);
fflush(stdout);
tcgetattr(fileno(stdin), &newtty);
tcgetattr(fileno(stdin), &oldtty);
signal (SIGINT, trapped);
}
echo_off ()
{
#ifdef SYSV
newtty.c_lflag &= ~(ICANON | ECHO | ECHONL);
#else
newtty.sg_flags |= CBREAK;
newtty.sg_flags &= ~ECHO;
#endif
#ifdef SYSV
newtty.c_cc[VMIN] = 1;
newtty.c_cc[VTIME] = 0;
newtty.c_cc[VINTR] = 3;
#else
ioctl(fileno(stdin), TIOCGETC, &chars);
chars.t_intrc = 3;
ioctl(fileno(stdin), TIOCSETC, &chars);
#endif
stty (fileno (stdin), &newtty);
tcsetattr(fileno(stdin), TCSADRAIN, &newtty);
}
unset_term ()
{
stty (fileno (stdin), &oldtty);
#ifndef SYSV
ioctl(fileno(stdin), TIOCSETC, &chars);
#endif
tcsetattr(fileno(stdin), TCSADRAIN, &oldtty);
}
void trapped()
@ -278,8 +176,6 @@ void trapped()
exit (-1);
}
#endif
/* removebackspaced over charaters from the string */
backspace(buf)
char *buf;