1/* atob8.c: The opieatob8() library function. 2 3%%% portions-copyright-cmetz-96 4Portions of this software are Copyright 1996-1999 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 10Portions of this software are Copyright 1995 by Randall Atkinson and Dan 11McDonald, All Rights Reserved. All Rights under this copyright are assigned 12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and 13License Agreement applies to this software. 14 15 History: 16 17 Modified by cmetz for OPIE 2.4. Use struct opie_otpkey for binary arg. 18 Modified by cmetz for OPIE 2.3. Return the output variable. 19 Don't check parameters. 20 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al. 21 Inlined and obseleted opieskipspace(). Inlined and obseleted 22 opiehtoi(). 23 Created at NRL for OPIE 2.2 from opiesubr2.c 24*/ 25#include "opie_cfg.h" 26#include <stdio.h> 27#include "opie.h" 28 29/* Convert 8-byte hex-ascii string to binary array 30 */ 31char *opieatob8 FUNCTION((out, in), struct opie_otpkey *outkey AND char *in) 32{ 33 register int i; 34 register int val; 35 unsigned char *out = (unsigned char *)outkey; 36 37 for (i = 0; i < 8; i++) { 38 while (*in == ' ' || *in == '\t') 39 in++; 40 if (!*in) 41 return NULL; 42 43 if ((*in >= '0') && (*in <= '9')) 44 val = *(in++) - '0'; 45 else 46 if ((*in >= 'a') && (*in <= 'f')) 47 val = *(in++) - 'a' + 10; 48 else 49 if ((*in >= 'A') && (*in <= 'F')) 50 val = *(in++) - 'A' + 10; 51 else 52 return NULL; 53 54 *out = val << 4; 55 56 while (*in == ' ' || *in == '\t') 57 in++; 58 if (!*in) 59 return NULL; 60 61 if ((*in >= '0') && (*in <= '9')) 62 val = *(in++) - '0'; 63 else 64 if ((*in >= 'a') && (*in <= 'f')) 65 val = *(in++) - 'a' + 10; 66 else 67 if ((*in >= 'A') && (*in <= 'F')) 68 val = *(in++) - 'A' + 10; 69 else 70 return NULL; 71 72 *out++ |= val; 73 } 74 75 return out; 76} 77