Annotation of src/usr.bin/skey/skey.c, Revision 1.1.1.1
1.1 deraadt 1: /*
2: * S/KEY v1.1b (skey.c)
3: *
4: * Authors:
5: * Neil M. Haller <nmh@thumper.bellcore.com>
6: * Philip R. Karn <karn@chicago.qualcomm.com>
7: * John S. Walden <jsw@thumper.bellcore.com>
8: * Scott Chasin <chasin@crimelab.com>
9: *
10: *
11: * Stand-alone program for computing responses to S/Key challenges.
12: * Takes the iteration count and seed as command line args, prompts
13: * for the user's key, and produces both word and hex format responses.
14: *
15: * Usage example:
16: * >skey 88 ka9q2
17: * Enter password:
18: * OMEN US HORN OMIT BACK AHOY
19: * >
20: *
21: * $Id: skey.c,v 1.3 1995/06/05 19:55:40 pk Exp $
22: */
23:
24: #include <sys/cdefs.h>
25: #include <stdio.h>
26: #include <stdlib.h>
27: #include <string.h>
28: #include <fcntl.h>
29: #include <sgtty.h>
30: #include "md4.h"
31: #include "skey.h"
32:
33: void usage __P((char *));
34:
35: int
36: main(argc, argv)
37: int argc;
38: char *argv[];
39: {
40: int n, cnt, i, pass = 0;
41: char passwd[256], key[8], buf[33], *seed, *slash;
42: extern int optind;
43: extern char *optarg;
44:
45: cnt = 1;
46:
47: while ((i = getopt(argc, argv, "n:p:")) != EOF) {
48: switch (i) {
49: case 'n':
50: cnt = atoi(optarg);
51: break;
52: case 'p':
53: strcpy(passwd, optarg);
54: pass = 1;
55: break;
56: }
57: }
58:
59: /* could be in the form <number>/<seed> */
60:
61: if (argc <= optind + 1) {
62: /* look for / in it */
63: if (argc <= optind)
64: usage(argv[0]);
65: slash = strchr(argv[optind], '/');
66: if (slash == NULL)
67: usage(argv[0]);
68: *slash++ = '\0';
69: seed = slash;
70:
71: if ((n = atoi(argv[optind])) < 0) {
72: fprintf(stderr, "%s not positive\n", argv[optind]);
73: usage(argv[0]);
74: }
75: } else {
76:
77: if ((n = atoi(argv[optind])) < 0) {
78: fprintf(stderr, "%s not positive\n", argv[optind]);
79: usage(argv[0]);
80: }
81: seed = argv[++optind];
82: }
83:
84: /* Get user's secret password */
85: if (!pass) {
86: fprintf(stderr, "Enter secret password: ");
87: readpass(passwd, sizeof(passwd));
88: }
89: rip(passwd);
90:
91: /* Crunch seed and password into starting key */
92: if (keycrunch(key, seed, passwd) != 0) {
93: fprintf(stderr, "%s: key crunch failed\n", argv[0]);
94: exit(1);
95: }
96: if (cnt == 1) {
97: while (n-- != 0)
98: f(key);
99: printf("%s\n", btoe(buf, key));
100: #ifdef HEXIN
101: printf("%s\n", put8(buf, key));
102: #endif
103: } else {
104: for (i = 0; i <= n - cnt; i++)
105: f(key);
106: for (; i <= n; i++) {
107: #ifdef HEXIN
108: printf("%d: %-29s %s\n", i, btoe(buf, key), put8(buf, key));
109: #else
110: printf("%d: %-29s\n", i, btoe(buf, key));
111: #endif
112: f(key);
113: }
114: }
115: exit(0);
116: }
117:
118: void
119: usage(s)
120: char *s;
121: {
122:
123: fprintf(stderr,
124: "Usage: %s [-n count] [-p password ] sequence# [/] key\n", s);
125: exit(1);
126: }