version 1.87, 2013/01/26 06:11:05 |
version 1.88, 2013/04/19 01:06:50 |
|
|
u_int discard_len; |
u_int discard_len; |
u_int cbc_mode; |
u_int cbc_mode; |
const EVP_CIPHER *(*evptype)(void); |
const EVP_CIPHER *(*evptype)(void); |
} ciphers[] = { |
}; |
|
|
|
static const struct Cipher ciphers[] = { |
{ "none", SSH_CIPHER_NONE, 8, 0, 0, 0, 0, 0, EVP_enc_null }, |
{ "none", SSH_CIPHER_NONE, 8, 0, 0, 0, 0, 0, EVP_enc_null }, |
{ "des", SSH_CIPHER_DES, 8, 8, 0, 0, 0, 1, EVP_des_cbc }, |
{ "des", SSH_CIPHER_DES, 8, 8, 0, 0, 0, 1, EVP_des_cbc }, |
{ "3des", SSH_CIPHER_3DES, 8, 16, 0, 0, 0, 1, evp_ssh1_3des }, |
{ "3des", SSH_CIPHER_3DES, 8, 16, 0, 0, 0, 1, evp_ssh1_3des }, |
|
|
|
|
/*--*/ |
/*--*/ |
|
|
|
/* Returns a comma-separated list of supported ciphers. */ |
|
char * |
|
cipher_alg_list(void) |
|
{ |
|
char *ret = NULL; |
|
size_t nlen, rlen = 0; |
|
const Cipher *c; |
|
|
|
for (c = ciphers; c->name != NULL; c++) { |
|
if (c->number != SSH_CIPHER_SSH2) |
|
continue; |
|
if (ret != NULL) |
|
ret[rlen++] = '\n'; |
|
nlen = strlen(c->name); |
|
ret = xrealloc(ret, 1, rlen + nlen + 2); |
|
memcpy(ret + rlen, c->name, nlen + 1); |
|
rlen += nlen; |
|
} |
|
return ret; |
|
} |
|
|
u_int |
u_int |
cipher_blocksize(const Cipher *c) |
cipher_blocksize(const Cipher *c) |
{ |
{ |
|
|
return mask; |
return mask; |
} |
} |
|
|
Cipher * |
const Cipher * |
cipher_by_name(const char *name) |
cipher_by_name(const char *name) |
{ |
{ |
Cipher *c; |
const Cipher *c; |
for (c = ciphers; c->name != NULL; c++) |
for (c = ciphers; c->name != NULL; c++) |
if (strcmp(c->name, name) == 0) |
if (strcmp(c->name, name) == 0) |
return c; |
return c; |
return NULL; |
return NULL; |
} |
} |
|
|
Cipher * |
const Cipher * |
cipher_by_number(int id) |
cipher_by_number(int id) |
{ |
{ |
Cipher *c; |
const Cipher *c; |
for (c = ciphers; c->name != NULL; c++) |
for (c = ciphers; c->name != NULL; c++) |
if (c->number == id) |
if (c->number == id) |
return c; |
return c; |
|
|
int |
int |
ciphers_valid(const char *names) |
ciphers_valid(const char *names) |
{ |
{ |
Cipher *c; |
const Cipher *c; |
char *cipher_list, *cp; |
char *cipher_list, *cp; |
char *p; |
char *p; |
|
|
|
|
int |
int |
cipher_number(const char *name) |
cipher_number(const char *name) |
{ |
{ |
Cipher *c; |
const Cipher *c; |
if (name == NULL) |
if (name == NULL) |
return -1; |
return -1; |
for (c = ciphers; c->name != NULL; c++) |
for (c = ciphers; c->name != NULL; c++) |
|
|
char * |
char * |
cipher_name(int id) |
cipher_name(int id) |
{ |
{ |
Cipher *c = cipher_by_number(id); |
const Cipher *c = cipher_by_number(id); |
return (c==NULL) ? "<unknown>" : c->name; |
return (c==NULL) ? "<unknown>" : c->name; |
} |
} |
|
|
void |
void |
cipher_init(CipherContext *cc, Cipher *cipher, |
cipher_init(CipherContext *cc, const Cipher *cipher, |
const u_char *key, u_int keylen, const u_char *iv, u_int ivlen, |
const u_char *key, u_int keylen, const u_char *iv, u_int ivlen, |
int do_encrypt) |
int do_encrypt) |
{ |
{ |
|
|
*/ |
*/ |
|
|
void |
void |
cipher_set_key_string(CipherContext *cc, Cipher *cipher, |
cipher_set_key_string(CipherContext *cc, const Cipher *cipher, |
const char *passphrase, int do_encrypt) |
const char *passphrase, int do_encrypt) |
{ |
{ |
MD5_CTX md; |
MD5_CTX md; |
|
|
int |
int |
cipher_get_keyiv_len(const CipherContext *cc) |
cipher_get_keyiv_len(const CipherContext *cc) |
{ |
{ |
Cipher *c = cc->cipher; |
const Cipher *c = cc->cipher; |
int ivlen; |
int ivlen; |
|
|
if (c->number == SSH_CIPHER_3DES) |
if (c->number == SSH_CIPHER_3DES) |
|
|
void |
void |
cipher_get_keyiv(CipherContext *cc, u_char *iv, u_int len) |
cipher_get_keyiv(CipherContext *cc, u_char *iv, u_int len) |
{ |
{ |
Cipher *c = cc->cipher; |
const Cipher *c = cc->cipher; |
int evplen; |
int evplen; |
|
|
switch (c->number) { |
switch (c->number) { |
|
|
void |
void |
cipher_set_keyiv(CipherContext *cc, u_char *iv) |
cipher_set_keyiv(CipherContext *cc, u_char *iv) |
{ |
{ |
Cipher *c = cc->cipher; |
const Cipher *c = cc->cipher; |
int evplen = 0; |
int evplen = 0; |
|
|
switch (c->number) { |
switch (c->number) { |
|
|
int |
int |
cipher_get_keycontext(const CipherContext *cc, u_char *dat) |
cipher_get_keycontext(const CipherContext *cc, u_char *dat) |
{ |
{ |
Cipher *c = cc->cipher; |
const Cipher *c = cc->cipher; |
int plen = 0; |
int plen = 0; |
|
|
if (c->evptype == EVP_rc4) { |
if (c->evptype == EVP_rc4) { |
|
|
void |
void |
cipher_set_keycontext(CipherContext *cc, u_char *dat) |
cipher_set_keycontext(CipherContext *cc, u_char *dat) |
{ |
{ |
Cipher *c = cc->cipher; |
const Cipher *c = cc->cipher; |
int plen; |
int plen; |
|
|
if (c->evptype == EVP_rc4) { |
if (c->evptype == EVP_rc4) { |