Reformat some of the code.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@521 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-17 13:13:14 +00:00
parent 09fdf0e8e6
commit 3216520b4c

View File

@@ -709,7 +709,7 @@ static struct crypto_struct ssh_ciphertab[] = {
/* it allocates a new cipher structure based on its offset into the global table */ /* it allocates a new cipher structure based on its offset into the global table */
static struct crypto_struct *cipher_new(int offset) { static struct crypto_struct *cipher_new(int offset) {
struct crypto_struct *cipher; struct crypto_struct *cipher = NULL;
cipher = malloc(sizeof(struct crypto_struct)); cipher = malloc(sizeof(struct crypto_struct));
if (cipher == NULL) { if (cipher == NULL) {
@@ -718,6 +718,7 @@ static struct crypto_struct *cipher_new(int offset){
/* note the memcpy will copy the pointers : so, you shouldn't free them */ /* note the memcpy will copy the pointers : so, you shouldn't free them */
memcpy(cipher, &ssh_ciphertab[offset], sizeof(*cipher)); memcpy(cipher, &ssh_ciphertab[offset], sizeof(*cipher));
return cipher; return cipher;
} }
@@ -780,55 +781,72 @@ void crypto_free(CRYPTO *crypto){
} }
static int crypt_set_algorithms2(SSH_SESSION *session){ static int crypt_set_algorithms2(SSH_SESSION *session){
/* we must scan the kex entries to find crypto algorithms and set their appropriate structure */ const char *wanted;
int i = 0; int i = 0;
/* we must scan the kex entries to find crypto algorithms and set their appropriate structure */
/* out */ /* out */
char *wanted=session->client_kex.methods[SSH_CRYPT_C_S]; wanted = session->client_kex.methods[SSH_CRYPT_C_S];
while(ssh_ciphertab[i].name && strcmp(wanted,ssh_ciphertab[i].name)) while (ssh_ciphertab[i].name && strcmp(wanted, ssh_ciphertab[i].name)) {
i++; i++;
if(!ssh_ciphertab[i].name){ }
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms2 : no crypto algorithm function found for %s",wanted);
if (ssh_ciphertab[i].name == NULL) {
ssh_set_error(session, SSH_FATAL,
"Crypt_set_algorithms2: no crypto algorithm function found for %s",
wanted);
return SSH_ERROR; return SSH_ERROR;
} }
ssh_log(session,SSH_LOG_PACKET,"Set output algorithm %s",wanted); ssh_log(session, SSH_LOG_PACKET, "Set output algorithm to %s", wanted);
session->next_crypto->out_cipher = cipher_new(i); session->next_crypto->out_cipher = cipher_new(i);
if (session->next_crypto->out_cipher == NULL) { if (session->next_crypto->out_cipher == NULL) {
ssh_set_error(session, SSH_FATAL, "No space left"); ssh_set_error(session, SSH_FATAL, "No space left");
return SSH_ERROR; return SSH_ERROR;
} }
i = 0; i = 0;
/* in */ /* in */
wanted = session->client_kex.methods[SSH_CRYPT_S_C]; wanted = session->client_kex.methods[SSH_CRYPT_S_C];
while(ssh_ciphertab[i].name && strcmp(wanted,ssh_ciphertab[i].name)) while (ssh_ciphertab[i].name && strcmp(wanted, ssh_ciphertab[i].name)) {
i++; i++;
if(!ssh_ciphertab[i].name){ }
ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms : no crypto algorithm function found for %s",wanted);
if (ssh_ciphertab[i].name == NULL) {
ssh_set_error(session, SSH_FATAL,
"Crypt_set_algorithms: no crypto algorithm function found for %s",
wanted);
return SSH_ERROR; return SSH_ERROR;
} }
ssh_log(session,SSH_LOG_PACKET,"Set input algorithm %s",wanted); ssh_log(session, SSH_LOG_PACKET, "Set input algorithm to %s", wanted);
session->next_crypto->in_cipher = cipher_new(i); session->next_crypto->in_cipher = cipher_new(i);
if (session->next_crypto->in_cipher == NULL) { if (session->next_crypto->in_cipher == NULL) {
ssh_set_error(session, SSH_FATAL, "No space left"); ssh_set_error(session, SSH_FATAL, "Not enough space");
return SSH_ERROR; return SSH_ERROR;
} }
/* compression */ /* compression */
if(strstr(session->client_kex.methods[SSH_COMP_C_S],"zlib")) if (strstr(session->client_kex.methods[SSH_COMP_C_S], "zlib")) {
session->next_crypto->do_compress_out = 1; session->next_crypto->do_compress_out = 1;
if(strstr(session->client_kex.methods[SSH_COMP_S_C],"zlib")) }
if (strstr(session->client_kex.methods[SSH_COMP_S_C], "zlib")) {
session->next_crypto->do_compress_in = 1; session->next_crypto->do_compress_in = 1;
}
return SSH_OK; return SSH_OK;
} }
static int crypt_set_algorithms1(SSH_SESSION *session) { static int crypt_set_algorithms1(SSH_SESSION *session) {
int i = 0; int i = 0;
/* right now, we force 3des-cbc to be taken */ /* right now, we force 3des-cbc to be taken */
while(ssh_ciphertab[i].name && strcmp(ssh_ciphertab[i].name,"3des-cbc-ssh1")) while (ssh_ciphertab[i].name && strcmp(ssh_ciphertab[i].name,
++i; "3des-cbc-ssh1")) {
if(!ssh_ciphertab[i].name){ i++;
}
if (ssh_ciphertab[i].name == NULL) {
ssh_set_error(session, SSH_FATAL, "cipher 3des-cbc-ssh1 not found!"); ssh_set_error(session, SSH_FATAL, "cipher 3des-cbc-ssh1 not found!");
return -1; return -1;
} }
@@ -849,7 +867,7 @@ static int crypt_set_algorithms1(SSH_SESSION *session){
} }
int crypt_set_algorithms(SSH_SESSION *session) { int crypt_set_algorithms(SSH_SESSION *session) {
return session->version==1?crypt_set_algorithms1(session): return (session->version == 1) ? crypt_set_algorithms1(session) :
crypt_set_algorithms2(session); crypt_set_algorithms2(session);
} }