[zoneinfo] Add some missing zoneinfo files
[dragonfly.git] / contrib / opie / libopie / keycrunch.c
blobd9ff5ca00b800a5a5d06757377c9454ab6f6ab1e
1 /* keycrunch.c: The opiekeycrunch() library function.
3 %%% copyright-cmetz-96
4 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 3 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
9 History:
11 Modified by cmetz for OPIE 2.4. Use struct opie_otpkey for arg.
12 Created by cmetz for OPIE 2.3 using the old keycrunch.c as a guide.
15 #include "opie_cfg.h"
17 #if HAVE_STRING_H
18 #include <string.h>
19 #endif /* HAVE_STRING_H */
20 #if HAVE_STDLIB_H
21 #include <stdlib.h>
22 #endif /* HAVE_STDLIB_H */
23 #include <ctype.h>
25 #include "opie.h"
27 int opiekeycrunch FUNCTION((algorithm, result, seed, secret), int algorithm AND
28 struct opie_otpkey *result AND char *seed AND char *secret)
30 int i, rval = -1;
31 char *c;
33 if (!result || !seed || !secret)
34 return 1;
36 i = strlen(seed) + strlen(secret);
37 if (!(c = malloc(i + 1)))
38 return -1;
41 char *c2 = c;
43 if (algorithm & 0x10)
44 while((*c2 = *(secret++)) != '\0') c2++;
46 while(*seed)
47 if (isspace(*(c2++) = tolower(*(seed++))))
48 goto kcret;
50 if (!(algorithm & 0x10))
51 strcpy(c2, secret);
54 opiehashlen(algorithm & 0x0f, c, result, i);
55 rval = 0;
57 kcret:
59 char *c2 = c;
60 while(*c2)
61 *(c2++) = 0;
64 free(c);
65 return rval;