1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-27 13:21:11 +03:00

wrapper: Move dh cleanup into dh.c

Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Aris Adamantiadis
2018-11-06 22:22:59 +01:00
committed by Andreas Schneider
parent 9407065879
commit 40faa98c5e
4 changed files with 9 additions and 14 deletions

View File

@@ -45,7 +45,7 @@ void ssh_server_dh_init(ssh_session session);
#endif /* WITH_SERVER */ #endif /* WITH_SERVER */
int ssh_dh_init_common(ssh_session session); int ssh_dh_init_common(ssh_session session);
void ssh_dh_cleanup(ssh_session session); void ssh_dh_cleanup(struct ssh_crypto_struct *crypto);
int ssh_dh_generate_secret(ssh_session session, bignum dest); int ssh_dh_generate_secret(ssh_session session, bignum dest);
#endif /* DH_H_ */ #endif /* DH_H_ */

View File

@@ -85,7 +85,7 @@ int ssh_client_dhgex_init(ssh_session session)
} }
return rc; return rc;
error: error:
ssh_dh_cleanup(session); ssh_dh_cleanup(session->next_crypto);
return SSH_ERROR; return SSH_ERROR;
} }
@@ -201,7 +201,7 @@ error:
if(!bignum_ctx_invalid(ctx)) { if(!bignum_ctx_invalid(ctx)) {
bignum_ctx_free(ctx); bignum_ctx_free(ctx);
} }
ssh_dh_cleanup(session); ssh_dh_cleanup(session->next_crypto);
session->session_state = SSH_SESSION_STATE_ERROR; session->session_state = SSH_SESSION_STATE_ERROR;
return SSH_PACKET_USED; return SSH_PACKET_USED;
@@ -252,7 +252,7 @@ static SSH_PACKET_CALLBACK(ssh_packet_client_dhgex_reply)
return SSH_PACKET_USED; return SSH_PACKET_USED;
error: error:
ssh_dh_cleanup(session); ssh_dh_cleanup(session->next_crypto);
session->session_state = SSH_SESSION_STATE_ERROR; session->session_state = SSH_SESSION_STATE_ERROR;
return SSH_PACKET_USED; return SSH_PACKET_USED;

View File

@@ -357,8 +357,7 @@ int ssh_dh_init_common(ssh_session session){
} }
} }
void ssh_dh_cleanup(ssh_session session){ void ssh_dh_cleanup(struct ssh_crypto_struct *crypto){
struct ssh_crypto_struct *crypto=session->next_crypto;
bignum_safe_free(crypto->x); bignum_safe_free(crypto->x);
bignum_safe_free(crypto->y); bignum_safe_free(crypto->y);
bignum_safe_free(crypto->e); bignum_safe_free(crypto->e);
@@ -521,7 +520,7 @@ int ssh_client_dh_init(ssh_session session){
rc = ssh_packet_send(session); rc = ssh_packet_send(session);
return rc; return rc;
error: error:
ssh_dh_cleanup(session); ssh_dh_cleanup(session->next_crypto);
return SSH_ERROR; return SSH_ERROR;
} }
@@ -566,7 +565,7 @@ SSH_PACKET_CALLBACK(ssh_packet_client_dh_reply){
session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
return SSH_PACKET_USED; return SSH_PACKET_USED;
error: error:
ssh_dh_cleanup(session); ssh_dh_cleanup(session->next_crypto);
session->session_state=SSH_SESSION_STATE_ERROR; session->session_state=SSH_SESSION_STATE_ERROR;
return SSH_PACKET_USED; return SSH_PACKET_USED;
} }
@@ -689,15 +688,14 @@ static SSH_PACKET_CALLBACK(ssh_packet_server_dh_init)
} }
SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_NEWKEYS sent"); SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_NEWKEYS sent");
session->dh_handshake_state = DH_STATE_NEWKEYS_SENT; session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
ssh_dh_cleanup(session);
return SSH_PACKET_USED; return SSH_PACKET_USED;
error: error:
ssh_dh_cleanup(session);
if (!bignum_ctx_invalid(ctx)) { if (!bignum_ctx_invalid(ctx)) {
bignum_ctx_free(ctx); bignum_ctx_free(ctx);
} }
session->session_state = SSH_SESSION_STATE_ERROR; session->session_state = SSH_SESSION_STATE_ERROR;
ssh_dh_cleanup(session->next_crypto);
return SSH_PACKET_USED; return SSH_PACKET_USED;
} }

View File

@@ -165,10 +165,7 @@ void crypto_free(struct ssh_crypto_struct *crypto)
cipher_free(crypto->in_cipher); cipher_free(crypto->in_cipher);
cipher_free(crypto->out_cipher); cipher_free(crypto->out_cipher);
bignum_safe_free(crypto->e); ssh_dh_cleanup(crypto);
bignum_safe_free(crypto->f);
bignum_safe_free(crypto->x);
bignum_safe_free(crypto->y);
bignum_safe_free(crypto->k); bignum_safe_free(crypto->k);
#ifdef HAVE_ECDH #ifdef HAVE_ECDH
SAFE_FREE(crypto->ecdh_client_pubkey); SAFE_FREE(crypto->ecdh_client_pubkey);