/[mcrypt]/libmcrypt/lib/mcrypt_modules.c
ViewVC logotype

Contents of /libmcrypt/lib/mcrypt_modules.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (show annotations)
Mon Sep 24 14:09:42 2001 UTC (22 years, 6 months ago) by nmav
Branch: MAIN
CVS Tags: libmcrypt_2_4_17
Changes since 1.23: +4 -3 lines
File MIME type: text/plain
bug fix

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26