diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-17 13:13:14 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-17 13:13:14 +0000 |
commit | 3216520b4caa54a6269a72b6ba74f57bacd1b32f (patch) | |
tree | 7986aa6db7b90b103ca05404706d9acd88da07c0 /libssh/wrapper.c | |
parent | 09fdf0e8e69b176290b4dbef8d627fb2e2527af3 (diff) | |
download | libssh-3216520b4caa54a6269a72b6ba74f57bacd1b32f.tar.gz libssh-3216520b4caa54a6269a72b6ba74f57bacd1b32f.tar.xz libssh-3216520b4caa54a6269a72b6ba74f57bacd1b32f.zip |
Reformat some of the code.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@521 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/wrapper.c')
-rw-r--r-- | libssh/wrapper.c | 156 |
1 files changed, 87 insertions, 69 deletions
diff --git a/libssh/wrapper.c b/libssh/wrapper.c index 84925273..a825f3ba 100644 --- a/libssh/wrapper.c +++ b/libssh/wrapper.c @@ -708,17 +708,18 @@ static struct crypto_struct ssh_ciphertab[] = { #endif /* OPENSSL_CRYPTO */ /* it allocates a new cipher structure based on its offset into the global table */ -static struct crypto_struct *cipher_new(int offset){ - struct crypto_struct *cipher; +static struct crypto_struct *cipher_new(int offset) { + struct crypto_struct *cipher = NULL; - cipher = malloc(sizeof(struct crypto_struct)); - if (cipher == NULL) { - return NULL; - } + cipher = malloc(sizeof(struct crypto_struct)); + if (cipher == NULL) { + return NULL; + } - /* note the memcpy will copy the pointers : so, you shouldn't free them */ - memcpy(cipher,&ssh_ciphertab[offset],sizeof(*cipher)); - return cipher; + /* note the memcpy will copy the pointers : so, you shouldn't free them */ + memcpy(cipher, &ssh_ciphertab[offset], sizeof(*cipher)); + + return cipher; } static void cipher_free(struct crypto_struct *cipher) { @@ -780,77 +781,94 @@ void crypto_free(CRYPTO *crypto){ } static int crypt_set_algorithms2(SSH_SESSION *session){ - /* we must scan the kex entries to find crypto algorithms and set their appropriate structure */ - int i=0; - /* out */ - char *wanted=session->client_kex.methods[SSH_CRYPT_C_S]; - while(ssh_ciphertab[i].name && strcmp(wanted,ssh_ciphertab[i].name)) - i++; - if(!ssh_ciphertab[i].name){ - ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms2 : no crypto algorithm function found for %s",wanted); - return SSH_ERROR; - } - ssh_log(session,SSH_LOG_PACKET,"Set output algorithm %s",wanted); + const char *wanted; + int i = 0; + + /* we must scan the kex entries to find crypto algorithms and set their appropriate structure */ + /* out */ + wanted = session->client_kex.methods[SSH_CRYPT_C_S]; + while (ssh_ciphertab[i].name && strcmp(wanted, ssh_ciphertab[i].name)) { + i++; + } - session->next_crypto->out_cipher = cipher_new(i); - if (session->next_crypto->out_cipher == NULL) { - ssh_set_error(session, SSH_FATAL, "No space left"); - return SSH_ERROR; - } + 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; + } + ssh_log(session, SSH_LOG_PACKET, "Set output algorithm to %s", wanted); - i=0; - /* in */ - wanted=session->client_kex.methods[SSH_CRYPT_S_C]; - while(ssh_ciphertab[i].name && strcmp(wanted,ssh_ciphertab[i].name)) - i++; - if(!ssh_ciphertab[i].name){ - ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms : no crypto algorithm function found for %s",wanted); - return SSH_ERROR; - } - ssh_log(session,SSH_LOG_PACKET,"Set input algorithm %s",wanted); + session->next_crypto->out_cipher = cipher_new(i); + if (session->next_crypto->out_cipher == NULL) { + ssh_set_error(session, SSH_FATAL, "No space left"); + return SSH_ERROR; + } + i = 0; - session->next_crypto->in_cipher = cipher_new(i); - if (session->next_crypto->in_cipher == NULL) { - ssh_set_error(session, SSH_FATAL, "No space left"); - return SSH_ERROR; - } + /* in */ + wanted = session->client_kex.methods[SSH_CRYPT_S_C]; + while (ssh_ciphertab[i].name && strcmp(wanted, ssh_ciphertab[i].name)) { + i++; + } - /* compression */ - if(strstr(session->client_kex.methods[SSH_COMP_C_S],"zlib")) - session->next_crypto->do_compress_out=1; - if(strstr(session->client_kex.methods[SSH_COMP_S_C],"zlib")) - session->next_crypto->do_compress_in=1; - return SSH_OK; + 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; + } + ssh_log(session, SSH_LOG_PACKET, "Set input algorithm to %s", wanted); + + session->next_crypto->in_cipher = cipher_new(i); + if (session->next_crypto->in_cipher == NULL) { + ssh_set_error(session, SSH_FATAL, "Not enough space"); + return SSH_ERROR; + } + + /* compression */ + if (strstr(session->client_kex.methods[SSH_COMP_C_S], "zlib")) { + session->next_crypto->do_compress_out = 1; + } + if (strstr(session->client_kex.methods[SSH_COMP_S_C], "zlib")) { + session->next_crypto->do_compress_in = 1; + } + + return SSH_OK; } -static int crypt_set_algorithms1(SSH_SESSION *session){ - int i=0; - /* right now, we force 3des-cbc to be taken */ - while(ssh_ciphertab[i].name && strcmp(ssh_ciphertab[i].name,"3des-cbc-ssh1")) - ++i; - if(!ssh_ciphertab[i].name){ - ssh_set_error(session,SSH_FATAL,"cipher 3des-cbc-ssh1 not found !"); - return -1; - } +static int crypt_set_algorithms1(SSH_SESSION *session) { + int i = 0; - session->next_crypto->out_cipher = cipher_new(i); - if (session->next_crypto->out_cipher == NULL) { - ssh_set_error(session, SSH_FATAL, "No space left"); - return SSH_ERROR; - } + /* right now, we force 3des-cbc to be taken */ + while (ssh_ciphertab[i].name && strcmp(ssh_ciphertab[i].name, + "3des-cbc-ssh1")) { + i++; + } - session->next_crypto->in_cipher = cipher_new(i); - if (session->next_crypto->in_cipher == NULL) { - ssh_set_error(session, SSH_FATAL, "No space left"); - return SSH_ERROR; - } + if (ssh_ciphertab[i].name == NULL) { + ssh_set_error(session, SSH_FATAL, "cipher 3des-cbc-ssh1 not found!"); + return -1; + } - return SSH_OK; + session->next_crypto->out_cipher = cipher_new(i); + if (session->next_crypto->out_cipher == NULL) { + ssh_set_error(session, SSH_FATAL, "No space left"); + return SSH_ERROR; + } + + session->next_crypto->in_cipher = cipher_new(i); + if (session->next_crypto->in_cipher == NULL) { + ssh_set_error(session, SSH_FATAL, "No space left"); + return SSH_ERROR; + } + + return SSH_OK; } -int crypt_set_algorithms(SSH_SESSION *session){ - return session->version==1?crypt_set_algorithms1(session): - crypt_set_algorithms2(session); +int crypt_set_algorithms(SSH_SESSION *session) { + return (session->version == 1) ? crypt_set_algorithms1(session) : + crypt_set_algorithms2(session); } // TODO Obviously too much cut and paste here |