1 |
/* |
2 |
* Copyright (C) 1998,1999,2000 Nikos Mavroyanopoulos |
3 |
* |
4 |
* This library is free software; you can redistribute it and/or modify it |
5 |
* under the terms of the GNU Library General Public License as published |
6 |
* by the Free Software Foundation; either version 2 of the License, or |
7 |
* (at your option) any later version. |
8 |
* |
9 |
* This library is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 |
* Library General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU Library General Public |
15 |
* License along with this library; if not, write to the |
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 |
* Boston, MA 02111-1307, USA. |
18 |
*/ |
19 |
|
20 |
#ifndef LIBDEFS_H |
21 |
#define LIBDEFS_H |
22 |
#include <libdefs.h> |
23 |
#endif |
24 |
#include <bzero.h> |
25 |
#include <mcrypt_internal.h> |
26 |
#include <xmemory.h> |
27 |
|
28 |
#if 0 |
29 |
extern int preloaded_symbols; |
30 |
#endif |
31 |
|
32 |
WIN32DLL_DEFINE |
33 |
int mcrypt_module_close(MCRYPT td) |
34 |
{ |
35 |
|
36 |
lt_dlclose(td->algorithm_handle); |
37 |
lt_dlclose(td->mode_handle); |
38 |
lt_dlexit(); |
39 |
|
40 |
td->algorithm_handle = NULL; |
41 |
td->mode_handle = NULL; |
42 |
|
43 |
td->m_encrypt = NULL; |
44 |
td->a_encrypt = NULL; |
45 |
td->a_decrypt = NULL; |
46 |
td->m_decrypt = NULL; |
47 |
|
48 |
return 0; |
49 |
} |
50 |
|
51 |
#ifndef USE_LTDL |
52 |
WIN32DLL_DEFINE |
53 |
void *mcrypt_dlopen_ext ( const char *filename) { |
54 |
void *ret; |
55 |
char full_path[1054]; |
56 |
|
57 |
if (strlen(filename)>sizeof(full_path)) return; |
58 |
|
59 |
strcpy(full_path, filename); |
60 |
ret = dlopen(full_path, RTLD_LAZY); |
61 |
|
62 |
if (ret==NULL) { |
63 |
#ifndef WIN32 |
64 |
strcat(full_path, ".so"); |
65 |
#else |
66 |
strcat(full_path, ".dll"); |
67 |
#endif |
68 |
ret = dlopen(full_path, RTLD_LAZY); |
69 |
} |
70 |
return ret; |
71 |
|
72 |
} |
73 |
#endif |
74 |
|
75 |
WIN32DLL_DEFINE |
76 |
void *mcrypt_dlopen ( const char* a_directory, const char *m_directory, const char *filename) { |
77 |
void* ret=NULL; |
78 |
|
79 |
#ifdef USE_LTDL |
80 |
char paths[1526]; |
81 |
|
82 |
memset( paths, 0, 1024); |
83 |
if (a_directory != NULL) { |
84 |
strncat( paths, a_directory, 512); |
85 |
strcat( paths, ":"); |
86 |
} |
87 |
if (m_directory != NULL) { |
88 |
strncat( paths, m_directory, 512); |
89 |
strcat( paths, ":"); |
90 |
} |
91 |
strncat( paths, LIBDIR, 512); |
92 |
|
93 |
lt_dlsetsearchpath(paths); |
94 |
|
95 |
ret = lt_dlopenext(filename); |
96 |
if (ret==NULL) ret = lt_dlopen(filename); |
97 |
|
98 |
return ret; |
99 |
|
100 |
#else |
101 |
char full_path[1050]; |
102 |
|
103 |
if (a_directory!=NULL) { |
104 |
strncpy(full_path, a_directory, 512); |
105 |
strcat(full_path, "/"); |
106 |
strncat( full_path, filename, 512); |
107 |
ret = mcrypt_dlopen_ext(full_path); |
108 |
} |
109 |
if (ret==NULL) { |
110 |
if (m_directory!=NULL) { |
111 |
strncpy(full_path, m_directory, 512); |
112 |
strcat(full_path, "/"); |
113 |
strncat( full_path, filename, 510); |
114 |
ret = mcrypt_dlopen_ext(full_path); |
115 |
} |
116 |
} |
117 |
if (ret==NULL) { |
118 |
if (LIBDIR!=NULL) { |
119 |
strncpy(full_path, LIBDIR, 512); |
120 |
strcat(full_path, "/"); |
121 |
strncat( full_path, filename, 510); |
122 |
ret = mcrypt_dlopen_ext(full_path); |
123 |
} |
124 |
} |
125 |
return ret; |
126 |
#endif |
127 |
|
128 |
} |
129 |
|
130 |
WIN32DLL_DEFINE |
131 |
MCRYPT mcrypt_module_open(char *algorithm, |
132 |
char *a_directory, char *mode, char *m_directory) |
133 |
{ |
134 |
MCRYPT td; |
135 |
char* err; |
136 |
|
137 |
td = calloc(1, sizeof(CRYPT_STREAM)); |
138 |
|
139 |
if (lt_dlinit() != 0) { |
140 |
return MCRYPT_FAILED; |
141 |
} |
142 |
|
143 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
144 |
|
145 |
td->algorithm_handle = mcrypt_dlopen(a_directory, m_directory, algorithm); |
146 |
if (td->algorithm_handle == NULL) { |
147 |
err=lt_dlerror(); |
148 |
if (err!=NULL) fputs( err, stderr); |
149 |
fputs("\n", stderr); |
150 |
return MCRYPT_FAILED; |
151 |
} |
152 |
|
153 |
td->mode_handle = mcrypt_dlopen(a_directory, m_directory, mode); |
154 |
|
155 |
if (td->mode_handle == NULL) { |
156 |
err=lt_dlerror(); |
157 |
if (err!=NULL) fputs( err, stderr); |
158 |
lt_dlclose(td->algorithm_handle); |
159 |
return MCRYPT_FAILED; |
160 |
} |
161 |
|
162 |
td->a_encrypt = lt_dlsym(td->algorithm_handle, "_mcrypt_encrypt"); |
163 |
td->a_decrypt = lt_dlsym(td->algorithm_handle, "_mcrypt_decrypt"); |
164 |
td->m_encrypt = lt_dlsym(td->mode_handle, "_mcrypt"); |
165 |
td->m_decrypt = lt_dlsym(td->mode_handle, "_mdecrypt"); |
166 |
td->a_block_size = |
167 |
lt_dlsym(td->algorithm_handle, "_mcrypt_get_block_size"); |
168 |
|
169 |
if (mcrypt_enc_is_block_algorithm_mode(td) != |
170 |
mcrypt_enc_is_block_algorithm(td)) { |
171 |
mcrypt_module_close(td); |
172 |
return MCRYPT_FAILED; |
173 |
} |
174 |
|
175 |
return td; |
176 |
} |
177 |
|
178 |
|
179 |
|
180 |
/* Modules' frontends */ |
181 |
|
182 |
WIN32DLL_DEFINE |
183 |
int mcrypt_get_size(MCRYPT td) |
184 |
{ |
185 |
int (*_mcrypt_get_size) (void); |
186 |
|
187 |
const char *error; |
188 |
char *s; |
189 |
|
190 |
s = td->algorithm_handle; |
191 |
_mcrypt_get_size = lt_dlsym(s, "_mcrypt_get_size"); |
192 |
if ((error = lt_dlerror())) { |
193 |
if (error!=NULL) fputs(error, stderr); |
194 |
fputs("\n", stderr); |
195 |
return MCRYPT_UNKNOWN_ERROR; |
196 |
} |
197 |
return _mcrypt_get_size(); |
198 |
} |
199 |
|
200 |
WIN32DLL_DEFINE |
201 |
int mcrypt_mode_get_size(MCRYPT td) |
202 |
{ |
203 |
int (*_mcrypt_get_size) (void); |
204 |
|
205 |
const char *error; |
206 |
char *s; |
207 |
|
208 |
s = td->mode_handle; |
209 |
_mcrypt_get_size = lt_dlsym(s, "_mcrypt_mode_get_size"); |
210 |
if ((error = lt_dlerror())) { |
211 |
if (error!=NULL) fputs(error, stderr); |
212 |
fputs("\n", stderr); |
213 |
return MCRYPT_UNKNOWN_ERROR; |
214 |
} |
215 |
return _mcrypt_get_size(); |
216 |
} |
217 |
|
218 |
WIN32DLL_DEFINE |
219 |
void mcrypt_set_key(MCRYPT td, void *a, void *b, int c, void *d, int e) |
220 |
{ |
221 |
void (*__mcrypt_set_key_stream) (void *, void *, int, void *, int); |
222 |
void (*__mcrypt_set_key_block) (void *, void *, int); |
223 |
const char *error; |
224 |
char *s; |
225 |
|
226 |
s = td->algorithm_handle; |
227 |
if (mcrypt_enc_is_block_algorithm(td) == 0) { |
228 |
/* stream */ |
229 |
__mcrypt_set_key_stream = lt_dlsym(s, "_mcrypt_set_key"); |
230 |
if ((error = lt_dlerror())) { |
231 |
if (error!=NULL) fputs(error, stderr); |
232 |
fputs("\n", stderr); |
233 |
return; |
234 |
} |
235 |
__mcrypt_set_key_stream(a, b, c, d, e); |
236 |
} else { |
237 |
__mcrypt_set_key_block = lt_dlsym(s, "_mcrypt_set_key"); |
238 |
if ((error = lt_dlerror())) { |
239 |
if (error!=NULL) fputs(error, stderr); |
240 |
fputs("\n", stderr); |
241 |
return; |
242 |
} |
243 |
__mcrypt_set_key_block(a, b, c); |
244 |
} |
245 |
} |
246 |
|
247 |
WIN32DLL_DEFINE |
248 |
int mcrypt_enc_set_state(MCRYPT td, void *iv, int size) |
249 |
{ |
250 |
int (*__mcrypt_set_state) (void *, void *, int); |
251 |
const char *error; |
252 |
char *s; |
253 |
|
254 |
s = td->mode_handle; |
255 |
|
256 |
__mcrypt_set_state = lt_dlsym(s, "_mcrypt_set_state"); |
257 |
if ((error = lt_dlerror())) { |
258 |
if (error!=NULL) fputs(error, stderr); |
259 |
fputs("\n", stderr); |
260 |
return MCRYPT_UNKNOWN_ERROR; |
261 |
} |
262 |
return __mcrypt_set_state(td->abuf, iv, size); |
263 |
} |
264 |
|
265 |
WIN32DLL_DEFINE |
266 |
int mcrypt_enc_get_block_size(MCRYPT td) |
267 |
{ |
268 |
int (*_mcrypt_get_block_size) (void); |
269 |
|
270 |
_mcrypt_get_block_size = td->a_block_size; |
271 |
return _mcrypt_get_block_size(); |
272 |
} |
273 |
|
274 |
WIN32DLL_DEFINE |
275 |
int mcrypt_get_algo_iv_size(MCRYPT td) |
276 |
{ |
277 |
int (*_mcrypt_get_algo_iv_size) (void); |
278 |
char *s; |
279 |
|
280 |
s = td->algorithm_handle; |
281 |
|
282 |
_mcrypt_get_algo_iv_size = lt_dlsym(s, "_mcrypt_get_algo_iv_size"); |
283 |
return _mcrypt_get_algo_iv_size(); |
284 |
} |
285 |
|
286 |
WIN32DLL_DEFINE |
287 |
int mcrypt_enc_get_iv_size(MCRYPT td) |
288 |
{ |
289 |
if (mcrypt_enc_is_block_algorithm_mode(td) == 1) { |
290 |
return mcrypt_enc_get_block_size(td); |
291 |
} else { |
292 |
return mcrypt_get_algo_iv_size(td); |
293 |
} |
294 |
} |
295 |
|
296 |
WIN32DLL_DEFINE |
297 |
int mcrypt_enc_get_key_size(MCRYPT td) |
298 |
{ |
299 |
int (*_mcrypt_get_key_size) (void); |
300 |
char *s; |
301 |
|
302 |
s = td->algorithm_handle; |
303 |
|
304 |
_mcrypt_get_key_size = lt_dlsym(s, "_mcrypt_get_key_size"); |
305 |
return _mcrypt_get_key_size(); |
306 |
} |
307 |
|
308 |
WIN32DLL_DEFINE |
309 |
int *mcrypt_enc_get_supported_key_sizes(MCRYPT td, int *len) |
310 |
{ |
311 |
int *(*_mcrypt_get_key_sizes) (int *); |
312 |
char *s; |
313 |
int *size; |
314 |
|
315 |
s = td->algorithm_handle; |
316 |
|
317 |
_mcrypt_get_key_sizes = |
318 |
lt_dlsym(s, "_mcrypt_get_supported_key_sizes"); |
319 |
size = _mcrypt_get_key_sizes(len); |
320 |
|
321 |
return size; |
322 |
} |
323 |
|
324 |
WIN32DLL_DEFINE |
325 |
int mcrypt_enc_is_block_algorithm(MCRYPT td) |
326 |
{ |
327 |
int (*_is_block_algorithm) (void); |
328 |
char *s; |
329 |
|
330 |
s = td->algorithm_handle; |
331 |
|
332 |
_is_block_algorithm = lt_dlsym(s, "_is_block_algorithm"); |
333 |
return _is_block_algorithm(); |
334 |
} |
335 |
|
336 |
WIN32DLL_DEFINE |
337 |
char *mcrypt_enc_get_algorithms_name(MCRYPT td) |
338 |
{ |
339 |
char *(*_mcrypt_get_algorithms_name) (void); |
340 |
char *s; |
341 |
|
342 |
s = td->algorithm_handle; |
343 |
|
344 |
_mcrypt_get_algorithms_name = |
345 |
lt_dlsym(s, "_mcrypt_get_algorithms_name"); |
346 |
return _mcrypt_get_algorithms_name(); |
347 |
} |
348 |
|
349 |
WIN32DLL_DEFINE |
350 |
void mcrypt_block_encrypt(MCRYPT td, void *b) |
351 |
{ |
352 |
void (*_mcrypt_block_encrypt) (void *, void *); |
353 |
char *a; |
354 |
|
355 |
a = td->akey; |
356 |
_mcrypt_block_encrypt = td->a_encrypt; |
357 |
|
358 |
_mcrypt_block_encrypt(a, b); |
359 |
} |
360 |
|
361 |
WIN32DLL_DEFINE |
362 |
void mcrypt_block_decrypt(MCRYPT td, void *b) |
363 |
{ |
364 |
void (*_mcrypt_block_decrypt) (void *, void *); |
365 |
char *a; |
366 |
|
367 |
a = td->akey; |
368 |
_mcrypt_block_decrypt = td->a_decrypt; |
369 |
_mcrypt_block_decrypt(a, b); |
370 |
} |
371 |
|
372 |
WIN32DLL_DEFINE |
373 |
void mcrypt_stream_encrypt(MCRYPT td, void *b, int c) |
374 |
{ |
375 |
void (*_mcrypt_stream_encrypt) (void *, void *, int); |
376 |
char *a; |
377 |
|
378 |
a = td->akey; |
379 |
_mcrypt_stream_encrypt = td->a_encrypt; |
380 |
_mcrypt_stream_encrypt(a, b, c); |
381 |
} |
382 |
|
383 |
WIN32DLL_DEFINE |
384 |
void mcrypt_stream_decrypt(MCRYPT td, void *b, int c) |
385 |
{ |
386 |
void (*_mcrypt_stream_decrypt) (void *, void *, int); |
387 |
char *a; |
388 |
|
389 |
a = td->akey; |
390 |
_mcrypt_stream_decrypt = td->a_decrypt; |
391 |
_mcrypt_stream_decrypt(a, b, c); |
392 |
} |
393 |
|
394 |
WIN32DLL_DEFINE |
395 |
int init_mcrypt(MCRYPT td, void *buf, void *a, int b, void *c) |
396 |
{ |
397 |
int (*_init_mcrypt) (void *, void *, int, void *, int); |
398 |
char *s; |
399 |
|
400 |
s = td->mode_handle; |
401 |
_init_mcrypt = lt_dlsym(s, "_init_mcrypt"); |
402 |
return _init_mcrypt(buf, a, b, c, mcrypt_enc_get_block_size(td)); |
403 |
} |
404 |
|
405 |
WIN32DLL_DEFINE |
406 |
int end_mcrypt(MCRYPT td, void *buf) |
407 |
{ |
408 |
int (*_end_mcrypt) (void *); |
409 |
char *s; |
410 |
|
411 |
s = td->mode_handle; |
412 |
_end_mcrypt = lt_dlsym(s, "_end_mcrypt"); |
413 |
return _end_mcrypt(buf); |
414 |
} |
415 |
|
416 |
WIN32DLL_DEFINE |
417 |
int mcrypt(MCRYPT td, void *buf, void *a, int b) |
418 |
{ |
419 |
int (*_mcrypt) (void *, void *, int, int, void *, void *, void*); |
420 |
_mcrypt = td->m_encrypt; |
421 |
|
422 |
return _mcrypt(buf, a, b, mcrypt_enc_get_block_size(td), td->akey, |
423 |
td->a_encrypt, td->a_decrypt); |
424 |
} |
425 |
|
426 |
WIN32DLL_DEFINE |
427 |
int mdecrypt(MCRYPT td, void *buf, void *a, int b) |
428 |
{ |
429 |
int (*_mdecrypt) (void *, void *, int, int, void *, void *, void*); |
430 |
|
431 |
_mdecrypt = td->m_decrypt; |
432 |
return _mdecrypt(buf, a, b, mcrypt_enc_get_block_size(td), |
433 |
td->akey, td->a_encrypt, td->a_decrypt); |
434 |
} |
435 |
|
436 |
WIN32DLL_DEFINE |
437 |
char *mcrypt_enc_get_modes_name(MCRYPT td) |
438 |
{ |
439 |
char *(*_mcrypt_get_modes_name) (void); |
440 |
char *s; |
441 |
|
442 |
s = td->mode_handle; |
443 |
|
444 |
_mcrypt_get_modes_name = lt_dlsym(s, "_mcrypt_get_modes_name"); |
445 |
return _mcrypt_get_modes_name(); |
446 |
} |
447 |
|
448 |
WIN32DLL_DEFINE |
449 |
int mcrypt_enc_is_block_mode(MCRYPT td) |
450 |
{ |
451 |
int (*_is_block_mode) (void); |
452 |
char *s; |
453 |
|
454 |
s = td->mode_handle; |
455 |
|
456 |
_is_block_mode = lt_dlsym(s, "_is_block_mode"); |
457 |
return _is_block_mode(); |
458 |
} |
459 |
|
460 |
WIN32DLL_DEFINE |
461 |
int mcrypt_enc_mode_has_iv(MCRYPT td) |
462 |
{ |
463 |
int (*_has_iv) (void); |
464 |
char *s; |
465 |
|
466 |
s = td->mode_handle; |
467 |
|
468 |
_has_iv = lt_dlsym(s, "_has_iv"); |
469 |
return _has_iv(); |
470 |
} |
471 |
|
472 |
WIN32DLL_DEFINE |
473 |
int mcrypt_enc_is_block_algorithm_mode(MCRYPT td) |
474 |
{ |
475 |
int (*_is_a_block_mode) (void); |
476 |
char *s; |
477 |
|
478 |
s = td->mode_handle; |
479 |
|
480 |
_is_a_block_mode = lt_dlsym(s, "_is_block_algorithm_mode"); |
481 |
return _is_a_block_mode(); |
482 |
} |
483 |
|
484 |
WIN32DLL_DEFINE |
485 |
int mcrypt_enc_self_test(MCRYPT td) |
486 |
{ |
487 |
int (*_self_test) (void); |
488 |
char *s; |
489 |
|
490 |
s = td->algorithm_handle; |
491 |
|
492 |
_self_test = lt_dlsym(s, "_mcrypt_self_test"); |
493 |
|
494 |
return _self_test(); |
495 |
} |
496 |
|
497 |
WIN32DLL_DEFINE |
498 |
int mcrypt_module_self_test(char *algorithm, char *a_directory) |
499 |
{ |
500 |
int i; |
501 |
lt_dlhandle *_handle; |
502 |
int (*_self_test) (void); |
503 |
char* error; |
504 |
|
505 |
|
506 |
if (lt_dlinit() != 0) { |
507 |
return MCRYPT_UNKNOWN_ERROR; |
508 |
} |
509 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
510 |
|
511 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
512 |
|
513 |
if (!_handle) { |
514 |
error=lt_dlerror(); |
515 |
if (error!=NULL) fputs( error, stderr); |
516 |
fputs("\n", stderr); |
517 |
return MCRYPT_UNKNOWN_ERROR; |
518 |
} |
519 |
|
520 |
_self_test = lt_dlsym(_handle, "_mcrypt_self_test"); |
521 |
|
522 |
i = _self_test(); |
523 |
|
524 |
lt_dlclose(_handle); |
525 |
lt_dlexit(); |
526 |
return i; |
527 |
} |
528 |
|
529 |
WIN32DLL_DEFINE |
530 |
int mcrypt_module_algorithm_version(char *algorithm, char *a_directory) |
531 |
{ |
532 |
int i; |
533 |
lt_dlhandle _handle; |
534 |
int (*_version) (void); |
535 |
char* error; |
536 |
|
537 |
if (lt_dlinit() != 0) { |
538 |
return MCRYPT_UNKNOWN_ERROR; |
539 |
} |
540 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
541 |
|
542 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
543 |
if (!_handle) { |
544 |
error=lt_dlerror(); |
545 |
if (error!=NULL) fputs( error, stderr); |
546 |
fputs("\n", stderr); |
547 |
return MCRYPT_UNKNOWN_ERROR; |
548 |
} |
549 |
|
550 |
_version = lt_dlsym(_handle, "_mcrypt_algorithm_version"); |
551 |
|
552 |
i = _version(); |
553 |
|
554 |
lt_dlclose(_handle); |
555 |
lt_dlexit(); |
556 |
|
557 |
return i; |
558 |
} |
559 |
|
560 |
WIN32DLL_DEFINE |
561 |
int mcrypt_module_mode_version(char *mode, char *m_directory) |
562 |
{ |
563 |
int i; |
564 |
lt_dlhandle *_handle; |
565 |
int (*_version) (void); |
566 |
char* error; |
567 |
|
568 |
if (lt_dlinit() != 0) { |
569 |
return MCRYPT_UNKNOWN_ERROR; |
570 |
} |
571 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
572 |
|
573 |
_handle = mcrypt_dlopen(m_directory, NULL, mode); |
574 |
if (!_handle) { |
575 |
error=lt_dlerror(); |
576 |
if(error!=NULL) fputs(error, stderr); |
577 |
fputs("\n", stderr); |
578 |
return MCRYPT_UNKNOWN_ERROR; |
579 |
} |
580 |
|
581 |
_version = lt_dlsym(_handle, "_mcrypt_mode_version"); |
582 |
|
583 |
i = _version(); |
584 |
|
585 |
lt_dlclose(_handle); |
586 |
lt_dlexit(); |
587 |
|
588 |
return i; |
589 |
} |
590 |
|
591 |
WIN32DLL_DEFINE |
592 |
int mcrypt_module_is_block_algorithm(char *algorithm, char *a_directory) |
593 |
{ |
594 |
int i; |
595 |
lt_dlhandle _handle; |
596 |
int (*_is_block_algorithm) (void); |
597 |
char* error; |
598 |
|
599 |
if (lt_dlinit() != 0) { |
600 |
return MCRYPT_UNKNOWN_ERROR; |
601 |
} |
602 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
603 |
|
604 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
605 |
|
606 |
if (!_handle) { |
607 |
error=lt_dlerror(); |
608 |
if(error!=NULL) fputs( error, stderr); |
609 |
fputs("\n", stderr); |
610 |
return MCRYPT_UNKNOWN_ERROR; |
611 |
} |
612 |
|
613 |
_is_block_algorithm = lt_dlsym(_handle, "_is_block_algorithm"); |
614 |
|
615 |
i = _is_block_algorithm(); |
616 |
|
617 |
lt_dlclose(_handle); |
618 |
lt_dlexit(); |
619 |
|
620 |
return i; |
621 |
} |
622 |
|
623 |
WIN32DLL_DEFINE |
624 |
int mcrypt_module_is_block_algorithm_mode(char *mode, char *m_directory) |
625 |
{ |
626 |
int i; |
627 |
lt_dlhandle *_handle; |
628 |
int (*_is_a_block_mode) (void); |
629 |
char* error; |
630 |
|
631 |
if (lt_dlinit() != 0) { |
632 |
return MCRYPT_UNKNOWN_ERROR; |
633 |
} |
634 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
635 |
|
636 |
_handle = mcrypt_dlopen(m_directory, NULL, mode); |
637 |
if (!_handle) { |
638 |
error=lt_dlerror(); |
639 |
if(error!=NULL) fputs( error, stderr); |
640 |
fputs("\n", stderr); |
641 |
return MCRYPT_UNKNOWN_ERROR; |
642 |
} |
643 |
|
644 |
_is_a_block_mode = lt_dlsym(_handle, "_is_block_algorithm_mode"); |
645 |
|
646 |
i = _is_a_block_mode(); |
647 |
|
648 |
lt_dlclose(_handle); |
649 |
lt_dlexit(); |
650 |
|
651 |
return i; |
652 |
} |
653 |
|
654 |
WIN32DLL_DEFINE |
655 |
int mcrypt_module_is_block_mode(char *mode, char *m_directory) |
656 |
{ |
657 |
int i; |
658 |
lt_dlhandle *_handle; |
659 |
int (*_is_block_mode) (void); |
660 |
char* error; |
661 |
|
662 |
if (lt_dlinit() != 0) { |
663 |
return MCRYPT_UNKNOWN_ERROR; |
664 |
} |
665 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
666 |
|
667 |
_handle = mcrypt_dlopen(m_directory, NULL, mode); |
668 |
if (!_handle) { |
669 |
error=lt_dlerror(); |
670 |
if(error!=NULL) fputs( error, stderr); |
671 |
fputs("\n", stderr); |
672 |
return MCRYPT_UNKNOWN_ERROR; |
673 |
} |
674 |
|
675 |
_is_block_mode = lt_dlsym(_handle, "_is_block_mode"); |
676 |
|
677 |
i = _is_block_mode(); |
678 |
|
679 |
lt_dlclose(_handle); |
680 |
lt_dlexit(); |
681 |
|
682 |
return i; |
683 |
} |
684 |
|
685 |
WIN32DLL_DEFINE |
686 |
int mcrypt_module_get_algo_block_size(char *algorithm, char *a_directory) |
687 |
{ |
688 |
int i; |
689 |
lt_dlhandle _handle; |
690 |
int (*_get_block_size) (void); |
691 |
char* error; |
692 |
|
693 |
if (lt_dlinit() != 0) { |
694 |
return MCRYPT_UNKNOWN_ERROR; |
695 |
} |
696 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
697 |
|
698 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
699 |
if (!_handle) { |
700 |
error=lt_dlerror(); |
701 |
if(error!=NULL) fputs( error, stderr); |
702 |
fputs("\n", stderr); |
703 |
return MCRYPT_UNKNOWN_ERROR; |
704 |
} |
705 |
|
706 |
_get_block_size = lt_dlsym(_handle, "_mcrypt_get_block_size"); |
707 |
|
708 |
i = _get_block_size(); |
709 |
|
710 |
lt_dlclose(_handle); |
711 |
lt_dlexit(); |
712 |
|
713 |
return i; |
714 |
} |
715 |
|
716 |
WIN32DLL_DEFINE |
717 |
int mcrypt_module_get_algo_key_size(char *algorithm, char *a_directory) |
718 |
{ |
719 |
int i; |
720 |
lt_dlhandle _handle; |
721 |
int (*_get_key_size) (void); |
722 |
char* error; |
723 |
|
724 |
if (lt_dlinit() != 0) { |
725 |
return MCRYPT_UNKNOWN_ERROR; |
726 |
} |
727 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
728 |
|
729 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
730 |
if (!_handle) { |
731 |
error=lt_dlerror(); |
732 |
if(error!=NULL) fputs( error, stderr); |
733 |
fputs("\n", stderr); |
734 |
return MCRYPT_UNKNOWN_ERROR; |
735 |
} |
736 |
|
737 |
_get_key_size = lt_dlsym(_handle, "_mcrypt_get_key_size"); |
738 |
|
739 |
i = _get_key_size(); |
740 |
|
741 |
lt_dlclose(_handle); |
742 |
lt_dlexit(); |
743 |
|
744 |
return i; |
745 |
} |
746 |
|
747 |
WIN32DLL_DEFINE |
748 |
int *mcrypt_module_get_algo_supported_key_sizes(char *algorithm, |
749 |
char *a_directory, |
750 |
int *len) |
751 |
{ |
752 |
lt_dlhandle _handle; |
753 |
int *(*_mcrypt_get_key_sizes) (int *); |
754 |
int *size; |
755 |
char* error; |
756 |
|
757 |
if (lt_dlinit() != 0) { |
758 |
*len = 0; |
759 |
return NULL; |
760 |
} |
761 |
/* LTDL_SET_PRELOADED_SYMBOLS(); */ |
762 |
|
763 |
_handle = mcrypt_dlopen(a_directory, NULL, algorithm); |
764 |
if (!_handle) { |
765 |
error=lt_dlerror(); |
766 |
if(error!=NULL) fputs( error, stderr); |
767 |
fputs("\n", stderr); |
768 |
*len = 0; |
769 |
return NULL; |
770 |
} |
771 |
|
772 |
_mcrypt_get_key_sizes = |
773 |
lt_dlsym(_handle, "_mcrypt_get_supported_key_sizes"); |
774 |
|
775 |
size = _mcrypt_get_key_sizes(len); |
776 |
|
777 |
lt_dlclose(_handle); |
778 |
lt_dlexit(); |
779 |
|
780 |
return size; |
781 |
} |