#ifdef unix /* Assume POSIX */
#if (defined(__MSDOS__) || defined(MPU8086) || defined(MPU8080) \
|| defined(vax) || defined (MIPSEL))
#define LITTLE_ENDIAN /* Low order bytes are first in memory */
#endif /* Almost all other machines are big-endian */
* concatenate the seed and the password, run through MD4 and
* collapse to 64 bits. This is defined as the user's starting key.
keycrunch(result
,seed
,passwd
)
char *result
; /* 8-byte result */
char *seed
; /* Seed, any length */
char *passwd
; /* Password, any length */
buflen
= strlen(seed
) + strlen(passwd
);
if((buf
= malloc(buflen
+1)) == NULL
)
/* Crunch the key through MD4 */
MDupdate(&md
,(unsigned char *)buf
,8*buflen
);
/* Fold result from 128 to 64 bits */
md
.buffer
[0] ^= md
.buffer
[2];
md
.buffer
[1] ^= md
.buffer
[3];
/* Only works on byte-addressed little-endian machines!! */
memcpy(result
,(char *)md
.buffer
,8);
/* Default (but slow) code that will convert to
* little-endian byte ordering on any machine
/* The one-way function f(). Takes 8 bytes and returns 8 bytes in place */
MDupdate(&md
,(unsigned char *)x
,64);
/* Fold 128 to 64 bits */
md
.buffer
[0] ^= md
.buffer
[2];
md
.buffer
[1] ^= md
.buffer
[3];
/* Only works on byte-addressed little-endian machines!! */
memcpy(x
,(char *)md
.buffer
,8);
/* Default (but slow) code that will convert to
* little-endian byte ordering on any machine
/* Strip trailing cr/lf from a line of text */
if((cp
= strchr(buf
,'\r')) != NULL
)
if((cp
= strchr(buf
,'\n')) != NULL
)
/************************/
for(cp
=buf
,i
= 0; i
< n
; i
++)
if ((*cp
++ = bdos(7,0,0)) == '\r')
struct termios saved_ttymode
;
struct termios noecho_ttymode
;
/* Save normal line editing modes */
tcgetattr(0, &saved_ttymode
);
tcgetattr(0, &noecho_ttymode
);
noecho_ttymode
.c_lflag
&= ~ECHO
;
tcsetattr(0, TCSANOW
, &noecho_ttymode
);
/* Restore previous tty modes */
tcsetattr(0, TCSANOW
, &saved_ttymode
);
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
/* removebackspaced over charaters from the string*/
/* make sure there are only 7 bit code in the line*/