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

Improve crypto free functions.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@387 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-04 14:15:14 +00:00
parent b3a0c6d9cb
commit a7fbedf8d6

View File

@@ -462,25 +462,27 @@ static struct crypto_struct *cipher_new(int offset){
return cipher; return cipher;
} }
static void cipher_free(struct crypto_struct *cipher){ static void cipher_free(struct crypto_struct *cipher) {
#ifdef HAVE_LIBGCRYPT #ifdef HAVE_LIBGCRYPT
unsigned int i; unsigned int i;
#endif #endif
if (cipher == NULL) { if (cipher == NULL) {
return; return;
} }
if(cipher->key){ if(cipher->key) {
#ifdef HAVE_LIBGCRYPT #ifdef HAVE_LIBGCRYPT
for (i=0;i<cipher->keylen/sizeof (gcry_cipher_hd_t);i++) for (i = 0; i < (cipher->keylen / sizeof(gcry_cipher_hd_t)); i++) {
gcry_cipher_close(cipher->key[i]); gcry_cipher_close(cipher->key[i]);
}
#elif defined HAVE_LIBCRYPTO #elif defined HAVE_LIBCRYPTO
/* destroy the key */ /* destroy the key */
memset(cipher->key,0,cipher->keylen); memset(cipher->key, 0, cipher->keylen);
#endif #endif
free(cipher->key); SAFE_FREE(cipher->key);
} }
free(cipher); SAFE_FREE(cipher);
} }
CRYPTO *crypto_new(void) { CRYPTO *crypto_new(void) {
@@ -500,26 +502,22 @@ void crypto_free(CRYPTO *crypto){
if (crypto == NULL) { if (crypto == NULL) {
return; return;
} }
if(crypto->server_pubkey)
free(crypto->server_pubkey); SAFE_FREE(crypto->server_pubkey);
if(crypto->in_cipher)
cipher_free(crypto->in_cipher); cipher_free(crypto->in_cipher);
if(crypto->out_cipher)
cipher_free(crypto->out_cipher); cipher_free(crypto->out_cipher);
if(crypto->e)
bignum_free(crypto->e); bignum_free(crypto->e);
if(crypto->f)
bignum_free(crypto->f); bignum_free(crypto->f);
if(crypto->x)
bignum_free(crypto->x); bignum_free(crypto->x);
if(crypto->y)
bignum_free(crypto->y); bignum_free(crypto->y);
if(crypto->k)
bignum_free(crypto->k); bignum_free(crypto->k);
/* lot of other things */ /* lot of other things */
/* i'm lost in my own code. good work */ /* i'm lost in my own code. good work */
memset(crypto,0,sizeof(*crypto)); memset(crypto,0,sizeof(*crypto));
free(crypto);
SAFE_FREE(crypto);
} }
static int crypt_set_algorithms2(SSH_SESSION *session){ static int crypt_set_algorithms2(SSH_SESSION *session){