View | Details | Raw Unified | Return to bug 141 | Differences between
and this patch

Collapse All | Expand All

(-)cipher.c (+40 lines)
Lines 44-49 Link Here
44
#include <openssl/md5.h>
44
#include <openssl/md5.h>
45
#include "rijndael.h"
45
#include "rijndael.h"
46
46
47
#if OPENSSL_VERSION_NUMBER <= 0x0090600fL
48
#define SSH_OLD_EVP
49
#define EVP_CIPHER_CTX_get_app_data(e)          ((e)->app_data)
50
#endif
51
47
static EVP_CIPHER *evp_ssh1_3des(void);
52
static EVP_CIPHER *evp_ssh1_3des(void);
48
static EVP_CIPHER *evp_ssh1_bf(void);
53
static EVP_CIPHER *evp_ssh1_bf(void);
49
static EVP_CIPHER *evp_rijndael(void);
54
static EVP_CIPHER *evp_rijndael(void);
Lines 171-177 Link Here
171
    int encrypt)
176
    int encrypt)
172
{
177
{
173
	static int dowarn = 1;
178
	static int dowarn = 1;
179
#ifdef SSH_OLD_EVP
180
	EVP_CIPHER *type;
181
#else
174
	const EVP_CIPHER *type;
182
	const EVP_CIPHER *type;
183
#endif
175
	int klen;
184
	int klen;
176
185
177
	if (cipher->number == SSH_CIPHER_DES) {
186
	if (cipher->number == SSH_CIPHER_DES) {
Lines 195-201 Link Here
195
204
196
	type = (*cipher->evptype)();
205
	type = (*cipher->evptype)();
197
206
207
#ifdef SSH_OLD_EVP
208
	if (type->key_len < cipher->key_len)
209
		type->key_len = cipher->key_len;
198
	EVP_CIPHER_CTX_init(&cc->evp);
210
	EVP_CIPHER_CTX_init(&cc->evp);
211
	EVP_CipherInit(&cc->evp, type, (u_char *)key, (u_char *)iv,
212
	    (encrypt == CIPHER_ENCRYPT));
213
#else
199
	if (EVP_CipherInit(&cc->evp, type, NULL, (u_char *)iv,
214
	if (EVP_CipherInit(&cc->evp, type, NULL, (u_char *)iv,
200
	    (encrypt == CIPHER_ENCRYPT)) == 0)
215
	    (encrypt == CIPHER_ENCRYPT)) == 0)
201
		fatal("cipher_init: EVP_CipherInit failed for %s",
216
		fatal("cipher_init: EVP_CipherInit failed for %s",
Lines 210-215 Link Here
210
	if (EVP_CipherInit(&cc->evp, NULL, (u_char *)key, NULL, -1) == 0)
225
	if (EVP_CipherInit(&cc->evp, NULL, (u_char *)key, NULL, -1) == 0)
211
		fatal("cipher_init: EVP_CipherInit: set key failed for %s",
226
		fatal("cipher_init: EVP_CipherInit: set key failed for %s",
212
		    cipher->name);
227
		    cipher->name);
228
#endif
213
}
229
}
214
230
215
void
231
void
Lines 217-231 Link Here
217
{
233
{
218
	if (len % cc->cipher->block_size)
234
	if (len % cc->cipher->block_size)
219
		fatal("cipher_encrypt: bad plaintext length %d", len);
235
		fatal("cipher_encrypt: bad plaintext length %d", len);
236
#ifdef SSH_OLD_EVP
237
	EVP_Cipher(&cc->evp, dest, (u_char *)src, len);
238
#else
220
	if (EVP_Cipher(&cc->evp, dest, (u_char *)src, len) == 0)
239
	if (EVP_Cipher(&cc->evp, dest, (u_char *)src, len) == 0)
221
		fatal("evp_crypt: EVP_Cipher failed");
240
		fatal("evp_crypt: EVP_Cipher failed");
241
#endif
222
}
242
}
223
243
224
void
244
void
225
cipher_cleanup(CipherContext *cc)
245
cipher_cleanup(CipherContext *cc)
226
{
246
{
247
#ifdef SSH_OLD_EVP
248
	EVP_CIPHER_CTX_cleanup(&cc->evp);
249
#else
227
	if (EVP_CIPHER_CTX_cleanup(&cc->evp) == 0)
250
	if (EVP_CIPHER_CTX_cleanup(&cc->evp) == 0)
228
		error("cipher_cleanup: EVP_CIPHER_CTX_cleanup failed");
251
		error("cipher_cleanup: EVP_CIPHER_CTX_cleanup failed");
252
#endif
229
}
253
}
230
254
231
/*
255
/*
Lines 296-301 Link Here
296
	EVP_CIPHER_CTX_init(&c->k1);
320
	EVP_CIPHER_CTX_init(&c->k1);
297
	EVP_CIPHER_CTX_init(&c->k2);
321
	EVP_CIPHER_CTX_init(&c->k2);
298
	EVP_CIPHER_CTX_init(&c->k3);
322
	EVP_CIPHER_CTX_init(&c->k3);
323
#ifdef SSH_OLD_EVP
324
	EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc);
325
	EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc);
326
	EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc);
327
#else
299
	if (EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc) == 0 ||
328
	if (EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc) == 0 ||
300
	    EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc) == 0 ||
329
	    EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc) == 0 ||
301
	    EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc) == 0) {
330
	    EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc) == 0) {
Lines 304-309 Link Here
304
		EVP_CIPHER_CTX_set_app_data(ctx, NULL);
333
		EVP_CIPHER_CTX_set_app_data(ctx, NULL);
305
		return (0);
334
		return (0);
306
	}
335
	}
336
#endif
307
	return (1);
337
	return (1);
308
}
338
}
309
static int
339
static int
Lines 315-324 Link Here
315
		error("ssh1_3des_cbc: no context");
345
		error("ssh1_3des_cbc: no context");
316
		return (0);
346
		return (0);
317
	}
347
	}
348
#ifdef SSH_OLD_EVP
349
	EVP_Cipher(&c->k1, dest, (u_char *)src, len);
350
	EVP_Cipher(&c->k2, dest, dest, len);
351
	EVP_Cipher(&c->k3, dest, dest, len);
352
#else
318
	if (EVP_Cipher(&c->k1, dest, (u_char *)src, len) == 0 ||
353
	if (EVP_Cipher(&c->k1, dest, (u_char *)src, len) == 0 ||
319
	    EVP_Cipher(&c->k2, dest, dest, len) == 0 ||
354
	    EVP_Cipher(&c->k2, dest, dest, len) == 0 ||
320
	    EVP_Cipher(&c->k3, dest, dest, len) == 0)
355
	    EVP_Cipher(&c->k3, dest, dest, len) == 0)
321
		return (0);
356
		return (0);
357
#endif
322
	return (1);
358
	return (1);
323
}
359
}
324
static int
360
static int
Lines 346-352 Link Here
346
	ssh1_3des.init = ssh1_3des_init;
382
	ssh1_3des.init = ssh1_3des_init;
347
	ssh1_3des.cleanup = ssh1_3des_cleanup;
383
	ssh1_3des.cleanup = ssh1_3des_cleanup;
348
	ssh1_3des.do_cipher = ssh1_3des_cbc;
384
	ssh1_3des.do_cipher = ssh1_3des_cbc;
385
#ifndef SSH_OLD_EVP
349
	ssh1_3des.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH;
386
	ssh1_3des.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH;
387
#endif
350
	return (&ssh1_3des);
388
	return (&ssh1_3des);
351
}
389
}
352
390
Lines 494-500 Link Here
494
	rijndal_cbc.init = ssh_rijndael_init;
532
	rijndal_cbc.init = ssh_rijndael_init;
495
	rijndal_cbc.cleanup = ssh_rijndael_cleanup;
533
	rijndal_cbc.cleanup = ssh_rijndael_cleanup;
496
	rijndal_cbc.do_cipher = ssh_rijndael_cbc;
534
	rijndal_cbc.do_cipher = ssh_rijndael_cbc;
535
#ifndef SSH_OLD_EVP
497
	rijndal_cbc.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
536
	rijndal_cbc.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH |
498
	    EVP_CIPH_ALWAYS_CALL_INIT;
537
	    EVP_CIPH_ALWAYS_CALL_INIT;
538
#endif
499
	return (&rijndal_cbc);
539
	return (&rijndal_cbc);
500
}
540
}

Return to bug 141