26 |
#include <xmemory.h> |
#include <xmemory.h> |
27 |
|
|
28 |
#ifndef DEBUG |
#ifndef DEBUG |
29 |
# define fputs(x, y) 1 |
# define fputs(x, y) |
30 |
#endif |
#endif |
31 |
|
|
32 |
|
extern const lt_dlsymlist lt_preloaded_symbols[]; |
33 |
|
|
34 |
|
#define MAX_MOD_SIZE 1024 |
35 |
|
|
36 |
|
static lt_ptr search_symlist_lib(const char* _name) { |
37 |
|
int i=0; |
38 |
|
char name[MAX_MOD_SIZE]; |
39 |
|
|
40 |
|
strcpy( name, _name); |
41 |
|
strcat( name, ".a"); |
42 |
|
|
43 |
|
while( lt_preloaded_symbols[i].name!=0 || lt_preloaded_symbols[i].address!=0) { |
44 |
|
if (lt_preloaded_symbols[i].name!=NULL) { |
45 |
|
if (strcmp(name, lt_preloaded_symbols[i].name)==0) { |
46 |
|
return (void*) -1; |
47 |
|
} |
48 |
|
} |
49 |
|
i++; |
50 |
|
} |
51 |
|
return NULL; |
52 |
|
} |
53 |
|
|
54 |
|
static lt_ptr search_symlist_sym(mcrypt_dlhandle handle, const char* _name) { |
55 |
|
int i=0; |
56 |
|
char name[MAX_MOD_SIZE]; |
57 |
|
|
58 |
|
strcpy(name, handle.name); |
59 |
|
|
60 |
|
strcat( name, "_LTX_"); |
61 |
|
strcat( name, _name); |
62 |
|
|
63 |
|
while( lt_preloaded_symbols[i].name!=0 || lt_preloaded_symbols[i].address!=0) { |
64 |
|
if (lt_preloaded_symbols[i].name!=NULL) { |
65 |
|
if (strcmp(name, lt_preloaded_symbols[i].name)==0) { |
66 |
|
return lt_preloaded_symbols[i].address; |
67 |
|
} |
68 |
|
} |
69 |
|
i++; |
70 |
|
} |
71 |
|
return NULL; |
72 |
|
} |
73 |
|
|
74 |
|
void mcrypt_dlclose( mcrypt_dlhandle handle) { |
75 |
|
void* mod = handle.handle; |
76 |
|
|
77 |
|
if (mod!=MCRYPT_INTERNAL_HANDLER && mod!=NULL) |
78 |
|
lt_dlclose(mod); |
79 |
|
handle.handle = NULL; |
80 |
|
} |
81 |
|
|
82 |
|
lt_ptr mcrypt_dlsym( mcrypt_dlhandle handle, char* str) { |
83 |
|
void* mod; |
84 |
|
|
85 |
|
mod = handle.handle; |
86 |
|
|
87 |
|
if (mod!=MCRYPT_INTERNAL_HANDLER) |
88 |
|
return lt_dlsym(mod, str); |
89 |
|
else |
90 |
|
return search_symlist_sym(handle, str); |
91 |
|
|
92 |
|
} |
93 |
|
|
94 |
WIN32DLL_DEFINE |
WIN32DLL_DEFINE |
95 |
int mcrypt_module_close(MCRYPT td) |
int mcrypt_module_close(MCRYPT td) |
96 |
{ |
{ |
97 |
|
mcrypt_dlclose(td->algorithm_handle); |
98 |
lt_dlclose(td->algorithm_handle); |
mcrypt_dlclose(td->mode_handle); |
|
lt_dlclose(td->mode_handle); |
|
99 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
100 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
101 |
} |
} |
102 |
|
|
|
td->algorithm_handle = NULL; |
|
|
td->mode_handle = NULL; |
|
|
|
|
103 |
td->m_encrypt = NULL; |
td->m_encrypt = NULL; |
104 |
td->a_encrypt = NULL; |
td->a_encrypt = NULL; |
105 |
td->a_decrypt = NULL; |
td->a_decrypt = NULL; |
110 |
return 0; |
return 0; |
111 |
} |
} |
112 |
|
|
|
#ifndef USE_LTDL |
|
|
WIN32DLL_DEFINE |
|
|
void *mcrypt_dlopen_ext ( const char *filename) { |
|
|
void *ret; |
|
|
char full_path[1054]; |
|
|
|
|
|
if (strlen(filename)>sizeof(full_path)) return NULL; |
|
113 |
|
|
114 |
strcpy(full_path, filename); |
WIN32DLL_DEFINE |
115 |
ret = dlopen(full_path, RTLD_LAZY); |
void* mcrypt_dlopen ( mcrypt_dlhandle* handle, const char* a_directory, const char *m_directory, const char *filename) { |
116 |
|
static int loaded_symbols; |
117 |
|
|
118 |
|
char paths[1526]; |
119 |
|
|
120 |
if (ret==NULL) { |
if (loaded_symbols==0) { |
121 |
#ifndef WIN32 |
loaded_symbols=1; |
122 |
strcat(full_path, ".so"); |
LTDL_SET_PRELOADED_SYMBOLS(); |
|
#else |
|
|
strcat(full_path, ".dll"); |
|
|
#endif |
|
|
ret = dlopen(full_path, RTLD_LAZY); |
|
123 |
} |
} |
|
return ret; |
|
|
|
|
|
} |
|
|
#endif |
|
124 |
|
|
125 |
WIN32DLL_DEFINE |
if (strlen(filename) > sizeof( handle->name)) |
126 |
void *mcrypt_dlopen ( const char* a_directory, const char *m_directory, const char *filename) { |
return MCRYPT_FAILED; |
127 |
void* ret=NULL; |
else |
128 |
|
strcpy( handle->name, filename); |
129 |
#ifdef USE_LTDL |
|
130 |
char paths[1526]; |
if (search_symlist_lib(filename)!=NULL) { |
131 |
|
fprintf(stderr, "USING INTERNAL HANDLER\n"); |
132 |
|
handle->handle = MCRYPT_INTERNAL_HANDLER; |
133 |
|
return handle->handle; |
134 |
|
} |
135 |
|
|
136 |
memset( paths, 0, 1024); |
memset( paths, 0, 1024); |
137 |
if (a_directory != NULL) { |
if (a_directory != NULL) { |
146 |
|
|
147 |
lt_dlsetsearchpath(paths); |
lt_dlsetsearchpath(paths); |
148 |
|
|
149 |
ret = lt_dlopenext(filename); |
handle->handle = lt_dlopenext(filename); |
|
|
|
|
return ret; |
|
150 |
|
|
151 |
#else |
return handle->handle; |
|
char full_path[1050]; |
|
|
|
|
|
if (a_directory!=NULL) { |
|
|
strncpy(full_path, a_directory, 512); |
|
|
strcat(full_path, "/"); |
|
|
strncat( full_path, filename, 512); |
|
|
ret = mcrypt_dlopen_ext(full_path); |
|
|
} |
|
|
if (ret==NULL) { |
|
|
if (m_directory!=NULL) { |
|
|
strncpy(full_path, m_directory, 512); |
|
|
strcat(full_path, "/"); |
|
|
strncat( full_path, filename, 510); |
|
|
ret = mcrypt_dlopen_ext(full_path); |
|
|
} |
|
|
} |
|
|
if (ret==NULL) { |
|
|
if (LIBDIR!=NULL) { |
|
|
strncpy(full_path, LIBDIR, 512); |
|
|
strcat(full_path, "/"); |
|
|
strncat( full_path, filename, 510); |
|
|
ret = mcrypt_dlopen_ext(full_path); |
|
|
} |
|
|
} |
|
|
return ret; |
|
|
#endif |
|
152 |
|
|
153 |
} |
} |
154 |
|
|
158 |
{ |
{ |
159 |
MCRYPT td; |
MCRYPT td; |
160 |
const char* err; |
const char* err; |
161 |
|
void *ret; |
162 |
|
|
163 |
td = calloc(1, sizeof(CRYPT_STREAM)); |
td = calloc(1, sizeof(CRYPT_STREAM)); |
164 |
if (td==NULL) return MCRYPT_FAILED; |
if (td==NULL) return MCRYPT_FAILED; |
167 |
return MCRYPT_FAILED; |
return MCRYPT_FAILED; |
168 |
} |
} |
169 |
|
|
170 |
td->algorithm_handle = mcrypt_dlopen(a_directory, m_directory, algorithm); |
ret = mcrypt_dlopen( &td->algorithm_handle, a_directory, m_directory, algorithm); |
171 |
if (td->algorithm_handle == NULL) { |
if (ret == NULL) { |
172 |
err=lt_dlerror(); |
err=lt_dlerror(); |
173 |
if (err!=NULL) fputs( err, stderr); |
if (err!=NULL) fputs( err, stderr); |
174 |
fputs("\n", stderr); |
fputs("\n", stderr); |
175 |
|
free(td); |
176 |
return MCRYPT_FAILED; |
return MCRYPT_FAILED; |
177 |
} |
} |
178 |
|
|
179 |
td->mode_handle = mcrypt_dlopen(a_directory, m_directory, mode); |
ret = mcrypt_dlopen( &td->mode_handle, a_directory, m_directory, mode); |
180 |
|
|
181 |
if (td->mode_handle == NULL) { |
if (ret == NULL) { |
182 |
err=lt_dlerror(); |
err=lt_dlerror(); |
183 |
if (err!=NULL) fputs( err, stderr); |
if (err!=NULL) fputs( err, stderr); |
184 |
lt_dlclose(td->algorithm_handle); |
mcrypt_dlclose(td->algorithm_handle); |
185 |
|
free(td); |
186 |
return MCRYPT_FAILED; |
return MCRYPT_FAILED; |
187 |
} |
} |
188 |
|
|
189 |
td->a_encrypt = lt_dlsym(td->algorithm_handle, "_mcrypt_encrypt"); |
td->a_encrypt = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_encrypt"); |
190 |
td->a_decrypt = lt_dlsym(td->algorithm_handle, "_mcrypt_decrypt"); |
td->a_decrypt = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_decrypt"); |
191 |
td->m_encrypt = lt_dlsym(td->mode_handle, "_mcrypt"); |
td->m_encrypt = mcrypt_dlsym(td->mode_handle, "_mcrypt"); |
192 |
td->m_decrypt = lt_dlsym(td->mode_handle, "_mdecrypt"); |
td->m_decrypt = mcrypt_dlsym(td->mode_handle, "_mdecrypt"); |
193 |
td->a_block_size = |
td->a_block_size = |
194 |
lt_dlsym(td->algorithm_handle, "_mcrypt_get_block_size"); |
mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_block_size"); |
195 |
|
|
196 |
if (mcrypt_enc_is_block_algorithm_mode(td) != |
if (mcrypt_enc_is_block_algorithm_mode(td) != |
197 |
mcrypt_enc_is_block_algorithm(td)) { |
mcrypt_enc_is_block_algorithm(td)) { |
213 |
|
|
214 |
const char *error; |
const char *error; |
215 |
|
|
216 |
_mcrypt_get_size = lt_dlsym(td->algorithm_handle, "_mcrypt_get_size"); |
_mcrypt_get_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_size"); |
217 |
if (_mcrypt_get_size == NULL) { |
if (_mcrypt_get_size == NULL) { |
218 |
error = lt_dlerror(); |
error = lt_dlerror(); |
219 |
if (error!=NULL) fputs(error, stderr); |
if (error!=NULL) fputs(error, stderr); |
230 |
|
|
231 |
const char *error; |
const char *error; |
232 |
|
|
233 |
_mcrypt_get_size = lt_dlsym(td->mode_handle, "_mcrypt_mode_get_size"); |
_mcrypt_get_size = mcrypt_dlsym(td->mode_handle, "_mcrypt_mode_get_size"); |
234 |
if (_mcrypt_get_size == NULL) { |
if (_mcrypt_get_size == NULL) { |
235 |
error = lt_dlerror(); |
error = lt_dlerror(); |
236 |
if (error!=NULL) fputs(error, stderr); |
if (error!=NULL) fputs(error, stderr); |
249 |
|
|
250 |
if (mcrypt_enc_is_block_algorithm(td) == 0) { |
if (mcrypt_enc_is_block_algorithm(td) == 0) { |
251 |
/* stream */ |
/* stream */ |
252 |
__mcrypt_set_key_stream = lt_dlsym(td->algorithm_handle, "_mcrypt_set_key"); |
__mcrypt_set_key_stream = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_set_key"); |
253 |
if (__mcrypt_set_key_stream == NULL) { |
if (__mcrypt_set_key_stream == NULL) { |
254 |
error = lt_dlerror(); |
error = lt_dlerror(); |
255 |
if (error!=NULL) fputs(error, stderr); |
if (error!=NULL) fputs(error, stderr); |
258 |
} |
} |
259 |
return __mcrypt_set_key_stream(a, b, c, d, e); |
return __mcrypt_set_key_stream(a, b, c, d, e); |
260 |
} else { |
} else { |
261 |
__mcrypt_set_key_block = lt_dlsym(td->algorithm_handle, "_mcrypt_set_key"); |
__mcrypt_set_key_block = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_set_key"); |
262 |
if (__mcrypt_set_key_block == NULL) { |
if (__mcrypt_set_key_block == NULL) { |
263 |
error = lt_dlerror(); |
error = lt_dlerror(); |
264 |
if (error!=NULL) fputs(error, stderr); |
if (error!=NULL) fputs(error, stderr); |
275 |
int (*__mcrypt_set_state) (void *, void *, int); |
int (*__mcrypt_set_state) (void *, void *, int); |
276 |
const char *error; |
const char *error; |
277 |
|
|
278 |
__mcrypt_set_state = lt_dlsym(td->mode_handle, "_mcrypt_set_state"); |
__mcrypt_set_state = mcrypt_dlsym(td->mode_handle, "_mcrypt_set_state"); |
279 |
if (__mcrypt_set_state==NULL) { |
if (__mcrypt_set_state==NULL) { |
280 |
error = lt_dlerror(); |
error = lt_dlerror(); |
281 |
if (error!=NULL) fputs(error, stderr); |
if (error!=NULL) fputs(error, stderr); |
299 |
{ |
{ |
300 |
int (*_mcrypt_get_algo_iv_size) (void); |
int (*_mcrypt_get_algo_iv_size) (void); |
301 |
|
|
302 |
_mcrypt_get_algo_iv_size = lt_dlsym(td->algorithm_handle, "_mcrypt_get_algo_iv_size"); |
_mcrypt_get_algo_iv_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_algo_iv_size"); |
303 |
return _mcrypt_get_algo_iv_size(); |
return _mcrypt_get_algo_iv_size(); |
304 |
} |
} |
305 |
|
|
318 |
{ |
{ |
319 |
int (*_mcrypt_get_key_size) (void); |
int (*_mcrypt_get_key_size) (void); |
320 |
|
|
321 |
_mcrypt_get_key_size = lt_dlsym(td->algorithm_handle, "_mcrypt_get_key_size"); |
_mcrypt_get_key_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_key_size"); |
322 |
return _mcrypt_get_key_size(); |
return _mcrypt_get_key_size(); |
323 |
} |
} |
324 |
|
|
329 |
int *size; |
int *size; |
330 |
|
|
331 |
_mcrypt_get_key_sizes = |
_mcrypt_get_key_sizes = |
332 |
lt_dlsym(td->algorithm_handle, "_mcrypt_get_supported_key_sizes"); |
mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_supported_key_sizes"); |
333 |
size = _mcrypt_get_key_sizes(len); |
size = _mcrypt_get_key_sizes(len); |
334 |
|
|
335 |
return size; |
return size; |
340 |
{ |
{ |
341 |
int (*_is_block_algorithm) (void); |
int (*_is_block_algorithm) (void); |
342 |
|
|
343 |
_is_block_algorithm = lt_dlsym(td->algorithm_handle, "_is_block_algorithm"); |
_is_block_algorithm = mcrypt_dlsym(td->algorithm_handle, "_is_block_algorithm"); |
344 |
return _is_block_algorithm(); |
return _is_block_algorithm(); |
345 |
} |
} |
346 |
|
|
350 |
char *(*_mcrypt_get_algorithms_name) (void); |
char *(*_mcrypt_get_algorithms_name) (void); |
351 |
|
|
352 |
_mcrypt_get_algorithms_name = |
_mcrypt_get_algorithms_name = |
353 |
lt_dlsym(td->algorithm_handle, "_mcrypt_get_algorithms_name"); |
mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_algorithms_name"); |
354 |
return _mcrypt_get_algorithms_name(); |
return _mcrypt_get_algorithms_name(); |
355 |
} |
} |
356 |
|
|
359 |
{ |
{ |
360 |
int (*_init_mcrypt) (void *, void *, int, void *, int); |
int (*_init_mcrypt) (void *, void *, int, void *, int); |
361 |
|
|
362 |
_init_mcrypt = lt_dlsym(td->mode_handle, "_init_mcrypt"); |
_init_mcrypt = mcrypt_dlsym(td->mode_handle, "_init_mcrypt"); |
363 |
return _init_mcrypt(buf, a, b, c, mcrypt_enc_get_block_size(td)); |
return _init_mcrypt(buf, a, b, c, mcrypt_enc_get_block_size(td)); |
364 |
} |
} |
365 |
|
|
368 |
{ |
{ |
369 |
int (*_end_mcrypt) (void *); |
int (*_end_mcrypt) (void *); |
370 |
|
|
371 |
_end_mcrypt = lt_dlsym(td->mode_handle, "_end_mcrypt"); |
_end_mcrypt = mcrypt_dlsym(td->mode_handle, "_end_mcrypt"); |
372 |
return _end_mcrypt(buf); |
return _end_mcrypt(buf); |
373 |
} |
} |
374 |
|
|
397 |
{ |
{ |
398 |
char *(*_mcrypt_get_modes_name) (void); |
char *(*_mcrypt_get_modes_name) (void); |
399 |
|
|
400 |
_mcrypt_get_modes_name = lt_dlsym(td->mode_handle, "_mcrypt_get_modes_name"); |
_mcrypt_get_modes_name = mcrypt_dlsym(td->mode_handle, "_mcrypt_get_modes_name"); |
401 |
return _mcrypt_get_modes_name(); |
return _mcrypt_get_modes_name(); |
402 |
} |
} |
403 |
|
|
406 |
{ |
{ |
407 |
int (*_is_block_mode) (void); |
int (*_is_block_mode) (void); |
408 |
|
|
409 |
_is_block_mode = lt_dlsym(td->mode_handle, "_is_block_mode"); |
_is_block_mode = mcrypt_dlsym(td->mode_handle, "_is_block_mode"); |
410 |
return _is_block_mode(); |
return _is_block_mode(); |
411 |
} |
} |
412 |
|
|
415 |
{ |
{ |
416 |
int (*_has_iv) (void); |
int (*_has_iv) (void); |
417 |
|
|
418 |
_has_iv = lt_dlsym(td->mode_handle, "_has_iv"); |
_has_iv = mcrypt_dlsym(td->mode_handle, "_has_iv"); |
419 |
return _has_iv(); |
return _has_iv(); |
420 |
} |
} |
421 |
|
|
424 |
{ |
{ |
425 |
int (*_is_a_block_mode) (void); |
int (*_is_a_block_mode) (void); |
426 |
|
|
427 |
_is_a_block_mode = lt_dlsym(td->mode_handle, "_is_block_algorithm_mode"); |
_is_a_block_mode = mcrypt_dlsym(td->mode_handle, "_is_block_algorithm_mode"); |
428 |
return _is_a_block_mode(); |
return _is_a_block_mode(); |
429 |
} |
} |
430 |
|
|
433 |
{ |
{ |
434 |
int (*_self_test) (void); |
int (*_self_test) (void); |
435 |
|
|
436 |
_self_test = lt_dlsym(td->algorithm_handle, "_mcrypt_self_test"); |
_self_test = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_self_test"); |
437 |
|
|
438 |
return _self_test(); |
return _self_test(); |
439 |
} |
} |
442 |
int mcrypt_module_self_test(char *algorithm, char *a_directory) |
int mcrypt_module_self_test(char *algorithm, char *a_directory) |
443 |
{ |
{ |
444 |
int i; |
int i; |
445 |
lt_dlhandle _handle; |
void* rr; |
446 |
|
mcrypt_dlhandle _handle; |
447 |
int (*_self_test) (void); |
int (*_self_test) (void); |
448 |
const char* error; |
const char* error; |
449 |
|
|
451 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
452 |
} |
} |
453 |
|
|
454 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
rr = mcrypt_dlopen(&_handle, a_directory, NULL, algorithm); |
455 |
|
|
456 |
if (!_handle) { |
if (!rr) { |
457 |
error=lt_dlerror(); |
error=lt_dlerror(); |
458 |
if (error!=NULL) fputs( error, stderr); |
if (error!=NULL) fputs( error, stderr); |
459 |
fputs("\n", stderr); |
fputs("\n", stderr); |
461 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
462 |
} |
} |
463 |
|
|
464 |
_self_test = lt_dlsym(_handle, "_mcrypt_self_test"); |
_self_test = mcrypt_dlsym(_handle, "_mcrypt_self_test"); |
465 |
|
|
466 |
i = _self_test(); |
i = _self_test(); |
467 |
|
|
468 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
469 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
470 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
471 |
} |
} |
477 |
int mcrypt_module_algorithm_version(char *algorithm, char *a_directory) |
int mcrypt_module_algorithm_version(char *algorithm, char *a_directory) |
478 |
{ |
{ |
479 |
int i; |
int i; |
480 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
481 |
int (*_version) (void); |
int (*_version) (void); |
482 |
const char* error; |
const char* error; |
483 |
|
void* rr; |
484 |
|
|
485 |
if (lt_dlinit() != 0) { |
if (lt_dlinit() != 0) { |
486 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
487 |
} |
} |
488 |
|
|
489 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
rr = mcrypt_dlopen(&_handle, a_directory, NULL, algorithm); |
490 |
if (!_handle) { |
if (!rr) { |
491 |
error=lt_dlerror(); |
error=lt_dlerror(); |
492 |
if (error!=NULL) fputs( error, stderr); |
if (error!=NULL) fputs( error, stderr); |
493 |
fputs("\n", stderr); |
fputs("\n", stderr); |
494 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
495 |
} |
} |
496 |
|
|
497 |
_version = lt_dlsym(_handle, "_mcrypt_algorithm_version"); |
_version = mcrypt_dlsym(_handle, "_mcrypt_algorithm_version"); |
498 |
|
|
499 |
i = _version(); |
i = _version(); |
500 |
|
|
501 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
502 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
503 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
504 |
} |
} |
510 |
int mcrypt_module_mode_version(char *mode, char *m_directory) |
int mcrypt_module_mode_version(char *mode, char *m_directory) |
511 |
{ |
{ |
512 |
int i; |
int i; |
513 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
514 |
int (*_version) (void); |
int (*_version) (void); |
515 |
const char* error; |
const char* error; |
516 |
|
void * rr; |
517 |
|
|
518 |
if (lt_dlinit() != 0) { |
if (lt_dlinit() != 0) { |
519 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
520 |
} |
} |
521 |
|
|
522 |
_handle = mcrypt_dlopen(m_directory, NULL, mode); |
rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode); |
523 |
if (!_handle) { |
if (!rr) { |
524 |
error=lt_dlerror(); |
error=lt_dlerror(); |
525 |
if(error!=NULL) fputs(error, stderr); |
if(error!=NULL) fputs(error, stderr); |
526 |
fputs("\n", stderr); |
fputs("\n", stderr); |
527 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
528 |
} |
} |
529 |
|
|
530 |
_version = lt_dlsym(_handle, "_mcrypt_mode_version"); |
_version = mcrypt_dlsym( _handle, "_mcrypt_mode_version"); |
531 |
|
|
532 |
i = _version(); |
i = _version(); |
533 |
|
|
534 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
535 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
536 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
537 |
} |
} |
543 |
int mcrypt_module_is_block_algorithm(char *algorithm, char *a_directory) |
int mcrypt_module_is_block_algorithm(char *algorithm, char *a_directory) |
544 |
{ |
{ |
545 |
int i; |
int i; |
546 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
547 |
int (*_is_block_algorithm) (void); |
int (*_is_block_algorithm) (void); |
548 |
const char* error; |
const char* error; |
549 |
|
void * rr; |
550 |
|
|
551 |
if (lt_dlinit() != 0) { |
if (lt_dlinit() != 0) { |
552 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
553 |
} |
} |
554 |
|
|
555 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm); |
556 |
|
if (!rr) { |
|
if (!_handle) { |
|
557 |
error=lt_dlerror(); |
error=lt_dlerror(); |
558 |
if(error!=NULL) fputs( error, stderr); |
if(error!=NULL) fputs( error, stderr); |
559 |
fputs("\n", stderr); |
fputs("\n", stderr); |
560 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
561 |
} |
} |
562 |
|
|
563 |
_is_block_algorithm = lt_dlsym(_handle, "_is_block_algorithm"); |
_is_block_algorithm = mcrypt_dlsym(_handle, "_is_block_algorithm"); |
564 |
|
|
565 |
i = _is_block_algorithm(); |
i = _is_block_algorithm(); |
566 |
|
|
567 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
568 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
569 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
570 |
} |
} |
576 |
int mcrypt_module_is_block_algorithm_mode(char *mode, char *m_directory) |
int mcrypt_module_is_block_algorithm_mode(char *mode, char *m_directory) |
577 |
{ |
{ |
578 |
int i; |
int i; |
579 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
580 |
int (*_is_a_block_mode) (void); |
int (*_is_a_block_mode) (void); |
581 |
const char* error; |
const char* error; |
582 |
|
void * rr; |
583 |
|
|
584 |
if (lt_dlinit() != 0) { |
if (lt_dlinit() != 0) { |
585 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
586 |
} |
} |
587 |
|
|
588 |
_handle = mcrypt_dlopen(m_directory, NULL, mode); |
rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode); |
589 |
if (!_handle) { |
if (!rr) { |
590 |
error=lt_dlerror(); |
error=lt_dlerror(); |
591 |
if(error!=NULL) fputs( error, stderr); |
if(error!=NULL) fputs( error, stderr); |
592 |
fputs("\n", stderr); |
fputs("\n", stderr); |
593 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
594 |
} |
} |
595 |
|
|
596 |
_is_a_block_mode = lt_dlsym(_handle, "_is_block_algorithm_mode"); |
_is_a_block_mode = mcrypt_dlsym(_handle, "_is_block_algorithm_mode"); |
597 |
|
|
598 |
i = _is_a_block_mode(); |
i = _is_a_block_mode(); |
599 |
|
|
600 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
601 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
602 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
603 |
} |
} |
608 |
WIN32DLL_DEFINE |
WIN32DLL_DEFINE |
609 |
int mcrypt_module_is_block_mode(char *mode, char *m_directory) |
int mcrypt_module_is_block_mode(char *mode, char *m_directory) |
610 |
{ |
{ |
611 |
|
void * rr; |
612 |
int i; |
int i; |
613 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
614 |
int (*_is_block_mode) (void); |
int (*_is_block_mode) (void); |
615 |
const char* error; |
const char* error; |
616 |
|
|
618 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
619 |
} |
} |
620 |
|
|
621 |
_handle = mcrypt_dlopen(m_directory, NULL, mode); |
rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode); |
622 |
if (!_handle) { |
if (!rr) { |
623 |
error=lt_dlerror(); |
error=lt_dlerror(); |
624 |
if(error!=NULL) fputs( error, stderr); |
if(error!=NULL) fputs( error, stderr); |
625 |
fputs("\n", stderr); |
fputs("\n", stderr); |
626 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
627 |
} |
} |
628 |
|
|
629 |
_is_block_mode = lt_dlsym(_handle, "_is_block_mode"); |
_is_block_mode = mcrypt_dlsym(_handle, "_is_block_mode"); |
630 |
|
|
631 |
i = _is_block_mode(); |
i = _is_block_mode(); |
632 |
|
|
633 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
634 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
635 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
636 |
} |
} |
642 |
int mcrypt_module_get_algo_block_size(char *algorithm, char *a_directory) |
int mcrypt_module_get_algo_block_size(char *algorithm, char *a_directory) |
643 |
{ |
{ |
644 |
int i; |
int i; |
645 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
646 |
int (*_get_block_size) (void); |
int (*_get_block_size) (void); |
647 |
const char* error; |
const char* error; |
648 |
|
void * rr; |
649 |
|
|
650 |
if (lt_dlinit() != 0) { |
if (lt_dlinit() != 0) { |
651 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
652 |
} |
} |
653 |
|
|
654 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm); |
655 |
if (!_handle) { |
if (!rr) { |
656 |
error=lt_dlerror(); |
error=lt_dlerror(); |
657 |
if(error!=NULL) fputs( error, stderr); |
if(error!=NULL) fputs( error, stderr); |
658 |
fputs("\n", stderr); |
fputs("\n", stderr); |
659 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
660 |
} |
} |
661 |
|
|
662 |
_get_block_size = lt_dlsym(_handle, "_mcrypt_get_block_size"); |
_get_block_size = mcrypt_dlsym(_handle, "_mcrypt_get_block_size"); |
663 |
|
|
664 |
i = _get_block_size(); |
i = _get_block_size(); |
665 |
|
|
666 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
667 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
668 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
669 |
} |
} |
675 |
int mcrypt_module_get_algo_key_size(char *algorithm, char *a_directory) |
int mcrypt_module_get_algo_key_size(char *algorithm, char *a_directory) |
676 |
{ |
{ |
677 |
int i; |
int i; |
678 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
679 |
int (*_get_key_size) (void); |
int (*_get_key_size) (void); |
680 |
const char* error; |
const char* error; |
681 |
|
void * rr; |
682 |
|
|
683 |
if (lt_dlinit() != 0) { |
if (lt_dlinit() != 0) { |
684 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
685 |
} |
} |
686 |
|
|
687 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm); |
688 |
if (!_handle) { |
if (!rr) { |
689 |
error=lt_dlerror(); |
error=lt_dlerror(); |
690 |
if(error!=NULL) fputs( error, stderr); |
if(error!=NULL) fputs( error, stderr); |
691 |
fputs("\n", stderr); |
fputs("\n", stderr); |
692 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
693 |
} |
} |
694 |
|
|
695 |
_get_key_size = lt_dlsym(_handle, "_mcrypt_get_key_size"); |
_get_key_size = mcrypt_dlsym(_handle, "_mcrypt_get_key_size"); |
696 |
|
|
697 |
i = _get_key_size(); |
i = _get_key_size(); |
698 |
|
|
699 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
700 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
701 |
return MCRYPT_UNKNOWN_ERROR; |
return MCRYPT_UNKNOWN_ERROR; |
702 |
} |
} |
709 |
char *a_directory, |
char *a_directory, |
710 |
int *len) |
int *len) |
711 |
{ |
{ |
712 |
lt_dlhandle _handle; |
mcrypt_dlhandle _handle; |
713 |
int *(*_mcrypt_get_key_sizes) (int *); |
int *(*_mcrypt_get_key_sizes) (int *); |
714 |
int *size; |
int *size; |
715 |
const char* error; |
const char* error; |
716 |
|
void * rr; |
717 |
|
|
718 |
if (lt_dlinit() != 0) { |
if (lt_dlinit() != 0) { |
719 |
*len = 0; |
*len = 0; |
720 |
return NULL; |
return NULL; |
721 |
} |
} |
722 |
|
|
723 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm); |
724 |
if (!_handle) { |
if (!rr) { |
725 |
error=lt_dlerror(); |
error=lt_dlerror(); |
726 |
if(error!=NULL) fputs( error, stderr); |
if(error!=NULL) fputs( error, stderr); |
727 |
fputs("\n", stderr); |
fputs("\n", stderr); |
730 |
} |
} |
731 |
|
|
732 |
_mcrypt_get_key_sizes = |
_mcrypt_get_key_sizes = |
733 |
lt_dlsym(_handle, "_mcrypt_get_supported_key_sizes"); |
mcrypt_dlsym(_handle, "_mcrypt_get_supported_key_sizes"); |
734 |
|
|
735 |
size = _mcrypt_get_key_sizes(len); |
size = _mcrypt_get_key_sizes(len); |
736 |
|
|
737 |
lt_dlclose(_handle); |
mcrypt_dlclose(_handle); |
738 |
if (lt_dlexit() != 0) { |
if (lt_dlexit() != 0) { |
739 |
return NULL; |
return NULL; |
740 |
} |
} |