122347Spst/* randomchallenge.c: The opierandomchallenge() library function. 222347Spst 329964Sache%%% portions-copyright-cmetz-96 492906SmarkmPortions of this software are Copyright 1996-1999 by Craig Metz, All Rights 522347SpstReserved. The Inner Net License Version 2 applies to these portions of 622347Spstthe software. 722347SpstYou should have received a copy of the license with this software. If 822347Spstyou didn't get a copy, you may request one from <license@inner.net>. 922347Spst 1022347SpstPortions of this software are Copyright 1995 by Randall Atkinson and Dan 1122347SpstMcDonald, All Rights Reserved. All Rights under this copyright are assigned 1222347Spstto the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and 1322347SpstLicense Agreement applies to this software. 1422347Spst 1522347Spst History: 1622347Spst 1792906Smarkm Modified by cmetz for OPIE 2.4. Use snprintf(). 1859118Skris Modified by cmetz for OPIE 2.32. Initialize algids[] with 0s 1959118Skris instead of NULL. 2022347Spst Modified by cmetz for OPIE 2.3. Add sha support. 2122347Spst Modified by cmetz for OPIE 2.22. Don't include stdio.h. 2222347Spst Use opienewseed(). Don't include unneeded headers. 2322347Spst Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al. 2422347Spst Changed use of gethostname() to uname(). Ifdefed around some 2522347Spst headers. 2622347Spst Created at NRL for OPIE 2.2 from opiesubr2.c 2722347Spst*/ 2822347Spst 2922347Spst#include "opie_cfg.h" 3022347Spst#include "opie.h" 3122347Spst 3259118Skrisstatic char *algids[] = { 0, 0, 0, "sha1", "md4", "md5" }; 3322347Spst 3422347Spst/* Generate a random challenge */ 3522347Spst/* This could grow into quite a monster, really. Random is good enough for 3622347Spst most situations; it is certainly better than a fixed string */ 3722347SpstVOIDRET opierandomchallenge FUNCTION((prompt), char *prompt) 3822347Spst{ 3992906Smarkm char buf[OPIE_SEED_MAX+1]; 4022347Spst 4122347Spst buf[0] = 0; 4222347Spst if (opienewseed(buf)) 4322347Spst strcpy(buf, "ke4452"); 4422347Spst 4592906Smarkm snprintf(prompt, OPIE_CHALLENGE_MAX+1, "otp-%s %d %s ext", algids[MDX], 4692906Smarkm (rand() % 499) + 1, buf); 4722347Spst} 48