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