-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptpassword.c
193 lines (163 loc) · 3.46 KB
/
cryptpassword.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
*
* cryptpassword function
*
* Version 0.0
*
*/
#include "skey.h"
#ifdef __cplusplus
extern "C" {
#endif
int
cryptpassword (char **out, char *in, char *key)
{
char *ascii_offset;
char *base;
char *crypt_ptr;
char *in_ptr;
char *in_ptr_buf;
char *key_ptr;
char *out_ptr;
char *ptr;
char *result;
char *constant_ptr;
unsigned int in_ptr_size;
unsigned int key_ptr_size;
unsigned int ascii_offset_size;
unsigned int base_size;
unsigned int compare_size;
unsigned int in_size;
unsigned int key_size;
unsigned int offset;
unsigned int out_size;
unsigned int result_size;
in_size = strlen (in);
key_size = strlen (key);
in_ptr_buf = (char * ) malloc ((size_t ) in_size + 2);
memset ((void *) in_ptr_buf, ' ', in_size + 2);
memcpy ((void *) in_ptr_buf, (const void *) in, (size_t ) in_size);
*(in_ptr_buf + in_size + 1) = '\0';
(in_size)++;
if (skey_read (skey_read_new(),
in_ptr_buf,
&in_ptr,
&in_size,
&in_ptr_size) != 0)
return (-1);
free (in_ptr_buf);
if (skey_read (skey_read_new(),
key,
&key_ptr,
&key_size,
&key_ptr_size) != 0)
{
free (in_ptr);
return (-1);
}
for (offset = 7; offset <= key_ptr_size; offset += 8)
{
*(key_ptr - offset) = '1';
}
base = key_ptr;
base_size = 5;
ptr = key_ptr - 2;
constant_ptr = "11010";
constant_ptr += base_size - 1;
if (skey_compare (skey_compare_new (),
constant_ptr,
ptr,
&base_size,
&base_size) == 2)
base_size--;
base = ptr;
compare_size = 1;
if (skey_compare (skey_compare_new (),
"0",
ptr,
&compare_size,
&base_size) == 1)
base = "11010";
if (skey_crypt (skey_crypt_new (),
in_ptr,
key_ptr,
&crypt_ptr,
&in_ptr_size,
&key_ptr_size) != 0)
{
in_ptr -= (in_ptr_size - 1);
key_ptr -= (key_ptr_size - 1);
free (in_ptr);
free (key_ptr);
return (-1);
}
if (skey_addbin (skey_addbin_new (),
crypt_ptr,
ptr,
&result,
&in_ptr_size,
&base_size,
&result_size) != 0)
{
in_ptr -= (in_ptr_size - 1);
key_ptr -= (key_ptr_size - 1);
crypt_ptr -= (in_ptr_size - 1);
free (in_ptr);
free (key_ptr);
free (crypt_ptr);
return (-1);
}
result += (result_size - 1);
ascii_offset = "1100001";
ascii_offset += 6;
ascii_offset_size = 7;
if (skey_mod (skey_mod_new (),
result,
base,
ascii_offset,
&out_ptr,
&result_size,
&base_size,
&ascii_offset_size,
&out_size) != 0)
{
in_ptr -= (in_ptr_size - 1);
key_ptr -= (key_ptr_size - 1);
crypt_ptr -= in_ptr_size;
result -= (result_size - 1);
free (in_ptr);
free (key_ptr);
free (crypt_ptr);
free (result);
return (-1);
}
out_size = strlen (out_ptr);
out_ptr += (out_size - 1);
if (skey_convert (skey_convert_new (),
out_ptr,
out,
&out_size) != 0)
{
in_ptr -= (in_ptr_size - 1);
key_ptr -= (key_ptr_size - 1);
crypt_ptr -= in_ptr_size;
result -= (result_size - 1);
free (in_ptr);
free (key_ptr);
free (crypt_ptr);
free (result);
return (-1);
}
in_ptr -= (in_ptr_size - 1);
key_ptr -= (key_ptr_size - 1);
crypt_ptr -= in_ptr_size;
result -= (result_size - 1);
free (in_ptr);
free (key_ptr);
free (crypt_ptr);
free (result);
return (0);
}
#ifdef __cplusplus
}
#endif