-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinc.utils.c
executable file
·150 lines (123 loc) · 3.96 KB
/
inc.utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (C) 2006 Richard Kotal
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
static const EVP_MD* fb_shash_GetHashId (char *name)
{
const EVP_MD *MD = NULL;
char *s = NULL;
char *buf = NULL;
int len = 0;
if (name == NULL) return MD;
len = strlen(name);
buf = malloc(len+1);
memset (buf, '\0' , len+1);
memcpy(buf,name,len);
s = fb_shash_StrToUpper(buf);
MD = EVP_get_digestbyname(s);
if (buf != NULL) free(buf);
return MD;
}
static char *fb_shash_GetOutStr (char *err)
{
int len = 0;
char *out = NULL;
if (err == NULL) return out;
len = strlen (err);
out = (char *) ib_util_malloc (len + 1);
memset (out, '\0' , len + 1);
memcpy (out, err,len);
return out;
}
static char *fb_shash_StrToUpper(char *string)
{
char *s = NULL;
s = string;
while (*s != '\0') {
if (islower(UCHAR(*s))) {
*s = toupper(UCHAR(*s));
}
++s;
}
return string;
}
/*
* Copyright (C) 1998 Nikos Mavroyanopoulos
* Copyright (C) 1999,2000 Sascha Schumman, Nikos Mavroyanopoulos
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
$Id: stdfns.c,v 1.2 2006/01/10 03:47:18 imipak Exp $
*/
/**
* Some of these are wrappers. The idea is to eventually produce an extremely
* lightweight set of robust, portable functions that are guaranteed to produce
* a "safe" result, even with bogus inputs. We can't trust native C libraries
* to validate inputs.
*/
static unsigned char fb_shash_utils_val2char(unsigned char x)
{
unsigned char out;
switch(x)
{
case 0x0 : { out = '0'; break; }
case 0x1 : { out = '1'; break; }
case 0x2 : { out = '2'; break; }
case 0x3 : { out = '3'; break; }
case 0x4 : { out = '4'; break; }
case 0x5 : { out = '5'; break; }
case 0x6 : { out = '6'; break; }
case 0x7 : { out = '7'; break; }
case 0x8 : { out = '8'; break; }
case 0x9 : { out = '9'; break; }
case 0xa : { out = 'a'; break; }
case 0xb : { out = 'b'; break; }
case 0xc : { out = 'c'; break; }
case 0xd : { out = 'd'; break; }
case 0xe : { out = 'e'; break; }
case 0xf : { out = 'f'; break; }
}
return(out);
}
static char * fb_shash_utils_asciify(char *in, long len)
{
char *ptrIn = in;
char *buffer = malloc((2 * len) + 1);
char *ptrOut = buffer;
long loop;
memset (buffer, '\0' , (2 * len) + 1);
for (loop = 0; loop < len; loop++, ptrIn++)
{
*ptrOut++ = fb_shash_utils_val2char((*ptrIn & 0xf0) >> 4);
*ptrOut++ = fb_shash_utils_val2char((*ptrIn & 0x0f));
}
return(buffer);
}