122347Spst/* atob8.c: The opieatob8() 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 struct opie_otpkey for binary arg. 1822347Spst Modified by cmetz for OPIE 2.3. Return the output variable. 1922347Spst Don't check parameters. 2022347Spst Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al. 2122347Spst Inlined and obseleted opieskipspace(). Inlined and obseleted 2222347Spst opiehtoi(). 2322347Spst Created at NRL for OPIE 2.2 from opiesubr2.c 2422347Spst*/ 2522347Spst#include "opie_cfg.h" 2622347Spst#include <stdio.h> 2722347Spst#include "opie.h" 2822347Spst 2922347Spst/* Convert 8-byte hex-ascii string to binary array 3022347Spst */ 3192906Smarkmchar *opieatob8 FUNCTION((out, in), struct opie_otpkey *outkey AND char *in) 3222347Spst{ 3322347Spst register int i; 3422347Spst register int val; 3592906Smarkm unsigned char *out = (unsigned char *)outkey; 3622347Spst 3722347Spst for (i = 0; i < 8; i++) { 3822347Spst while (*in == ' ' || *in == '\t') 3922347Spst in++; 4022347Spst if (!*in) 4122347Spst return NULL; 4222347Spst 4322347Spst if ((*in >= '0') && (*in <= '9')) 4422347Spst val = *(in++) - '0'; 4522347Spst else 4622347Spst if ((*in >= 'a') && (*in <= 'f')) 4722347Spst val = *(in++) - 'a' + 10; 4822347Spst else 4922347Spst if ((*in >= 'A') && (*in <= 'F')) 5022347Spst val = *(in++) - 'A' + 10; 5122347Spst else 5222347Spst return NULL; 5322347Spst 5422347Spst *out = val << 4; 5522347Spst 5622347Spst while (*in == ' ' || *in == '\t') 5722347Spst in++; 5822347Spst if (!*in) 5922347Spst return NULL; 6022347Spst 6122347Spst if ((*in >= '0') && (*in <= '9')) 6222347Spst val = *(in++) - '0'; 6322347Spst else 6422347Spst if ((*in >= 'a') && (*in <= 'f')) 6522347Spst val = *(in++) - 'a' + 10; 6622347Spst else 6722347Spst if ((*in >= 'A') && (*in <= 'F')) 6822347Spst val = *(in++) - 'A' + 10; 6922347Spst else 7022347Spst return NULL; 7122347Spst 7222347Spst *out++ |= val; 7322347Spst } 7422347Spst 7522347Spst return out; 7622347Spst} 77