aboutsummaryrefslogtreecommitdiff
path: root/libssh/dh.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2008-03-03 14:51:35 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2008-03-03 14:51:35 +0000
commit01470097c6ff22b3c1a8c4383ae08a2ad3ce0ff8 (patch)
treecb0a7cd01ed647ca4c2d19e534556d48bba8cd57 /libssh/dh.c
parentfeccd44ef59329f3bfb8963e473a14e43e1aa2ec (diff)
downloadlibssh-01470097c6ff22b3c1a8c4383ae08a2ad3ce0ff8.tar.gz
libssh-01470097c6ff22b3c1a8c4383ae08a2ad3ce0ff8.tar.xz
libssh-01470097c6ff22b3c1a8c4383ae08a2ad3ce0ff8.zip
fix bug #0000002 : in_socket_buffer and out_socket_buffer memleak +
"g" and "p" O(1) memleak. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@134 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/dh.c')
-rw-r--r--libssh/dh.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/libssh/dh.c b/libssh/dh.c
index 937ca6a4..a7f4e775 100644
--- a/libssh/dh.c
+++ b/libssh/dh.c
@@ -65,6 +65,7 @@ static unsigned char p_value[] = {
static unsigned long g_int = 2 ; /* G is defined as 2 by the ssh2 standards */
static bignum g;
static bignum p;
+static int ssh_crypto_inited=0;
/* maybe it might be enhanced .... */
/* XXX Do it. */
@@ -84,10 +85,10 @@ int ssh_get_random(void *where, int len, int strong){
}
}
+
/* it inits the values g and p which are used for DH key agreement */
void ssh_crypto_init(){
- static int init=0;
- if(!init){
+ if(ssh_crypto_inited == 0){
#ifdef HAVE_LIBGCRYPT
gcry_check_version(NULL);
if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P,0))
@@ -105,10 +106,18 @@ void ssh_crypto_init(){
bignum_bin2bn(p_value,P_LEN,p);
OpenSSL_add_all_algorithms();
#endif
- init++;
+ ssh_crypto_inited++;
}
}
+void ssh_crypto_finalize(){
+ if(ssh_crypto_inited){
+ bignum_free(g);
+ bignum_free(p);
+ ssh_crypto_inited=0;
+ }
+}
+
/* prints the bignum on stderr */
void ssh_print_bignum(char *which,bignum num){
#ifdef HAVE_LIBGCRYPT