Deleted Added
full compact
generator.c (27925) generator.c (29967)
1/* generator.c: The opiegenerator() library function.
2
1/* generator.c: The opiegenerator() library function.
2
3%%% portions-copyright-cmetz
4Portions of this software are Copyright 1996 by Craig Metz, All Rights
3%%% portions-copyright-cmetz-96
4Portions of this software are Copyright 1996-1997 by Craig Metz, All Rights
5Reserved. The Inner Net License Version 2 applies to these portions of
6the software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10 History:
11
5Reserved. The Inner Net License Version 2 applies to these portions of
6the software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10 History:
11
12 Modified by cmetz for OPIE 2.31. Renamed "init" to "init-hex".
13 Removed active attack protection support. Fixed fairly
14 bug in how init response was computed (i.e., dead wrong).
12 Modified by cmetz for OPIE 2.3. Use _opieparsechallenge(). ifdef
13 around string.h. Output hex responses by default, output
14 OTP re-init extended responses (same secret) if sequence
15 number falls below 10.
16 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
17 Bug fixes.
18 Created at NRL for OPIE 2.2.
19*/

--- 20 unchanged lines hidden (view full) ---

40 buffer += 4;
41
42 if (_opieparsechallenge(buffer, &algorithm, &sequence, &seed))
43 return 1;
44
45 if ((sequence < 2) || (sequence > 9999))
46 return 1;
47
15 Modified by cmetz for OPIE 2.3. Use _opieparsechallenge(). ifdef
16 around string.h. Output hex responses by default, output
17 OTP re-init extended responses (same secret) if sequence
18 number falls below 10.
19 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
20 Bug fixes.
21 Created at NRL for OPIE 2.2.
22*/

--- 20 unchanged lines hidden (view full) ---

43 buffer += 4;
44
45 if (_opieparsechallenge(buffer, &algorithm, &sequence, &seed))
46 return 1;
47
48 if ((sequence < 2) || (sequence > 9999))
49 return 1;
50
48 if (!secret[0])
49 return 2;
50
51 if (opiepasscheck(secret))
52 return -2;
53
54 if (i = opiekeycrunch(algorithm, key, seed, secret))
55 return i;
56
51 if (opiepasscheck(secret))
52 return -2;
53
54 if (i = opiekeycrunch(algorithm, key, seed, secret))
55 return i;
56
57
57 if (sequence < 10) {
58 char newseed[OPIE_SEED_MAX + 1];
58 if (sequence < 10) {
59 char newseed[OPIE_SEED_MAX + 1];
59 char newkey[8], cko[8], ckn[8], ckxor[8], cv[8];
60 char newkey[8];
60 char *c;
61 char buf[OPIE_SEED_MAX + 48 + 1];
62
61 char *c;
62 char buf[OPIE_SEED_MAX + 48 + 1];
63
64 while (sequence-- != 0)
65 opiehash(key, algorithm);
66
63 if (opienewseed(strcpy(newseed, seed)) < 0)
64 return -1;
65
66 if (opiekeycrunch(algorithm, newkey, newseed, secret))
67 return -1;
68
69 for (i = 0; i < 499; i++)
70 opiehash(newkey, algorithm);
71
67 if (opienewseed(strcpy(newseed, seed)) < 0)
68 return -1;
69
70 if (opiekeycrunch(algorithm, newkey, newseed, secret))
71 return -1;
72
73 for (i = 0; i < 499; i++)
74 opiehash(newkey, algorithm);
75
72 if (opiekeycrunch(algorithm | 0x10, cko, seed, secret))
73 return -1;
74
75 if (opiekeycrunch(algorithm | 0x10, ckn, newseed, secret))
76 return -1;
77
78 for (i = 0; i < 8; i++)
79 ckxor[i] = cko[i] ^ ckn[i];
80
81 strcpy(response, "init:");
76 strcpy(response, "init-hex:");
82 strcat(response, opiebtoh(buf, key));
83 sprintf(buf, ":%s 499 %s:", algids[algorithm], newseed);
84 strcat(response, buf);
85 strcat(response, opiebtoh(buf, newkey));
77 strcat(response, opiebtoh(buf, key));
78 sprintf(buf, ":%s 499 %s:", algids[algorithm], newseed);
79 strcat(response, buf);
80 strcat(response, opiebtoh(buf, newkey));
86 strcat(response, ":");
87 strcat(response, opiebtoh(buf, ckxor));
88 strcat(response, ":");
89
90 c = buf;
91 memcpy(c, ckn, sizeof(ckn)); c += sizeof(ckn);
92 memcpy(c, key, sizeof(key)); c += sizeof(key);
93#ifdef HAVE_ANSISPRINTF
94 c += sprintf(c, "%s 499 %s", algids[algorithm], newseed);
95#else /* HAVE_ANSISPRINTF */
96 sprintf(c, "%s 499 %s", algids[algorithm], newseed);
97 while(*c) c++;
98#endif /* HAVE_ANSISPRINTF */
99 memcpy(c, newkey, sizeof(newkey)); c += sizeof(newkey);
100 memcpy(c, ckxor, sizeof(ckxor)); c += sizeof(ckxor);
101 memcpy(c, ckn, sizeof(ckn)); c += sizeof(ckn);
102 opiehashlen(algorithm, buf, cv, (unsigned int)c - (unsigned int)buf);
103
104 strcat(response, opiebtoh(buf, cv));
105 } else {
106 while (sequence-- != 0)
107 opiehash(key, algorithm);
81 } else {
82 while (sequence-- != 0)
83 opiehash(key, algorithm);
108
84
109 opiebtoh(response, key);
110 }
111
112 return 0;
113}
85 opiebtoh(response, key);
86 }
87
88 return 0;
89}