aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-09-26 10:56:56 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-10-19 22:01:28 +0200
commit504afadbf064de41c5d7b60c1d68959dc3352ac6 (patch)
treedcafa8339cf4a203a600c8bb15b507ba646a86ae
parent922012f04c798c87104a6aba665407e5b780a0d2 (diff)
downloadlibssh-504afadbf064de41c5d7b60c1d68959dc3352ac6.tar.gz
libssh-504afadbf064de41c5d7b60c1d68959dc3352ac6.tar.xz
libssh-504afadbf064de41c5d7b60c1d68959dc3352ac6.zip
wrapper: Fix size type and loops in crypt_set_algorithms_server()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/wrapper.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/wrapper.c b/src/wrapper.c
index d6baaf4b..303c04f6 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -400,9 +400,11 @@ int crypt_set_algorithms_client(ssh_session session)
#ifdef WITH_SERVER
int crypt_set_algorithms_server(ssh_session session){
const char *method = NULL;
- int i = 0;
+ size_t i = 0;
struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
struct ssh_hmac_struct *ssh_hmactab=ssh_get_hmactab();
+ int cmp;
+
if (session == NULL) {
return SSH_ERROR;
@@ -416,8 +418,6 @@ int crypt_set_algorithms_server(ssh_session session){
method = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
- int cmp;
-
cmp = strcmp(method, ssh_ciphertab[i].name);
if (cmp == 0) {
break;
@@ -436,7 +436,7 @@ int crypt_set_algorithms_server(ssh_session session){
ssh_set_error_oom(session);
return SSH_ERROR;
}
- i=0;
+
if (session->next_crypto->out_cipher->aead_encrypt != NULL){
/* this cipher has integrated MAC */
if (session->next_crypto->out_cipher->ciphertype == SSH_AEAD_CHACHA20_POLY1305) {
@@ -451,8 +451,11 @@ int crypt_set_algorithms_server(ssh_session session){
}
/* HMAC algorithm selection */
- while (ssh_hmactab[i].name && strcmp(method, ssh_hmactab[i].name)) {
- i++;
+ for (i = 0; ssh_hmactab[i].name != NULL; i++) {
+ cmp = strcmp(method, ssh_hmactab[i].name);
+ if (cmp == 0) {
+ break;
+ }
}
if (ssh_hmactab[i].name == NULL) {
@@ -466,16 +469,13 @@ int crypt_set_algorithms_server(ssh_session session){
session->next_crypto->out_hmac = ssh_hmactab[i].hmac_type;
/* in */
- i=0;
method = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
for (i = 0; ssh_ciphertab[i].name; i++) {
- int cmp;
-
- cmp = strcmp(method, ssh_ciphertab[i].name);
- if (cmp == 0) {
- break;
- }
+ cmp = strcmp(method, ssh_ciphertab[i].name);
+ if (cmp == 0) {
+ break;
+ }
}
if (ssh_ciphertab[i].name == NULL) {
@@ -490,7 +490,6 @@ int crypt_set_algorithms_server(ssh_session session){
ssh_set_error_oom(session);
return SSH_ERROR;
}
- i=0;
if (session->next_crypto->in_cipher->aead_encrypt != NULL){
/* this cipher has integrated MAC */
@@ -505,12 +504,10 @@ int crypt_set_algorithms_server(ssh_session session){
}
for (i = 0; ssh_hmactab[i].name != NULL; i++) {
- int cmp;
-
- cmp = strcmp(method, ssh_hmactab[i].name);
- if (cmp == 0) {
- break;
- }
+ cmp = strcmp(method, ssh_hmactab[i].name);
+ if (cmp == 0) {
+ break;
+ }
}
if (ssh_hmactab[i].name == NULL) {
@@ -522,7 +519,6 @@ int crypt_set_algorithms_server(ssh_session session){
SSH_LOG(SSH_LOG_PACKET, "Set HMAC input algorithm to %s", method);
session->next_crypto->in_hmac = ssh_hmactab[i].hmac_type;
- i=0;
/* compression */
method = session->next_crypto->kex_methods[SSH_COMP_C_S];