/[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.30 - (show annotations)
Sat Jul 6 10:18:18 2002 UTC (21 years, 9 months ago) by nmav
Branch: MAIN
CVS Tags: libmcrypt_2_5_3
Changes since 1.29: +23 -22 lines
File MIME type: text/plain
introduced the use of the const keyword in the exported functions

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26