1999-02-02 15:34:56 +03:00
|
|
|
/* $NetBSD: skey.c,v 1.8 1999/02/02 12:36:09 christos Exp $ */
|
1996-09-19 23:39:36 +04:00
|
|
|
|
1994-05-24 10:47:42 +04:00
|
|
|
/*
|
|
|
|
* S/KEY v1.1b (skey.c)
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Neil M. Haller <nmh@thumper.bellcore.com>
|
|
|
|
* Philip R. Karn <karn@chicago.qualcomm.com>
|
|
|
|
* John S. Walden <jsw@thumper.bellcore.com>
|
|
|
|
* Scott Chasin <chasin@crimelab.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Stand-alone program for computing responses to S/Key challenges.
|
|
|
|
* Takes the iteration count and seed as command line args, prompts
|
|
|
|
* for the user's key, and produces both word and hex format responses.
|
|
|
|
*
|
|
|
|
* Usage example:
|
|
|
|
* >skey 88 ka9q2
|
|
|
|
* Enter password:
|
|
|
|
* OMEN US HORN OMIT BACK AHOY
|
|
|
|
* >
|
|
|
|
*/
|
|
|
|
|
1997-10-20 03:20:15 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
1999-02-02 15:34:56 +03:00
|
|
|
__RCSID("$NetBSD: skey.c,v 1.8 1999/02/02 12:36:09 christos Exp $");
|
1997-10-20 03:20:15 +04:00
|
|
|
#endif
|
|
|
|
|
1995-06-05 23:55:40 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-24 10:47:42 +04:00
|
|
|
#include <fcntl.h>
|
1998-02-03 07:08:01 +03:00
|
|
|
#include <stdio.h>
|
1997-06-22 22:51:47 +04:00
|
|
|
#include <skey.h>
|
1998-02-03 07:08:01 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
1994-05-24 10:47:42 +04:00
|
|
|
|
1997-10-20 03:20:15 +04:00
|
|
|
int main __P((int, char **));
|
1995-06-05 23:55:40 +04:00
|
|
|
void usage __P((char *));
|
1994-05-24 10:47:42 +04:00
|
|
|
|
1995-06-05 23:55:40 +04:00
|
|
|
int
|
1994-05-24 10:47:42 +04:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
int n, cnt, i, pass = 0;
|
|
|
|
char passwd[256], key[8], buf[33], *seed, *slash;
|
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
|
|
|
|
|
|
|
cnt = 1;
|
|
|
|
|
1997-10-20 03:20:15 +04:00
|
|
|
while ((i = getopt(argc, argv, "n:p:")) != -1) {
|
1994-05-24 10:47:42 +04:00
|
|
|
switch (i) {
|
|
|
|
case 'n':
|
|
|
|
cnt = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
strcpy(passwd, optarg);
|
|
|
|
pass = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* could be in the form <number>/<seed> */
|
|
|
|
|
|
|
|
if (argc <= optind + 1) {
|
|
|
|
/* look for / in it */
|
1994-12-29 02:17:52 +03:00
|
|
|
if (argc <= optind)
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
slash = strchr(argv[optind], '/');
|
1994-12-29 02:17:52 +03:00
|
|
|
if (slash == NULL)
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
*slash++ = '\0';
|
|
|
|
seed = slash;
|
|
|
|
|
|
|
|
if ((n = atoi(argv[optind])) < 0) {
|
1994-12-29 02:17:52 +03:00
|
|
|
fprintf(stderr, "%s not positive\n", argv[optind]);
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ((n = atoi(argv[optind])) < 0) {
|
1994-12-29 02:17:52 +03:00
|
|
|
fprintf(stderr, "%s not positive\n", argv[optind]);
|
1994-05-24 10:47:42 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
}
|
|
|
|
seed = argv[++optind];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get user's secret password */
|
|
|
|
if (!pass) {
|
1994-12-29 02:17:52 +03:00
|
|
|
fprintf(stderr, "Enter secret password: ");
|
1994-05-24 10:47:42 +04:00
|
|
|
readpass(passwd, sizeof(passwd));
|
|
|
|
}
|
|
|
|
rip(passwd);
|
|
|
|
|
|
|
|
/* Crunch seed and password into starting key */
|
|
|
|
if (keycrunch(key, seed, passwd) != 0) {
|
|
|
|
fprintf(stderr, "%s: key crunch failed\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (cnt == 1) {
|
|
|
|
while (n-- != 0)
|
|
|
|
f(key);
|
|
|
|
printf("%s\n", btoe(buf, key));
|
|
|
|
#ifdef HEXIN
|
|
|
|
printf("%s\n", put8(buf, key));
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
for (i = 0; i <= n - cnt; i++)
|
|
|
|
f(key);
|
|
|
|
for (; i <= n; i++) {
|
|
|
|
#ifdef HEXIN
|
|
|
|
printf("%d: %-29s %s\n", i, btoe(buf, key), put8(buf, key));
|
|
|
|
#else
|
|
|
|
printf("%d: %-29s\n", i, btoe(buf, key));
|
|
|
|
#endif
|
|
|
|
f(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage(s)
|
|
|
|
char *s;
|
|
|
|
{
|
1994-12-29 02:17:52 +03:00
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: %s [-n count] [-p password ] sequence# [/] key\n", s);
|
|
|
|
exit(1);
|
1994-05-24 10:47:42 +04:00
|
|
|
}
|