Lines 22-28
Link Here
|
22 |
exit(1); |
22 |
exit(1); |
23 |
} |
23 |
} |
24 |
|
24 |
|
25 |
static EVP_CIPHER_CTX ctx; |
25 |
static EVP_CIPHER_CTX *ctx; |
26 |
static int ctx_initialized = 0; |
26 |
static int ctx_initialized = 0; |
27 |
static int encryption_disabled = 0; |
27 |
static int encryption_disabled = 0; |
28 |
static int nfd; |
28 |
static int nfd; |
Lines 30-35
Link Here
|
30 |
static struct vde_open_args open_args={.port=0,.group=NULL,.mode=0700}; |
30 |
static struct vde_open_args open_args={.port=0,.group=NULL,.mode=0700}; |
31 |
static int verbose = 0; |
31 |
static int verbose = 0; |
32 |
|
32 |
|
|
|
33 |
#if OPENSSL_VERSION_NUMBER < 0x10100000 |
34 |
#define EVP_CIPHER_CTX_reset(x) EVP_CIPHER_CTX_cleanup(x) |
35 |
#endif |
36 |
|
33 |
void vc_printlog(int priority, const char *format, ...) |
37 |
void vc_printlog(int priority, const char *format, ...) |
34 |
{ |
38 |
{ |
35 |
va_list arg; |
39 |
va_list arg; |
Lines 103-121
Link Here
|
103 |
} |
107 |
} |
104 |
|
108 |
|
105 |
if (!ctx_initialized) { |
109 |
if (!ctx_initialized) { |
106 |
EVP_CIPHER_CTX_init (&ctx); |
110 |
ctx = EVP_CIPHER_CTX_new (); |
|
|
111 |
if (!ctx) |
112 |
return -1; |
107 |
ctx_initialized = 1; |
113 |
ctx_initialized = 1; |
108 |
} |
114 |
} |
109 |
|
115 |
|
110 |
EVP_EncryptInit (&ctx, EVP_bf_cbc (), p->key, p->iv); |
116 |
EVP_EncryptInit (ctx, EVP_bf_cbc (), p->key, p->iv); |
111 |
if (EVP_EncryptUpdate (&ctx, dst, &olen, src, len) != 1) |
117 |
if (EVP_EncryptUpdate (ctx, dst, &olen, src, len) != 1) |
112 |
{ |
118 |
{ |
113 |
fprintf (stderr,"error in encrypt update\n"); |
119 |
fprintf (stderr,"error in encrypt update\n"); |
114 |
olen = -1; |
120 |
olen = -1; |
115 |
goto cleanup; |
121 |
goto cleanup; |
116 |
} |
122 |
} |
117 |
|
123 |
|
118 |
if (EVP_EncryptFinal (&ctx, dst + olen, &tlen) != 1) |
124 |
if (EVP_EncryptFinal (ctx, dst + olen, &tlen) != 1) |
119 |
{ |
125 |
{ |
120 |
fprintf (stderr,"error in encrypt final\n"); |
126 |
fprintf (stderr,"error in encrypt final\n"); |
121 |
olen = -1; |
127 |
olen = -1; |
Lines 124-130
Link Here
|
124 |
olen += tlen; |
130 |
olen += tlen; |
125 |
|
131 |
|
126 |
cleanup: |
132 |
cleanup: |
127 |
EVP_CIPHER_CTX_cleanup(&ctx); |
133 |
EVP_CIPHER_CTX_reset(ctx); |
128 |
return olen; |
134 |
return olen; |
129 |
} |
135 |
} |
130 |
|
136 |
|
Lines 138-156
Link Here
|
138 |
} |
144 |
} |
139 |
|
145 |
|
140 |
if (!ctx_initialized) { |
146 |
if (!ctx_initialized) { |
141 |
EVP_CIPHER_CTX_init (&ctx); |
147 |
ctx = EVP_CIPHER_CTX_new (); |
|
|
148 |
if (!ctx) |
149 |
return -1; |
142 |
ctx_initialized = 1; |
150 |
ctx_initialized = 1; |
143 |
} |
151 |
} |
144 |
|
152 |
|
145 |
EVP_DecryptInit (&ctx, EVP_bf_cbc (), p->key, p->iv); |
153 |
EVP_DecryptInit (ctx, EVP_bf_cbc (), p->key, p->iv); |
146 |
if (EVP_DecryptUpdate (&ctx, dst, &olen, src, len) != 1) |
154 |
if (EVP_DecryptUpdate (ctx, dst, &olen, src, olen) != 1) |
147 |
{ |
155 |
{ |
148 |
fprintf (stderr,"error in decrypt update\n"); |
156 |
fprintf (stderr,"error in decrypt update\n"); |
149 |
olen = -1; |
157 |
olen = -1; |
150 |
goto cleanup; |
158 |
goto cleanup; |
151 |
} |
159 |
} |
152 |
|
160 |
|
153 |
if (EVP_DecryptFinal (&ctx, dst + olen, &tlen) != 1) |
161 |
if (EVP_DecryptFinal (ctx, dst + olen, &tlen) != 1) |
154 |
{ |
162 |
{ |
155 |
fprintf (stderr,"error in decrypt final\n"); |
163 |
fprintf (stderr,"error in decrypt final\n"); |
156 |
olen = -1; |
164 |
olen = -1; |
Lines 159-165
Link Here
|
159 |
olen += tlen; |
167 |
olen += tlen; |
160 |
|
168 |
|
161 |
cleanup: |
169 |
cleanup: |
162 |
EVP_CIPHER_CTX_cleanup(&ctx); |
170 |
EVP_CIPHER_CTX_reset (ctx); |
163 |
return olen; |
171 |
return olen; |
164 |
} |
172 |
} |
165 |
|
173 |
|