1 /* $FreeBSD: src/lib/libskey/skeysubr.c,v 1.9.6.1 2000/07/20 20:13:42 obrien Exp $ */
15 * concatenate the seed and the password, run through MDX and
16 * collapse to 64 bits. This is defined as the user's starting key.
19 keycrunch(result,seed,passwd)
20 char *result; /* 8-byte result */
21 const char *seed; /* Seed, any length */
22 const char *passwd; /* Password, any length */
29 buflen = strlen(seed) + strlen(passwd);
30 if((buf = malloc(buflen+1)) == NULL)
35 /* Crunch the key through MD[45] */
38 MDXUpdate(&md,(unsigned char *)buf,buflen);
39 MDXFinal((unsigned char *)results,&md);
42 results[0] ^= results[2];
43 results[1] ^= results[3];
45 memcpy(result,(char *)results,8);
50 /* The one-way function f(). Takes 8 bytes and returns 8 bytes in place */
59 MDXUpdate(&md,(unsigned char *)x,8);
60 MDXFinal((unsigned char *)results,&md);
61 /* Fold 128 to 64 bits */
62 results[0] ^= results[2];
63 results[1] ^= results[3];
65 memcpy(x,(char *)results,8);
68 /* Strip trailing cr/lf from a line of text */
73 buf[strcspn(buf, "\r\n")] = 0;
76 static struct termios saved_ttymode;
78 static void interrupt __P((int));
80 static void interrupt(sig)
83 tcsetattr(0, TCSANOW, &saved_ttymode);
84 err(1, "interrupted by signal %s", sys_siglist[sig]);
92 struct termios noecho_ttymode;
93 void (*oldsig) __P((int));
95 /* Save normal line editing modes */
96 tcgetattr(0, &saved_ttymode);
97 if ((oldsig = signal(SIGINT, SIG_IGN)) != SIG_IGN)
98 signal(SIGINT, interrupt);
100 /* Turn off echoing */
101 tcgetattr(0, &noecho_ttymode);
102 noecho_ttymode.c_lflag &= ~ECHO;
103 tcsetattr(0, TCSANOW, &noecho_ttymode);
107 /* Restore previous tty modes */
108 tcsetattr(0, TCSANOW, &saved_ttymode);
109 if (oldsig != SIG_IGN)
110 signal(SIGINT, oldsig);
113 after the secret key is taken from the keyboard, the line feed is
114 written to standard error instead of standard output. That means that
115 anyone using the program from a terminal won't notice, but capturing
116 standard output will get the key words without a newline in front of
119 fprintf(stderr, "\n");
130 /* make sure there are only 7 bit code in the line*/