version 1.3, 1999/09/26 22:53:25 |
version 1.4, 1999/09/28 04:45:36 |
|
|
|
|
#include "ssh.h" |
#include "ssh.h" |
#include "cipher.h" |
#include "cipher.h" |
|
#include "ssh_md5.h" |
|
|
/* |
/* |
* What kind of tripple DES are these 2 routines? |
* What kind of tripple DES are these 2 routines? |
|
|
/* Names of all encryption algorithms. These must match the numbers defined |
/* Names of all encryption algorithms. These must match the numbers defined |
int cipher.h. */ |
int cipher.h. */ |
static char *cipher_names[] = |
static char *cipher_names[] = |
{ "none", |
{ |
|
"none", |
"no idea", |
"no idea", |
#ifdef WITH_DES |
#ifdef WITH_DES |
"des", |
"des", |
|
|
#endif |
#endif |
"3des", |
"3des", |
"no tss", |
"no tss", |
#ifdef WITH_RC4 |
|
"rc4", |
|
#else |
|
"no rc4", |
"no rc4", |
#endif |
|
"blowfish" |
"blowfish" |
}; |
}; |
|
|
|
|
mask |= 1 << SSH_CIPHER_DES; |
mask |= 1 << SSH_CIPHER_DES; |
#endif |
#endif |
mask |= 1 << SSH_CIPHER_3DES; /* Mandatory */ |
mask |= 1 << SSH_CIPHER_3DES; /* Mandatory */ |
#ifdef WITH_RC4 |
|
mask |= 1 << SSH_CIPHER_RC4; |
|
#endif |
|
mask |= 1 << SSH_CIPHER_BLOWFISH; |
mask |= 1 << SSH_CIPHER_BLOWFISH; |
return mask; |
return mask; |
} |
} |
|
|
/* Returns the name of the cipher. */ |
/* Returns the name of the cipher. */ |
|
|
const char *cipher_name(int cipher) |
const |
|
char *cipher_name(int cipher) |
{ |
{ |
if (cipher < 0 || cipher >= sizeof(cipher_names) / sizeof(cipher_names[0])) |
if (cipher < 0 || cipher >= sizeof(cipher_names) / sizeof(cipher_names[0])) |
fatal("cipher_name: bad cipher number: %d", cipher); |
fatal("cipher_name: bad cipher number: %d", cipher); |
|
|
/* Parses the name of the cipher. Returns the number of the corresponding |
/* Parses the name of the cipher. Returns the number of the corresponding |
cipher, or -1 on error. */ |
cipher, or -1 on error. */ |
|
|
int cipher_number(const char *name) |
int |
|
cipher_number(const char *name) |
{ |
{ |
int i; |
int i; |
for (i = 0; i < sizeof(cipher_names) / sizeof(cipher_names[0]); i++) |
for (i = 0; i < sizeof(cipher_names) / sizeof(cipher_names[0]); i++) |
|
|
memset(context->u.des3.iv3, 0, sizeof(context->u.des3.iv3)); |
memset(context->u.des3.iv3, 0, sizeof(context->u.des3.iv3)); |
break; |
break; |
|
|
#ifdef WITH_RC4 |
|
case SSH_CIPHER_RC4: |
|
rc4_init(&context->u.rc4, key, keylen); |
|
break; |
|
#endif /* WITH_RC4 */ |
|
|
|
case SSH_CIPHER_BLOWFISH: |
case SSH_CIPHER_BLOWFISH: |
BF_set_key(&context->u.bf.key, keylen, padded); |
BF_set_key(&context->u.bf.key, keylen, padded); |
memset(context->u.bf.iv, 0, 8); |
memset(context->u.bf.iv, 0, 8); |
|
|
dest, (void*)src, len); |
dest, (void*)src, len); |
break; |
break; |
|
|
#ifdef WITH_RC4 |
|
case SSH_CIPHER_RC4: |
|
rc4_encrypt(&context->u.rc4, dest, src, len); |
|
break; |
|
#endif /* WITH_RC4 */ |
|
|
|
case SSH_CIPHER_BLOWFISH: |
case SSH_CIPHER_BLOWFISH: |
swap_bytes(src, dest, len); |
swap_bytes(src, dest, len); |
BF_cbc_encrypt(dest, dest, len, |
BF_cbc_encrypt(dest, dest, len, |
|
|
context->u.des3.key3, &context->u.des3.iv3, |
context->u.des3.key3, &context->u.des3.iv3, |
dest, (void*)src, len); |
dest, (void*)src, len); |
break; |
break; |
|
|
#ifdef WITH_RC4 |
|
case SSH_CIPHER_RC4: |
|
/* CRC-32 attack? */ |
|
rc4_decrypt(&context->u.rc4, dest, src, len); |
|
break; |
|
#endif /* WITH_RC4 */ |
|
|
|
case SSH_CIPHER_BLOWFISH: |
case SSH_CIPHER_BLOWFISH: |
detect_cbc_attack(src, len); |
detect_cbc_attack(src, len); |