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> |
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 |
} |
} |
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)); |
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); |