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.4 2008/09/30 16:57:06 swildner 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.
19 * result 8-byte result
20 * seed Seed, any length
21 * passwd Password, any length
24 keycrunch(char *result
, const char *seed
, const char *passwd
)
31 buflen
= strlen(seed
) + strlen(passwd
);
32 if((buf
= malloc(buflen
+1)) == NULL
)
37 /* Crunch the key through MD[45] */
40 MDXUpdate(&md
,(unsigned char *)buf
,buflen
);
41 MDXFinal((unsigned char *)results
,&md
);
44 results
[0] ^= results
[2];
45 results
[1] ^= results
[3];
47 memcpy(result
,(char *)results
,8);
52 /* 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 */
73 buf
[strcspn(buf
, "\r\n")] = 0;
76 static struct termios saved_ttymode
;
78 static void interrupt (int);
83 tcsetattr(0, TCSANOW
, &saved_ttymode
);
84 err(1, "interrupted by signal %s", sys_siglist
[sig
]);
88 readpass(char *buf
, int n
)
90 struct termios noecho_ttymode
;
93 /* Save normal line editing modes */
94 tcgetattr(0, &saved_ttymode
);
95 if ((oldsig
= signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
96 signal(SIGINT
, interrupt
);
98 /* Turn off echoing */
99 tcgetattr(0, &noecho_ttymode
);
100 noecho_ttymode
.c_lflag
&= ~ECHO
;
101 tcsetattr(0, TCSANOW
, &noecho_ttymode
);
105 /* Restore previous tty modes */
106 tcsetattr(0, TCSANOW
, &saved_ttymode
);
107 if (oldsig
!= SIG_IGN
)
108 signal(SIGINT
, oldsig
);
111 after the secret key is taken from the keyboard, the line feed is
112 written to standard error instead of standard output. That means that
113 anyone using the program from a terminal won't notice, but capturing
114 standard output will get the key words without a newline in front of
117 fprintf(stderr
, "\n");
127 /* make sure there are only 7 bit code in the line*/