Deleted Added
sdiff udiff text old ( 29964 ) new ( 59118 )
full compact
1/* keycrunch.c: The opiekeycrunch() library function.
2
3%%% copyright-cmetz-96
4This software is Copyright 1996-1997 by Craig Metz, All Rights Reserved.
5The Inner Net License Version 2 applies to this software.
6You should have received a copy of the license with this software. If
7you didn't get a copy, you may request one from <license@inner.net>.
8
9 History:
10
11 Created by cmetz for OPIE 2.3 using the old keycrunch.c as a guide.
12*/
13
14#include "opie_cfg.h"
15
16#if HAVE_STRING_H
17#include <string.h>
18#endif /* HAVE_STRING_H */
19#if HAVE_STDLIB_H
20#include <stdlib.h>
21#endif /* HAVE_STDLIB_H */
22#include <ctype.h>
23
24#include "opie.h"
25
26int opiekeycrunch FUNCTION((algorithm, result, seed, secret), int algorithm AND char *result AND char *seed AND char *secret)
27{
28 int i, rval = -1;
29 char *c;
30
31 if (!result || !seed || !secret)
32 return 1;
33
34 i = strlen(seed) + strlen(secret);
35 if (!(c = malloc(i + 1)))
36 return -1;
37
38 {
39 char *c2 = c;
40
41 if (algorithm & 0x10)
42 while(*c2 = *(secret++)) c2++;
43
44 while(*seed)
45 if (isspace(*(c2++) = tolower(*(seed++))))
46 goto kcret;
47
48 if (!(algorithm & 0x10))
49 strcpy(c2, secret);
50 }
51
52 opiehashlen(algorithm & 0x0f, c, result, i);
53 rval = 0;
54
55kcret:
56 {
57 char *c2 = c;
58 while(*c2)
59 *(c2++) = 0;
60 }
61
62 free(c);
63 return rval;
64}