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

Diff of /libmcrypt/lib/mcrypt_modules.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by nmav, Mon May 22 13:07:53 2000 UTC revision 1.36 by nmav, Sun Dec 22 17:56:02 2002 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 1998,1999,2000 Nikos Mavroyanopoulos   * Copyright (C) 1998,1999,2000,2001 Nikos Mavroyanopoulos
3   *   *
4   * This library is free software; you can redistribute it and/or modify it   * 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   * under the terms of the GNU Library General Public License as published
# Line 25  Line 25 
25  #include <mcrypt_internal.h>  #include <mcrypt_internal.h>
26  #include <xmemory.h>  #include <xmemory.h>
27    
28  #if 0  #ifndef DEBUG
29  extern int preloaded_symbols;  # define fputs(x, y)
30  #endif  #endif
31    
32  int mcrypt_module_close(MCRYPT td)  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          lt_dlclose(td->algorithm_handle);          if (mod!=MCRYPT_INTERNAL_HANDLER && mod!=NULL)
89          lt_dlclose(td->mode_handle);                  lt_dlclose(mod);
90          lt_dlexit();          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          td->algorithm_handle = NULL;  WIN32DLL_DEFINE
106          td->mode_handle = NULL;  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;          td->m_encrypt = NULL;
117          td->a_encrypt = NULL;          td->a_encrypt = NULL;
118          td->a_decrypt = NULL;          td->a_decrypt = NULL;
119          td->m_decrypt = NULL;          td->m_decrypt = NULL;
120    
121            free(td);
122            
123          return 0;          return 0;
124  }  }
125    
 #if 0  
 int mcrypt_modules_preopen()  
 {  
126    
127          if (preloaded_symbols==0) {  WIN32DLL_DEFINE
128                  preloaded_symbols = 1;  void* mcrypt_dlopen ( mcrypt_dlhandle* handle, const char* a_directory, const char *m_directory, const char *filename) {
129                  LTDL_SET_PRELOADED_SYMBOLS();          
130            char paths[1539];
131    
132            if (!filename || !(*filename)) {
133                    return MCRYPT_FAILED;
134          }          }
135    
136          return 0;          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  }  }
 #endif  
164    
165  MCRYPT mcrypt_module_open(char *algorithm,  WIN32DLL_DEFINE
166                            char *a_directory, char *mode, char *m_directory)  MCRYPT mcrypt_module_open(const char *algorithm,
167                              const char *a_directory, const char *mode,
168                              const char *m_directory)
169  {  {
170          MCRYPT td;          MCRYPT td;
171            const char* err;
172            void *ret;
173            
174          td = calloc(1, sizeof(CRYPT_STREAM));          td = calloc(1, sizeof(CRYPT_STREAM));
175            if (td==NULL) return MCRYPT_FAILED;
176    
177          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
178                  return MCRYPT_FAILED;                  return MCRYPT_FAILED;
179          }          }
180    
181          if (a_directory != NULL)          ret = mcrypt_dlopen( &td->algorithm_handle, a_directory, m_directory, algorithm);
182                  lt_dladdsearchdir(a_directory);          if (ret == NULL) {
183          if (m_directory != NULL)                  err=lt_dlerror();
184                  lt_dladdsearchdir(m_directory);                  if (err!=NULL) {
185          lt_dladdsearchdir(LIBDIR);                          fputs( err, stderr);
186                            fputs("\n", stderr);
187  /*      LTDL_SET_PRELOADED_SYMBOLS(); */                  }
188                    free(td);
189          td->algorithm_handle = lt_dlopenext(algorithm);                  lt_dlexit();
         if (td->algorithm_handle == NULL) {  
                 fputs(lt_dlerror(), stderr);  
                 fputs("\n", stderr);  
190                  return MCRYPT_FAILED;                  return MCRYPT_FAILED;
191          }          }
192    
193          td->mode_handle = lt_dlopenext(mode);          ret = mcrypt_dlopen( &td->mode_handle, a_directory, m_directory, mode);
194    
195          if (td->mode_handle == NULL) {          if (ret == NULL) {
196                  fputs(lt_dlerror(), stderr);                  err=lt_dlerror();
197                  fputs("\n", stderr);                  if (err!=NULL) {
198                  lt_dlclose(td->algorithm_handle);                          fputs( err, stderr);
199                            fputs( "\n", stderr);
200                    }
201                    mcrypt_dlclose(td->algorithm_handle);
202                    free(td);
203                    lt_dlexit();
204                  return MCRYPT_FAILED;                  return MCRYPT_FAILED;
205          }          }
206    
207          td->a_encrypt = lt_dlsym(td->algorithm_handle, "_mcrypt_encrypt");          td->a_encrypt = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_encrypt");
208          td->a_decrypt = lt_dlsym(td->algorithm_handle, "_mcrypt_decrypt");          td->a_decrypt = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_decrypt");
209          td->m_encrypt = lt_dlsym(td->mode_handle, "_mcrypt");          td->m_encrypt = mcrypt_dlsym(td->mode_handle, "_mcrypt");
210          td->m_decrypt = lt_dlsym(td->mode_handle, "_mdecrypt");          td->m_decrypt = mcrypt_dlsym(td->mode_handle, "_mdecrypt");
211          td->a_block_size =          td->a_block_size =
212              lt_dlsym(td->algorithm_handle, "_mcrypt_get_block_size");              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) !=          if (mcrypt_enc_is_block_algorithm_mode(td) !=
228              mcrypt_enc_is_block_algorithm(td)) {              mcrypt_enc_is_block_algorithm(td)) {
# Line 115  MCRYPT mcrypt_module_open(char *algorith Line 237  MCRYPT mcrypt_module_open(char *algorith
237    
238  /* Modules' frontends */  /* Modules' frontends */
239    
240    WIN32DLL_DEFINE
241  int mcrypt_get_size(MCRYPT td)  int mcrypt_get_size(MCRYPT td)
242  {  {
243          int (*_mcrypt_get_size) (void);          int (*_mcrypt_get_size) (void);
244    
245          const char *error;          const char *error;
         char *s;  
246    
247          s = td->algorithm_handle;          _mcrypt_get_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_size");
248          _mcrypt_get_size = lt_dlsym(s, "_mcrypt_get_size");          if (_mcrypt_get_size == NULL) {
249          if ((error = lt_dlerror())) {                  error = lt_dlerror();
250                  fputs(error, stderr);                  if (error!=NULL) {
251                  fputs("\n", stderr);                          fputs(error, stderr);
252                            fputs("\n", stderr);
253                    }
254                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
255          }          }
256          return _mcrypt_get_size();          return _mcrypt_get_size();
257  }  }
258    
259    WIN32DLL_DEFINE
260  int mcrypt_mode_get_size(MCRYPT td)  int mcrypt_mode_get_size(MCRYPT td)
261  {  {
262          int (*_mcrypt_get_size) (void);          int (*_mcrypt_get_size) (void);
263    
264          const char *error;          const char *error;
         char *s;  
265    
266          s = td->mode_handle;          _mcrypt_get_size = mcrypt_dlsym(td->mode_handle, "_mcrypt_mode_get_size");
267          _mcrypt_get_size = lt_dlsym(s, "_mcrypt_mode_get_size");          if (_mcrypt_get_size == NULL) {
268          if ((error = lt_dlerror())) {                  error = lt_dlerror();
269                  fputs(error, stderr);                  if (error!=NULL) {
270                  fputs("\n", stderr);                          fputs(error, stderr);
271                            fputs("\n", stderr);
272                    }
273                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
274          }          }
275          return _mcrypt_get_size();          return _mcrypt_get_size();
276  }  }
277    
278  void mcrypt_set_key(MCRYPT td, void *a, void *b, int c, void *d, int e)  WIN32DLL_DEFINE
279    int mcrypt_set_key(MCRYPT td, void *a, const void *key, int keysize, const void *iv, int e)
280  {  {
281          void (*__mcrypt_set_key_stream) (void *, void *, int, void *, int);          int (*__mcrypt_set_key_stream) (void *, const void *, int, const void *, int);
282          void (*__mcrypt_set_key_block) (void *, void *, int);          int (*__mcrypt_set_key_block) (void *, const void *, int);
283          const char *error;          const char *error;
         char *s;  
284    
         s = td->algorithm_handle;  
285          if (mcrypt_enc_is_block_algorithm(td) == 0) {          if (mcrypt_enc_is_block_algorithm(td) == 0) {
286                  /* stream */                  /* stream */
287                  __mcrypt_set_key_stream = lt_dlsym(s, "_mcrypt_set_key");                  __mcrypt_set_key_stream = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_set_key");
288                  if ((error = lt_dlerror())) {                  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);                          fputs(error, stderr);
322                          fputs("\n", stderr);                          fputs("\n", stderr);
                         return;  
323                  }                  }
324                  __mcrypt_set_key_stream(a, b, c, d, e);                  return MCRYPT_UNKNOWN_ERROR;
325          } else {          }
326                  __mcrypt_set_key_block = lt_dlsym(s, "_mcrypt_set_key");          return __mcrypt_set_state(td->abuf, iv, size);
327                  if ((error = lt_dlerror())) {  }
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);                          fputs(error, stderr);
340                          fputs("\n", stderr);                          fputs("\n", stderr);
                         return;  
341                  }                  }
342                  __mcrypt_set_key_block(a, b, c);                  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)  int mcrypt_enc_get_block_size(MCRYPT td)
350  {  {
351          int (*_mcrypt_get_block_size) (void);          int (*_mcrypt_get_block_size) (void);
# Line 186  int mcrypt_enc_get_block_size(MCRYPT td) Line 354  int mcrypt_enc_get_block_size(MCRYPT td)
354          return _mcrypt_get_block_size();          return _mcrypt_get_block_size();
355  }  }
356    
357    WIN32DLL_DEFINE
358  int mcrypt_get_algo_iv_size(MCRYPT td)  int mcrypt_get_algo_iv_size(MCRYPT td)
359  {  {
360            const char* error;
361          int (*_mcrypt_get_algo_iv_size) (void);          int (*_mcrypt_get_algo_iv_size) (void);
         char *s;  
362    
363          s = td->algorithm_handle;          _mcrypt_get_algo_iv_size = mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_algo_iv_size");
364            if (_mcrypt_get_algo_iv_size == NULL) {
365          _mcrypt_get_algo_iv_size = lt_dlsym(s, "_mcrypt_get_algo_iv_size");                  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();          return _mcrypt_get_algo_iv_size();
373  }  }
374    
375    WIN32DLL_DEFINE
376  int mcrypt_enc_get_iv_size(MCRYPT td)  int mcrypt_enc_get_iv_size(MCRYPT td)
377  {  {
378          if (mcrypt_enc_is_block_algorithm_mode(td) == 1) {          if (mcrypt_enc_is_block_algorithm_mode(td) == 1) {
# Line 208  int mcrypt_enc_get_iv_size(MCRYPT td) Line 382  int mcrypt_enc_get_iv_size(MCRYPT td)
382          }          }
383  }  }
384    
385    WIN32DLL_DEFINE
386  int mcrypt_enc_get_key_size(MCRYPT td)  int mcrypt_enc_get_key_size(MCRYPT td)
387  {  {
388            const char* error;
389          int (*_mcrypt_get_key_size) (void);          int (*_mcrypt_get_key_size) (void);
         char *s;  
   
         s = td->algorithm_handle;  
390    
391          _mcrypt_get_key_size = lt_dlsym(s, "_mcrypt_get_key_size");          _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();          return _mcrypt_get_key_size();
401  }  }
402    
403    WIN32DLL_DEFINE
404  int *mcrypt_enc_get_supported_key_sizes(MCRYPT td, int *len)  int *mcrypt_enc_get_supported_key_sizes(MCRYPT td, int *len)
405  {  {
406          int *(*_mcrypt_get_key_sizes) (int *);          int *(*_mcrypt_get_key_sizes) (int *);
407          char *s;          int *size, *ret;
408          int *size;          const char* error;
   
         s = td->algorithm_handle;  
409    
410          _mcrypt_get_key_sizes =          _mcrypt_get_key_sizes =
411              lt_dlsym(s, "_mcrypt_get_supported_key_sizes");              mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_supported_key_sizes");
412          size = _mcrypt_get_key_sizes(len);          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          return size;          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)  int mcrypt_enc_is_block_algorithm(MCRYPT td)
435  {  {
436          int (*_is_block_algorithm) (void);          int (*_is_block_algorithm) (void);
437          char *s;          const char* error;
438    
439          s = td->algorithm_handle;          _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    
         _is_block_algorithm = lt_dlsym(s, "_is_block_algorithm");  
449          return _is_block_algorithm();          return _is_block_algorithm();
450  }  }
451    
452    WIN32DLL_DEFINE
453  char *mcrypt_enc_get_algorithms_name(MCRYPT td)  char *mcrypt_enc_get_algorithms_name(MCRYPT td)
454  {  {
455          char *(*_mcrypt_get_algorithms_name) (void);          const char *(*_mcrypt_get_algorithms_name) (void);
456          char *s;          const char* error;
   
         s = td->algorithm_handle;  
457    
458          _mcrypt_get_algorithms_name =          _mcrypt_get_algorithms_name =
459              lt_dlsym(s, "_mcrypt_get_algorithms_name");              mcrypt_dlsym(td->algorithm_handle, "_mcrypt_get_algorithms_name");
460          return _mcrypt_get_algorithms_name();          if (_mcrypt_get_algorithms_name == NULL) {
461  }                  error = lt_dlerror();
462                    if (error!=NULL) {
463  void mcrypt_block_encrypt(MCRYPT td, void *b)                          fputs(error, stderr);
464  {                          fputs("\n", stderr);
465          void (*_mcrypt_block_encrypt) (void *, void *);                  }
466          char *a;                  return NULL;
467            }
         a = td->akey;  
         _mcrypt_block_encrypt = td->a_encrypt;  
   
         _mcrypt_block_encrypt(a, b);  
 }  
   
 void mcrypt_block_decrypt(MCRYPT td, void *b)  
 {  
         void (*_mcrypt_block_decrypt) (void *, void *);  
         char *a;  
   
         a = td->akey;  
         _mcrypt_block_decrypt = td->a_decrypt;  
         _mcrypt_block_decrypt(a, b);  
 }  
   
 void mcrypt_stream_encrypt(MCRYPT td, void *b, int c)  
 {  
         void (*_mcrypt_stream_encrypt) (void *, void *, int);  
         char *a;  
468    
469          a = td->akey;          return strdup(_mcrypt_get_algorithms_name());
         _mcrypt_stream_encrypt = td->a_encrypt;  
         _mcrypt_stream_encrypt(a, b, c);  
470  }  }
471    
472  void mcrypt_stream_decrypt(MCRYPT td, void *b, int c)  WIN32DLL_DEFINE
473    int init_mcrypt(MCRYPT td, void *buf, const void *key, int keysize, const void *iv)
474  {  {
475          void (*_mcrypt_stream_decrypt) (void *, void *, int);          int (*_init_mcrypt) (void *, const void *, int, const void *, int);
476          char *a;          const char* error;
   
         a = td->akey;  
         _mcrypt_stream_decrypt = td->a_decrypt;  
         _mcrypt_stream_decrypt(a, b, c);  
 }  
477    
478  int init_mcrypt(MCRYPT td, void *buf, void *a, int b, void *c)          _init_mcrypt = mcrypt_dlsym(td->mode_handle, "_init_mcrypt");
479  {          if (_init_mcrypt == NULL) {
480          int (*_init_mcrypt) (void *, void *, int, void *, int);                  error = lt_dlerror();
481          char *s;                  if (error!=NULL) {
482                            fputs(error, stderr);
483                            fputs("\n", stderr);
484                    }
485                    return MCRYPT_UNKNOWN_ERROR;
486            }
487    
488          s = td->mode_handle;          return _init_mcrypt(buf, key, keysize, iv, mcrypt_enc_get_block_size(td));
         _init_mcrypt = lt_dlsym(s, "_init_mcrypt");  
         return _init_mcrypt(buf, a, b, c, mcrypt_enc_get_block_size(td));  
489  }  }
490    
491    WIN32DLL_DEFINE
492  int end_mcrypt(MCRYPT td, void *buf)  int end_mcrypt(MCRYPT td, void *buf)
493  {  {
494          int (*_end_mcrypt) (void *);          int (*_end_mcrypt) (void *);
495          char *s;          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    
         s = td->mode_handle;  
         _end_mcrypt = lt_dlsym(s, "_end_mcrypt");  
507          return _end_mcrypt(buf);          return _end_mcrypt(buf);
508  }  }
509    
510    WIN32DLL_DEFINE
511  int mcrypt(MCRYPT td, void *buf, void *a, int b)  int mcrypt(MCRYPT td, void *buf, void *a, int b)
512  {  {
513          int (*_mcrypt) (void *, void *, int, int, void *, void *, void*);          int (*_mcrypt) (void *, void *, int, int, void *, void *, void*);
514    
515          _mcrypt = td->m_encrypt;          _mcrypt = td->m_encrypt;
516    
517          return _mcrypt(buf, a, b, mcrypt_enc_get_block_size(td), td->akey,          return _mcrypt(buf, a, b, mcrypt_enc_get_block_size(td), td->akey,
518                         td->a_encrypt, td->a_decrypt);                         td->a_encrypt, td->a_decrypt);
519  }  }
520    
521    WIN32DLL_DEFINE
522  int mdecrypt(MCRYPT td, void *buf, void *a, int b)  int mdecrypt(MCRYPT td, void *buf, void *a, int b)
523  {  {
524          int (*_mdecrypt) (void *, void *, int, int, void *, void *, void*);          int (*_mdecrypt) (void *, void *, int, int, void *, void *, void*);
# Line 339  int mdecrypt(MCRYPT td, void *buf, void Line 528  int mdecrypt(MCRYPT td, void *buf, void
528                           td->akey, td->a_encrypt, td->a_decrypt);                           td->akey, td->a_encrypt, td->a_decrypt);
529  }  }
530    
531    WIN32DLL_DEFINE
532  char *mcrypt_enc_get_modes_name(MCRYPT td)  char *mcrypt_enc_get_modes_name(MCRYPT td)
533  {  {
534          char *(*_mcrypt_get_modes_name) (void);          const char *(*_mcrypt_get_modes_name) (void);
535          char *s;          const char* error;
536    
537          s = td->mode_handle;          _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          _mcrypt_get_modes_name = lt_dlsym(s, "_mcrypt_get_modes_name");          return strdup(_mcrypt_get_modes_name());
         return _mcrypt_get_modes_name();  
548  }  }
549    
550    WIN32DLL_DEFINE
551  int mcrypt_enc_is_block_mode(MCRYPT td)  int mcrypt_enc_is_block_mode(MCRYPT td)
552  {  {
553          int (*_is_block_mode) (void);          int (*_is_block_mode) (void);
554          char *s;          const char* error;
555            
556          s = td->mode_handle;          _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    
         _is_block_mode = lt_dlsym(s, "_is_block_mode");  
566          return _is_block_mode();          return _is_block_mode();
567  }  }
568    
569    WIN32DLL_DEFINE
570  int mcrypt_enc_mode_has_iv(MCRYPT td)  int mcrypt_enc_mode_has_iv(MCRYPT td)
571  {  {
572          int (*_has_iv) (void);          int (*_has_iv) (void);
573          char *s;          const char* error;
574    
575          s = td->mode_handle;          _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    
         _has_iv = lt_dlsym(s, "_has_iv");  
585          return _has_iv();          return _has_iv();
586  }  }
587    
588    WIN32DLL_DEFINE
589  int mcrypt_enc_is_block_algorithm_mode(MCRYPT td)  int mcrypt_enc_is_block_algorithm_mode(MCRYPT td)
590  {  {
591          int (*_is_a_block_mode) (void);          int (*_is_a_block_mode) (void);
592          char *s;          const char* error;
593    
594          s = td->mode_handle;          _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    
         _is_a_block_mode = lt_dlsym(s, "_is_block_algorithm_mode");  
604          return _is_a_block_mode();          return _is_a_block_mode();
605  }  }
606    
607    WIN32DLL_DEFINE
608  int mcrypt_enc_self_test(MCRYPT td)  int mcrypt_enc_self_test(MCRYPT td)
609  {  {
610          int (*_self_test) (void);          int (*_self_test) (void);
611          char *s;          const char* error;
   
         s = td->algorithm_handle;  
612    
613          _self_test = lt_dlsym(s, "_mcrypt_self_test");          _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();          return _self_test();
624  }  }
625    
626    WIN32DLL_DEFINE
627  int mcrypt_module_self_test(char *algorithm, char *a_directory)  int mcrypt_module_self_test(const char *algorithm, const char *a_directory)
628  {  {
629          int i;          int i;
630          lt_dlhandle *_handle;          void* rr;
631            mcrypt_dlhandle _handle;
632          int (*_self_test) (void);          int (*_self_test) (void);
633            const char* error;
   
634    
635          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
636                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
637          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (a_directory != NULL) {  
                 lt_dlsetsearchpath(a_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
638    
639          _handle = lt_dlopenext(algorithm);          rr = mcrypt_dlopen(&_handle, a_directory, NULL, algorithm);
640    
641          if (!_handle) {          if (!rr) {
642                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
643                  fputs("\n", stderr);                  if (error!=NULL) {
644                            fputs( error, stderr);
645                            fputs("\n", stderr);
646                    }
647                    lt_dlexit();
648                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
649          }          }
650    
651          _self_test = lt_dlsym(_handle, "_mcrypt_self_test");          _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();          i = _self_test();
659    
660          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
661          lt_dlexit();          if (lt_dlexit() != 0) {
662                    return MCRYPT_UNKNOWN_ERROR;
663            }
664    
665          return i;          return i;
666  }  }
667    
668  int mcrypt_module_algorithm_version(char *algorithm, char *a_directory)  WIN32DLL_DEFINE
669    int mcrypt_module_algorithm_version(const char *algorithm, const char *a_directory)
670  {  {
671          int i;          int i;
672          lt_dlhandle _handle;          mcrypt_dlhandle _handle;
673          int (*_version) (void);          int (*_version) (void);
674            const char* error;
675            void* rr;
676            
677          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
678                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
679          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (a_directory != NULL) {  
                 lt_dlsetsearchpath(a_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
680    
681          _handle = lt_dlopenext(algorithm);          rr = mcrypt_dlopen(&_handle, a_directory, NULL, algorithm);
682          if (!_handle) {          if (!rr) {
683                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
684                  fputs("\n", stderr);                  if (error!=NULL) {
685                            fputs( error, stderr);
686                            fputs("\n", stderr);
687                    }
688                    lt_dlexit();
689                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
690          }          }
691    
692          _version = lt_dlsym(_handle, "_mcrypt_algorithm_version");          _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();          i = _version();
700    
701          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
702          lt_dlexit();          if (lt_dlexit() != 0) {
703                    return MCRYPT_UNKNOWN_ERROR;
704            }
705    
706          return i;          return i;
707  }  }
708    
709  int mcrypt_module_mode_version(char *mode, char *m_directory)  WIN32DLL_DEFINE
710    int mcrypt_module_mode_version(const char *mode, const char *m_directory)
711  {  {
712          int i;          int i;
713          lt_dlhandle *_handle;          mcrypt_dlhandle _handle;
714          int (*_version) (void);          int (*_version) (void);
715            const char* error;
716            void * rr;
717    
718          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
719                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
720          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (m_directory != NULL) {  
                 lt_dlsetsearchpath(m_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
721    
722          _handle = lt_dlopenext(mode);          rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode);
723          if (!_handle) {          if (!rr) {
724                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
725                  fputs("\n", stderr);                  if(error!=NULL) {
726                            fputs(error, stderr);
727                            fputs("\n", stderr);
728                    }
729                    lt_dlexit();
730                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
731          }          }
732    
733          _version = lt_dlsym(_handle, "_mcrypt_mode_version");          _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();          i = _version();
741    
742          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
743          lt_dlexit();          if (lt_dlexit() != 0) {
744                    return MCRYPT_UNKNOWN_ERROR;
745            }
746    
747          return i;          return i;
748  }  }
749    
750    WIN32DLL_DEFINE
751  int mcrypt_module_is_block_algorithm(char *algorithm, char *a_directory)  int mcrypt_module_is_block_algorithm(const char *algorithm, const char *a_directory)
752  {  {
753          int i;          int i;
754          lt_dlhandle _handle;          mcrypt_dlhandle _handle;
755          int (*_is_block_algorithm) (void);          int (*_is_block_algorithm) (void);
756            const char* error;
757            void * rr;
758            
759          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
760                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
761          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (a_directory != NULL) {  
                 lt_dlsetsearchpath(a_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
762    
763          _handle = lt_dlopenext(algorithm);          rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
764          if (!_handle) {          if (!rr) {
765                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
766                  fputs("\n", stderr);                  if(error!=NULL) {
767                            fputs( error, stderr);
768                            fputs("\n", stderr);
769                    }
770                    lt_dlexit();
771                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
772          }          }
773    
774          _is_block_algorithm = lt_dlsym(_handle, "_is_block_algorithm");          _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();          i = _is_block_algorithm();
782    
783          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
784          lt_dlexit();          if (lt_dlexit() != 0) {
785                    return MCRYPT_UNKNOWN_ERROR;
786            }
787    
788          return i;          return i;
789  }  }
790    
791    WIN32DLL_DEFINE
792  int mcrypt_module_is_block_algorithm_mode(char *mode, char *m_directory)  int mcrypt_module_is_block_algorithm_mode(const char *mode, const char *m_directory)
793  {  {
794          int i;          int i;
795          lt_dlhandle *_handle;          mcrypt_dlhandle _handle;
796          int (*_is_a_block_mode) (void);          int (*_is_a_block_mode) (void);
797            const char* error;
798            void * rr;
799    
800          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
801                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
802          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (m_directory != NULL) {  
                 lt_dlsetsearchpath(m_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
803    
804          _handle = lt_dlopenext(mode);          rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode);
805          if (!_handle) {          if (!rr) {
806                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
807                  fputs("\n", stderr);                  if(error!=NULL) {
808                            fputs( error, stderr);
809                            fputs("\n", stderr);
810                    }
811                    lt_dlexit();
812                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
813          }          }
814    
815          _is_a_block_mode = lt_dlsym(_handle, "_is_block_algorithm_mode");          _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();          i = _is_a_block_mode();
823    
824          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
825          lt_dlexit();          if (lt_dlexit() != 0) {
826                    return MCRYPT_UNKNOWN_ERROR;
827            }
828    
829          return i;          return i;
830  }  }
831    
832    WIN32DLL_DEFINE
833  int mcrypt_module_is_block_mode(char *mode, char *m_directory)  int mcrypt_module_is_block_mode(const char *mode, const char *m_directory)
834  {  {
835            void * rr;
836          int i;          int i;
837          lt_dlhandle *_handle;          mcrypt_dlhandle _handle;
838          int (*_is_block_mode) (void);          int (*_is_block_mode) (void);
839            const char* error;
840    
841          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
842                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
843          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (m_directory != NULL) {  
                 lt_dlsetsearchpath(m_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
844    
845          _handle = lt_dlopenext(mode);          rr = mcrypt_dlopen( &_handle, m_directory, NULL, mode);
846          if (!_handle) {          if (!rr) {
847                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
848                  fputs("\n", stderr);                  if(error!=NULL) {
849                            fputs( error, stderr);
850                            fputs("\n", stderr);
851                    }
852                    lt_dlexit();
853                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
854          }          }
855    
856          _is_block_mode = lt_dlsym(_handle, "_is_block_mode");          _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();          i = _is_block_mode();
864    
865          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
866          lt_dlexit();          if (lt_dlexit() != 0) {
867                    return MCRYPT_UNKNOWN_ERROR;
868            }
869    
870          return i;          return i;
871  }  }
872    
873  int mcrypt_module_get_algo_block_size(char *algorithm, char *a_directory)  WIN32DLL_DEFINE
874    int mcrypt_module_get_algo_block_size(const char *algorithm, const char *a_directory)
875  {  {
876          int i;          int i;
877          lt_dlhandle _handle;          mcrypt_dlhandle _handle;
878          int (*_get_block_size) (void);          int (*_get_block_size) (void);
879            const char* error;
880            void * rr;
881    
882          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
883                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
884          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (a_directory != NULL) {  
                 lt_dlsetsearchpath(a_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
885    
886          _handle = lt_dlopenext(algorithm);          rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
887          if (!_handle) {          if (!rr) {
888                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
889                  fputs("\n", stderr);                  if(error!=NULL) {
890                            fputs( error, stderr);
891                            fputs("\n", stderr);
892                    }
893                    lt_dlexit();
894                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
895          }          }
896    
897          _get_block_size = lt_dlsym(_handle, "_mcrypt_get_block_size");          _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();          i = _get_block_size();
905    
906          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
907          lt_dlexit();          if (lt_dlexit() != 0) {
908                    return MCRYPT_UNKNOWN_ERROR;
909            }
910    
911          return i;          return i;
912  }  }
913    
914  int mcrypt_module_get_algo_key_size(char *algorithm, char *a_directory)  WIN32DLL_DEFINE
915    int mcrypt_module_get_algo_key_size(const char *algorithm, const char *a_directory)
916  {  {
917          int i;          int i;
918          lt_dlhandle _handle;          mcrypt_dlhandle _handle;
919          int (*_get_key_size) (void);          int (*_get_key_size) (void);
920            const char* error;
921            void * rr;
922    
923          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
924                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
925          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (a_directory != NULL) {  
                 lt_dlsetsearchpath(a_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
926    
927          _handle = lt_dlopenext(algorithm);          rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
928          if (!_handle) {          if (!rr) {
929                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
930                  fputs("\n", stderr);                  if(error!=NULL) {
931                            fputs( error, stderr);
932                            fputs("\n", stderr);
933                    }
934                    lt_dlexit();
935                  return MCRYPT_UNKNOWN_ERROR;                  return MCRYPT_UNKNOWN_ERROR;
936          }          }
937    
938          _get_key_size = lt_dlsym(_handle, "_mcrypt_get_key_size");          _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();          i = _get_key_size();
946    
947          lt_dlclose(_handle);          mcrypt_dlclose(_handle);
948          lt_dlexit();          if (lt_dlexit() != 0) {
949                    return MCRYPT_UNKNOWN_ERROR;
950            }
951    
952          return i;          return i;
953  }  }
954    
955    WIN32DLL_DEFINE
956  int *mcrypt_module_get_algo_supported_key_sizes(char *algorithm,  int *mcrypt_module_get_algo_supported_key_sizes(const char *algorithm,
957                                                  char *a_directory,                                                  const char *a_directory,
958                                                  int *len)                                                  int *len)
959  {  {
960          lt_dlhandle _handle;          mcrypt_dlhandle _handle;
961          int *(*_mcrypt_get_key_sizes) (int *);          int *(*_mcrypt_get_key_sizes) (int *);
962          int *size;          int *size;
963            int * ret_size;
964            const char* error;
965            void * rr;
966    
967            
968          if (lt_dlinit() != 0) {          if (lt_dlinit() != 0) {
969                  *len = 0;                  *len = 0;
970                  return NULL;                  return NULL;
971          }          }
 /*      LTDL_SET_PRELOADED_SYMBOLS(); */  
         if (a_directory != NULL) {  
                 lt_dlsetsearchpath(a_directory);  
         } else {  
                 lt_dladdsearchdir(LIBDIR);  
         }  
972    
973          _handle = lt_dlopenext(algorithm);          rr = mcrypt_dlopen( &_handle, a_directory, NULL, algorithm);
974          if (!_handle) {          if (!rr) {
975                  fputs(lt_dlerror(), stderr);                  error=lt_dlerror();
976                  fputs("\n", stderr);                  if(error!=NULL) {
977                            fputs( error, stderr);
978                            fputs("\n", stderr);
979                    }
980                    lt_dlexit();
981                  *len = 0;                  *len = 0;
982                  return NULL;                  return NULL;
983          }          }
984    
985          _mcrypt_get_key_sizes =          _mcrypt_get_key_sizes =
986              lt_dlsym(_handle, "_mcrypt_get_supported_key_sizes");              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);          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          lt_dlclose(_handle);  /* Returns false(0) if the library has not been compiled
1012          lt_dlexit();   * 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    
         return size;  
1021  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.36

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26