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

Diff of /libmcrypt/lib/mcrypt.c

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

revision 1.4 by nmav, Wed Oct 25 18:43:11 2000 UTC revision 1.5 by nmav, Wed Jan 17 19:33:49 2001 UTC
# Line 36  Line 36 
36   *                                              --nikos   *                                              --nikos
37   */   */
38    
39    /* The above comments are too old! */
40    
41  #ifndef LIBDEFS_H  #ifndef LIBDEFS_H
42  #define LIBDEFS_H  #define LIBDEFS_H
43  #include <libdefs.h>  #include <libdefs.h>
# Line 54  static int internal_init_mcrypt(MCRYPT t Line 56  static int internal_init_mcrypt(MCRYPT t
56  {  {
57          int *sizes = NULL;          int *sizes = NULL;
58          int num_of_sizes, i, ok = 0;          int num_of_sizes, i, ok = 0;
59            int key_size;
60            
61          if (lenofkey == 0) {          if (lenofkey == 0) {
62                  return MCRYPT_KEY_LEN_ERROR;    /* error */                  return MCRYPT_KEY_LEN_ERROR;    /* error */
63          }          }
# Line 72  static int internal_init_mcrypt(MCRYPT t Line 76  static int internal_init_mcrypt(MCRYPT t
76                          ok = 1;                          ok = 1;
77          }          }
78    
79          free(sizes);          if (sizes!=NULL) free(sizes);
80          if (ok == 0) {  
81                  return MCRYPT_KEY_LEN_ERROR;          if (ok == 0) { /* not supported key size */
82                    key_size = mcrypt_enc_get_key_size(td);
83                    sizes = mcrypt_enc_get_supported_key_sizes(td, &num_of_sizes);
84                    if (sizes != NULL) {
85                            for (i = 0; i < num_of_sizes; i++) {
86                                    if (lenofkey <= sizes[i]) {
87                                            key_size = sizes[i];
88                                            break;
89                                    }
90                            }
91                            free(sizes);
92                    }
93            } else {
94                    key_size = lenofkey;
95          }          }
96    
97          td->keyword_given = mxcalloc(1, mcrypt_enc_get_key_size(td));          td->keyword_given = mxcalloc(1, mcrypt_enc_get_key_size(td));
# Line 82  static int internal_init_mcrypt(MCRYPT t Line 99  static int internal_init_mcrypt(MCRYPT t
99          td->akey = mxcalloc(1, mcrypt_get_size(td));          td->akey = mxcalloc(1, mcrypt_get_size(td));
100          td->abuf = mxcalloc(1, mcrypt_mode_get_size(td));          td->abuf = mxcalloc(1, mcrypt_mode_get_size(td));
101    
102          init_mcrypt(td, td->abuf, key, lenofkey, IV);          init_mcrypt(td, td->abuf, key, key_size, IV);
103    
104          mcrypt_set_key(td,          mcrypt_set_key(td,
105                         (void *) td->akey,                         (void *) td->akey,
106                         (void *) td->keyword_given,                         (void *) td->keyword_given,
107                         lenofkey, IV, mcrypt_enc_get_iv_size(td));                         key_size, IV, mcrypt_enc_get_iv_size(td));
108    
109          if (td->akey == NULL) {          if (td->akey == NULL) {
110                  internal_end_mcrypt(td);                  internal_end_mcrypt(td);

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26