/[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.36 - (show annotations)
Sun Dec 22 17:56:02 2002 UTC (18 years, 3 months ago) by nmav
Branch: MAIN
CVS Tags: libmcrypt_2_5_7, libmcrypt_2_5_6, libmcrypt_2_5_5, libmcrypt_2_5_5rc1, HEAD
Changes since 1.35: +0 -4 lines
File MIME type: text/plain
some fixes for ecb mode to work.

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[1539];
131
132 if (!filename || !(*filename)) {
133 return MCRYPT_FAILED;
134 }
135
136 if (strlen(filename) >= sizeof( handle->name))
137 return MCRYPT_FAILED;
138 else
139 strcpy( handle->name, filename);
140
141 if (_mcrypt_search_symlist_lib(filename)!=NULL) {
142 handle->handle = MCRYPT_INTERNAL_HANDLER;
143 return handle->handle;
144 }
145
146 *paths = '\0';
147 if (a_directory != NULL) {
148 strncat( paths, a_directory, 512);
149 strcat( paths, ":");
150 }
151 if (m_directory != NULL) {
152 strncat( paths, m_directory, 512);
153 strcat( paths, ":");
154 }
155 strncat( paths, LIBDIR, 512);
156
157 lt_dlsetsearchpath(paths);
158
159 handle->handle = lt_dlopenext(filename);
160
161 return handle->handle;
162
163 }
164
165 WIN32DLL_DEFINE
166 MCRYPT mcrypt_module_open(const char *algorithm,
167 const char *a_directory, const char *mode,
168 const char *m_directory)
169 {
170 MCRYPT td;
171 const char* err;
172 void *ret;
173
174 td = calloc(1, sizeof(CRYPT_STREAM));
175 if (td==NULL) return MCRYPT_FAILED;
176
177 if (lt_dlinit() != 0) {
178 return MCRYPT_FAILED;
179 }
180
181 ret = mcrypt_dlopen( &td->algorithm_handle, a_directory, m_directory, algorithm);
182 if (ret == NULL) {
183 err=lt_dlerror();
184 if (err!=NULL) {
185 fputs( err, stderr);
186 fputs("\n", stderr);
187 }
188 free(td);
189 lt_dlexit();
190 return MCRYPT_FAILED;
191 }
192
193 ret = mcrypt_dlopen( &td->mode_handle, a_directory, m_directory, mode);
194
195 if (ret == NULL) {
196 err=lt_dlerror();
197 if (err!=NULL) {
198 fputs( err, stderr);
199 fputs( "\n", stderr);
200 }
201 mcrypt_dlclose(td->algorithm_handle);
202 free(td);
203 lt_dlexit();
204 return MCRYPT_FAILED;
205 }
206
207 td->a_encrypt = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_encrypt");
208 td->a_decrypt = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_decrypt");
209 td->m_encrypt = mcrypt_dlsym(td->mode_handle, "_mcrypt");
210 td->m_decrypt = mcrypt_dlsym(td->mode_handle, "_mdecrypt");
211 td->a_block_size =
212 mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_block_size");
213
214 if (td->a_encrypt == NULL || td->a_decrypt == NULL|| td->m_encrypt == NULL||
215 td->m_decrypt == NULL|| td->a_block_size == NULL) {
216 err=lt_dlerror();
217 if (err!=NULL) {
218 fputs( err, stderr);
219 fputs( "\n", stderr);
220 }
221 mcrypt_dlclose(td->algorithm_handle);
222 free(td);
223 lt_dlexit();
224 return MCRYPT_FAILED;
225 }
226
227 if (mcrypt_enc_is_block_algorithm_mode(td) !=
228 mcrypt_enc_is_block_algorithm(td)) {
229 mcrypt_module_close(td);
230 return MCRYPT_FAILED;
231 }
232
233 return td;
234 }
235
236
237
238 /* Modules' frontends */
239
240 WIN32DLL_DEFINE
241 int mcrypt_get_size(MCRYPT td)
242 {
243 int (*_mcrypt_get_size) (void);
244
245 const char *error;
246
247 _mcrypt_get_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_size");
248 if (_mcrypt_get_size == NULL) {
249 error = lt_dlerror();
250 if (error!=NULL) {
251 fputs(error, stderr);
252 fputs("\n", stderr);
253 }
254 return MCRYPT_UNKNOWN_ERROR;
255 }
256 return _mcrypt_get_size();
257 }
258
259 WIN32DLL_DEFINE
260 int mcrypt_mode_get_size(MCRYPT td)
261 {
262 int (*_mcrypt_get_size) (void);
263
264 const char *error;
265
266 _mcrypt_get_size = mcrypt_dlsym(td->mode_handle, "_mcrypt_mode_get_size");
267 if (_mcrypt_get_size == NULL) {
268 error = lt_dlerror();
269 if (error!=NULL) {
270 fputs(error, stderr);
271 fputs("\n", stderr);
272 }
273 return MCRYPT_UNKNOWN_ERROR;
274 }
275 return _mcrypt_get_size();
276 }
277
278 WIN32DLL_DEFINE
279 int mcrypt_set_key(MCRYPT td, void *a, const void *key, int keysize, const void *iv, int e)
280 {
281 int (*__mcrypt_set_key_stream) (void *, const void *, int, const void *, int);
282 int (*__mcrypt_set_key_block) (void *, const void *, int);
283 const char *error;
284
285 if (mcrypt_enc_is_block_algorithm(td) == 0) {
286 /* stream */
287 __mcrypt_set_key_stream = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_set_key");
288 if (__mcrypt_set_key_stream == NULL) {
289 error = lt_dlerror();
290 if (error!=NULL) {
291 fputs(error, stderr);
292 fputs("\n", stderr);
293 }
294 return -2;
295 }
296 return __mcrypt_set_key_stream(a, key, keysize, iv, e);
297 } else {
298 __mcrypt_set_key_block = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_set_key");
299 if (__mcrypt_set_key_block == NULL) {
300 error = lt_dlerror();
301 if (error!=NULL) {
302 fputs(error, stderr);
303 fputs("\n", stderr);
304 }
305 return -2;
306 }
307 return __mcrypt_set_key_block(a, key, keysize);
308 }
309 }
310
311 WIN32DLL_DEFINE
312 int mcrypt_enc_set_state(MCRYPT td, const void *iv, int size)
313 {
314 int (*__mcrypt_set_state) (void *, const void *, int);
315 const char *error;
316
317 __mcrypt_set_state = mcrypt_dlsym(td->mode_handle, "_mcrypt_set_state");
318 if (__mcrypt_set_state==NULL) {
319 error = lt_dlerror();
320 if (error!=NULL) {
321 fputs(error, stderr);
322 fputs("\n", stderr);
323 }
324 return MCRYPT_UNKNOWN_ERROR;
325 }
326 return __mcrypt_set_state(td->abuf, iv, size);
327 }
328
329 WIN32DLL_DEFINE
330 int mcrypt_enc_get_state(MCRYPT td, void *iv, int *size)
331 {
332 int (*__mcrypt_get_state) (void *, void *, int*);
333 const char *error;
334
335 __mcrypt_get_state = mcrypt_dlsym(td->mode_handle, "_mcrypt_get_state");
336 if (__mcrypt_get_state==NULL) {
337 error = lt_dlerror();
338 if (error!=NULL) {
339 fputs(error, stderr);
340 fputs("\n", stderr);
341 }
342 return MCRYPT_UNKNOWN_ERROR;
343 }
344 return __mcrypt_get_state(td->abuf, iv, size);
345 }
346
347
348 WIN32DLL_DEFINE
349 int mcrypt_enc_get_block_size(MCRYPT td)
350 {
351 int (*_mcrypt_get_block_size) (void);
352
353 _mcrypt_get_block_size = td->a_block_size;
354 return _mcrypt_get_block_size();
355 }
356
357 WIN32DLL_DEFINE
358 int mcrypt_get_algo_iv_size(MCRYPT td)
359 {
360 const char* error;
361 int (*_mcrypt_get_algo_iv_size) (void);
362
363 _mcrypt_get_algo_iv_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_algo_iv_size");
364 if (_mcrypt_get_algo_iv_size == NULL) {
365 error = lt_dlerror();
366 if (error!=NULL) {
367 fputs(error, stderr);
368 fputs("\n", stderr);
369 }
370 return MCRYPT_UNKNOWN_ERROR;
371 }
372 return _mcrypt_get_algo_iv_size();
373 }
374
375 WIN32DLL_DEFINE
376 int mcrypt_enc_get_iv_size(MCRYPT td)
377 {
378 if (mcrypt_enc_is_block_algorithm_mode(td) == 1) {
379 return mcrypt_enc_get_block_size(td);
380 } else {
381 return mcrypt_get_algo_iv_size(td);
382 }
383 }
384
385 WIN32DLL_DEFINE
386 int mcrypt_enc_get_key_size(MCRYPT td)
387 {
388 const char* error;
389 int (*_mcrypt_get_key_size) (void);
390
391 _mcrypt_get_key_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_key_size");
392 if (_mcrypt_get_key_size == NULL) {
393 error = lt_dlerror();
394 if (error!=NULL) {
395 fputs(error, stderr);
396 fputs("\n", stderr);
397 }
398 return MCRYPT_UNKNOWN_ERROR;
399 }
400 return _mcrypt_get_key_size();
401 }
402
403 WIN32DLL_DEFINE
404 int *mcrypt_enc_get_supported_key_sizes(MCRYPT td, int *len)
405 {
406 int *(*_mcrypt_get_key_sizes) (int *);
407 int *size, *ret;
408 const char* error;
409
410 _mcrypt_get_key_sizes =
411 mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_supported_key_sizes");
412 if (_mcrypt_get_key_sizes == NULL) {
413 error = lt_dlerror();
414 if (error!=NULL) {
415 fputs(error, stderr);
416 fputs("\n", stderr);
417 }
418 *len = 0;
419 return NULL;
420 }
421
422 size = _mcrypt_get_key_sizes(len);
423
424 ret = NULL;
425 if (size!=NULL && (*len) != 0) {
426 ret = malloc( sizeof(int)*(*len));
427 if (ret==NULL) return NULL;
428 memcpy( ret, size, sizeof(int)*(*len));
429 }
430 return ret;
431 }
432
433 WIN32DLL_DEFINE
434 int mcrypt_enc_is_block_algorithm(MCRYPT td)
435 {
436 int (*_is_block_algorithm) (void);
437 const char* error;
438
439 _is_block_algorithm = mcrypt_dlsym(td->algorithm_handle, "_is_block_algorithm");
440 if (_is_block_algorithm == NULL) {
441 error = lt_dlerror();
442 if (error!=NULL) {
443 fputs(error, stderr);
444 fputs("\n", stderr);
445 }
446 return MCRYPT_UNKNOWN_ERROR;
447 }
448
449 return _is_block_algorithm();
450 }
451
452 WIN32DLL_DEFINE
453 char *mcrypt_enc_get_algorithms_name(MCRYPT td)
454 {
455 const char *(*_mcrypt_get_algorithms_name) (void);
456 const char* error;
457
458 _mcrypt_get_algorithms_name =
459 mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_algorithms_name");
460 if (_mcrypt_get_algorithms_name == NULL) {
461 error = lt_dlerror();
462 if (error!=NULL) {
463 fputs(error, stderr);
464 fputs("\n", stderr);
465 }
466 return NULL;
467 }
468
469 return strdup(_mcrypt_get_algorithms_name());
470 }
471
472 WIN32DLL_DEFINE
473 int init_mcrypt(MCRYPT td, void *buf, const void *key, int keysize, const void *iv)
474 {
475 int (*_init_mcrypt) (void *, const void *, int, const void *, int);
476 const char* error;
477
478 _init_mcrypt = mcrypt_dlsym(td->mode_handle, "_init_mcrypt");
479 if (_init_mcrypt == NULL) {
480 error = lt_dlerror();
481 if (error!=NULL) {
482 fputs(error, stderr);
483 fputs("\n", stderr);
484 }
485 return MCRYPT_UNKNOWN_ERROR;
486 }
487
488 return _init_mcrypt(buf, key, keysize, iv, mcrypt_enc_get_block_size(td));
489 }
490
491 WIN32DLL_DEFINE
492 int end_mcrypt(MCRYPT td, void *buf)
493 {
494 int (*_end_mcrypt) (void *);
495 const char* error;
496
497 _end_mcrypt = mcrypt_dlsym(td->mode_handle, "_end_mcrypt");
498 if (_end_mcrypt == NULL) {
499 error = lt_dlerror();
500 if (error!=NULL) {
501 fputs(error, stderr);
502 fputs("\n", stderr);
503 }
504 return MCRYPT_UNKNOWN_ERROR;
505 }
506
507 return _end_mcrypt(buf);
508 }
509
510 WIN32DLL_DEFINE
511 int mcrypt(MCRYPT td, void *buf, void *a, int b)
512 {
513 int (*_mcrypt) (void *, void *, int, int, void *, void *, void*);
514
515 _mcrypt = td->m_encrypt;
516
517 return _mcrypt(buf, a, b, mcrypt_enc_get_block_size(td), td->akey,
518 td->a_encrypt, td->a_decrypt);
519 }
520
521 WIN32DLL_DEFINE
522 int mdecrypt(MCRYPT td, void *buf, void *a, int b)
523 {
524 int (*_mdecrypt) (void *, void *, int, int, void *, void *, void*);
525
526 _mdecrypt = td->m_decrypt;
527 return _mdecrypt(buf, a, b, mcrypt_enc_get_block_size(td),
528 td->akey, td->a_encrypt, td->a_decrypt);
529 }
530
531 WIN32DLL_DEFINE
532 char *mcrypt_enc_get_modes_name(MCRYPT td)
533 {
534 const char *(*_mcrypt_get_modes_name) (void);
535 const char* error;
536
537 _mcrypt_get_modes_name = mcrypt_dlsym(td->mode_handle, "_mcrypt_get_modes_name");
538 if (_mcrypt_get_modes_name == NULL) {
539 error = lt_dlerror();
540 if (error!=NULL) {
541 fputs(error, stderr);
542 fputs("\n", stderr);
543 }
544 return NULL;
545 }
546
547 return strdup(_mcrypt_get_modes_name());
548 }
549
550 WIN32DLL_DEFINE
551 int mcrypt_enc_is_block_mode(MCRYPT td)
552 {
553 int (*_is_block_mode) (void);
554 const char* error;
555
556 _is_block_mode = mcrypt_dlsym(td->mode_handle, "_is_block_mode");
557 if (_is_block_mode == NULL) {
558 error = lt_dlerror();
559 if (error!=NULL) {
560 fputs(error, stderr);
561 fputs("\n", stderr);
562 }
563 return MCRYPT_UNKNOWN_ERROR;
564 }
565
566 return _is_block_mode();
567 }
568
569 WIN32DLL_DEFINE
570 int mcrypt_enc_mode_has_iv(MCRYPT td)
571 {
572 int (*_has_iv) (void);
573 const char* error;
574
575 _has_iv = mcrypt_dlsym(td->mode_handle, "_has_iv");
576 if (_has_iv == NULL) {
577 error = lt_dlerror();
578 if (error!=NULL) {
579 fputs(error, stderr);
580 fputs("\n", stderr);
581 }
582 return MCRYPT_UNKNOWN_ERROR;
583 }
584
585 return _has_iv();
586 }
587
588 WIN32DLL_DEFINE
589 int mcrypt_enc_is_block_algorithm_mode(MCRYPT td)
590 {
591 int (*_is_a_block_mode) (void);
592 const char* error;
593
594 _is_a_block_mode = mcrypt_dlsym(td->mode_handle, "_is_block_algorithm_mode");
595 if (_is_a_block_mode == NULL) {
596 error = lt_dlerror();
597 if (error!=NULL) {
598 fputs(error, stderr);
599 fputs("\n", stderr);
600 }
601 return MCRYPT_UNKNOWN_ERROR;
602 }
603
604 return _is_a_block_mode();
605 }
606
607 WIN32DLL_DEFINE
608 int mcrypt_enc_self_test(MCRYPT td)
609 {
610 int (*_self_test) (void);
611 const char* error;
612
613 _self_test = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_self_test");
614 if (_self_test == NULL) {
615 error = lt_dlerror();
616 if (error!=NULL) {
617 fputs(error, stderr);
618 fputs("\n", stderr);
619 }
620 return MCRYPT_UNKNOWN_ERROR;
621 }
622
623 return _self_test();
624 }
625
626 WIN32DLL_DEFINE
627 int mcrypt_module_self_test(const char *algorithm, const char *a_directory)
628 {
629 int i;
630 void* rr;
631 mcrypt_dlhandle _handle;
632 int (*_self_test) (void);
633 const char* error;
634
635 if (lt_dlinit() != 0) {
636 return MCRYPT_UNKNOWN_ERROR;
637 }
638
639 rr = mcrypt_dlopen(&_handle, a_directory, NULL, algorithm);
640
641 if (!rr) {
642 error=lt_dlerror();
643 if (error!=NULL) {
644 fputs( error, stderr);
645 fputs("\n", stderr);
646 }
647 lt_dlexit();
648 return MCRYPT_UNKNOWN_ERROR;
649 }
650
651 _self_test = mcrypt_dlsym(_handle, "_mcrypt_self_test");
652 if (_self_test == NULL) {
653 mcrypt_dlclose(_handle);
654 lt_dlexit();
655 return MCRYPT_UNKNOWN_ERROR;
656 }
657
658 i = _self_test();
659
660 mcrypt_dlclose(_handle);
661 if (lt_dlexit() != 0) {
662 return MCRYPT_UNKNOWN_ERROR;
663 }
664
665 return i;
666 }
667
668 WIN32DLL_DEFINE
669 int mcrypt_module_algorithm_version(const char *algorithm, const char *a_directory)
670 {
671 int i;
672 mcrypt_dlhandle _handle;
673 int (*_version) (void);
674 const char* error;
675 void* rr;
676
677 if (lt_dlinit() != 0) {
678 return MCRYPT_UNKNOWN_ERROR;
679 }
680
681 rr = mcrypt_dlopen(&_handle, a_directory, NULL, algorithm);
682 if (!rr) {
683 error=lt_dlerror();
684 if (error!=NULL) {
685 fputs( error, stderr);
686 fputs("\n", stderr);
687 }
688 lt_dlexit();
689 return MCRYPT_UNKNOWN_ERROR;
690 }
691
692 _version = mcrypt_dlsym(_handle, "_mcrypt_algorithm_version");
693 if (_version==NULL) {
694 mcrypt_dlclose(_handle);
695 lt_dlexit();
696 return MCRYPT_UNKNOWN_ERROR;
697 }
698
699 i = _version();
700
701 mcrypt_dlclose(_handle);
702 if (lt_dlexit() != 0) {
703 return MCRYPT_UNKNOWN_ERROR;
704 }
705
706 return i;
707 }
708
709 WIN32DLL_DEFINE
710 int mcrypt_module_mode_version(const char *mode, const char *m_directory)
711 {
712 int i;
713 mcrypt_dlhandle _handle;
714 int (*_version) (void);
715 const char* error;
716 void * rr;
717
718 if (lt_dlinit() != 0) {
719 return MCRYPT_UNKNOWN_ERROR;
720 }
721
722 rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode);
723 if (!rr) {
724 error=lt_dlerror();
725 if(error!=NULL) {
726 fputs(error, stderr);
727 fputs("\n", stderr);
728 }
729 lt_dlexit();
730 return MCRYPT_UNKNOWN_ERROR;
731 }
732
733 _version = mcrypt_dlsym( _handle, "_mcrypt_mode_version");
734 if (_version==NULL) {
735 mcrypt_dlclose(_handle);
736 lt_dlexit();
737 return MCRYPT_UNKNOWN_ERROR;
738 }
739
740 i = _version();
741
742 mcrypt_dlclose(_handle);
743 if (lt_dlexit() != 0) {
744 return MCRYPT_UNKNOWN_ERROR;
745 }
746
747 return i;
748 }
749
750 WIN32DLL_DEFINE
751 int mcrypt_module_is_block_algorithm(const char *algorithm, const char *a_directory)
752 {
753 int i;
754 mcrypt_dlhandle _handle;
755 int (*_is_block_algorithm) (void);
756 const char* error;
757 void * rr;
758
759 if (lt_dlinit() != 0) {
760 return MCRYPT_UNKNOWN_ERROR;
761 }
762
763 rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
764 if (!rr) {
765 error=lt_dlerror();
766 if(error!=NULL) {
767 fputs( error, stderr);
768 fputs("\n", stderr);
769 }
770 lt_dlexit();
771 return MCRYPT_UNKNOWN_ERROR;
772 }
773
774 _is_block_algorithm = mcrypt_dlsym(_handle, "_is_block_algorithm");
775 if (_is_block_algorithm==NULL) {
776 mcrypt_dlclose(_handle);
777 lt_dlexit();
778 return MCRYPT_UNKNOWN_ERROR;
779 }
780
781 i = _is_block_algorithm();
782
783 mcrypt_dlclose(_handle);
784 if (lt_dlexit() != 0) {
785 return MCRYPT_UNKNOWN_ERROR;
786 }
787
788 return i;
789 }
790
791 WIN32DLL_DEFINE
792 int mcrypt_module_is_block_algorithm_mode(const char *mode, const char *m_directory)
793 {
794 int i;
795 mcrypt_dlhandle _handle;
796 int (*_is_a_block_mode) (void);
797 const char* error;
798 void * rr;
799
800 if (lt_dlinit() != 0) {
801 return MCRYPT_UNKNOWN_ERROR;
802 }
803
804 rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode);
805 if (!rr) {
806 error=lt_dlerror();
807 if(error!=NULL) {
808 fputs( error, stderr);
809 fputs("\n", stderr);
810 }
811 lt_dlexit();
812 return MCRYPT_UNKNOWN_ERROR;
813 }
814
815 _is_a_block_mode = mcrypt_dlsym(_handle, "_is_block_algorithm_mode");
816 if (_is_a_block_mode==NULL) {
817 mcrypt_dlclose(_handle);
818 lt_dlexit();
819 return MCRYPT_UNKNOWN_ERROR;
820 }
821
822 i = _is_a_block_mode();
823
824 mcrypt_dlclose(_handle);
825 if (lt_dlexit() != 0) {
826 return MCRYPT_UNKNOWN_ERROR;
827 }
828
829 return i;
830 }
831
832 WIN32DLL_DEFINE
833 int mcrypt_module_is_block_mode(const char *mode, const char *m_directory)
834 {
835 void * rr;
836 int i;
837 mcrypt_dlhandle _handle;
838 int (*_is_block_mode) (void);
839 const char* error;
840
841 if (lt_dlinit() != 0) {
842 return MCRYPT_UNKNOWN_ERROR;
843 }
844
845 rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode);
846 if (!rr) {
847 error=lt_dlerror();
848 if(error!=NULL) {
849 fputs( error, stderr);
850 fputs("\n", stderr);
851 }
852 lt_dlexit();
853 return MCRYPT_UNKNOWN_ERROR;
854 }
855
856 _is_block_mode = mcrypt_dlsym(_handle, "_is_block_mode");
857 if (_is_block_mode==NULL) {
858 mcrypt_dlclose(_handle);
859 lt_dlexit();
860 return MCRYPT_UNKNOWN_ERROR;
861 }
862
863 i = _is_block_mode();
864
865 mcrypt_dlclose(_handle);
866 if (lt_dlexit() != 0) {
867 return MCRYPT_UNKNOWN_ERROR;
868 }
869
870 return i;
871 }
872
873 WIN32DLL_DEFINE
874 int mcrypt_module_get_algo_block_size(const char *algorithm, const char *a_directory)
875 {
876 int i;
877 mcrypt_dlhandle _handle;
878 int (*_get_block_size) (void);
879 const char* error;
880 void * rr;
881
882 if (lt_dlinit() != 0) {
883 return MCRYPT_UNKNOWN_ERROR;
884 }
885
886 rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
887 if (!rr) {
888 error=lt_dlerror();
889 if(error!=NULL) {
890 fputs( error, stderr);
891 fputs("\n", stderr);
892 }
893 lt_dlexit();
894 return MCRYPT_UNKNOWN_ERROR;
895 }
896
897 _get_block_size = mcrypt_dlsym(_handle, "_mcrypt_get_block_size");
898 if (_get_block_size==NULL) {
899 mcrypt_dlclose(_handle);
900 lt_dlexit();
901 return MCRYPT_UNKNOWN_ERROR;
902 }
903
904 i = _get_block_size();
905
906 mcrypt_dlclose(_handle);
907 if (lt_dlexit() != 0) {
908 return MCRYPT_UNKNOWN_ERROR;
909 }
910
911 return i;
912 }
913
914 WIN32DLL_DEFINE
915 int mcrypt_module_get_algo_key_size(const char *algorithm, const char *a_directory)
916 {
917 int i;
918 mcrypt_dlhandle _handle;
919 int (*_get_key_size) (void);
920 const char* error;
921 void * rr;
922
923 if (lt_dlinit() != 0) {
924 return MCRYPT_UNKNOWN_ERROR;
925 }
926
927 rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
928 if (!rr) {
929 error=lt_dlerror();
930 if(error!=NULL) {
931 fputs( error, stderr);
932 fputs("\n", stderr);
933 }
934 lt_dlexit();
935 return MCRYPT_UNKNOWN_ERROR;
936 }
937
938 _get_key_size = mcrypt_dlsym(_handle, "_mcrypt_get_key_size");
939 if (_get_key_size==NULL) {
940 mcrypt_dlclose(_handle);
941 lt_dlexit();
942 return MCRYPT_UNKNOWN_ERROR;
943 }
944
945 i = _get_key_size();
946
947 mcrypt_dlclose(_handle);
948 if (lt_dlexit() != 0) {
949 return MCRYPT_UNKNOWN_ERROR;
950 }
951
952 return i;
953 }
954
955 WIN32DLL_DEFINE
956 int *mcrypt_module_get_algo_supported_key_sizes(const char *algorithm,
957 const char *a_directory,
958 int *len)
959 {
960 mcrypt_dlhandle _handle;
961 int *(*_mcrypt_get_key_sizes) (int *);
962 int *size;
963 int * ret_size;
964 const char* error;
965 void * rr;
966
967
968 if (lt_dlinit() != 0) {
969 *len = 0;
970 return NULL;
971 }
972
973 rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
974 if (!rr) {
975 error=lt_dlerror();
976 if(error!=NULL) {
977 fputs( error, stderr);
978 fputs("\n", stderr);
979 }
980 lt_dlexit();
981 *len = 0;
982 return NULL;
983 }
984
985 _mcrypt_get_key_sizes =
986 mcrypt_dlsym(_handle, "_mcrypt_get_supported_key_sizes");
987 if (_mcrypt_get_key_sizes==NULL) {
988 mcrypt_dlclose(_handle);
989 lt_dlexit();
990 *len = 0;
991 return NULL;
992 }
993
994 ret_size = NULL;
995 size = _mcrypt_get_key_sizes(len);
996 if (*len!=0 && size!=NULL) {
997 ret_size = malloc( (*len)*sizeof(int));
998 if (ret_size!=NULL) {
999 memcpy( ret_size, size, (*len)*sizeof(int));
1000 }
1001 } else *len = 0;
1002
1003 mcrypt_dlclose(_handle);
1004 if (lt_dlexit() != 0) {
1005 return NULL;
1006 }
1007
1008 return ret_size;
1009 }
1010
1011 /* Returns false(0) if the library has not been compiled
1012 * with dynamic module support.
1013 */
1014 int mcrypt_module_support_dynamic(void) {
1015 #ifdef USE_LTDL
1016 return 1;
1017 #else
1018 return 0;
1019 #endif
1020
1021 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26