aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-18 08:07:11 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-18 08:07:11 +0000
commite4c521d896dba8750f7e3cc054e5fdd56dca5252 (patch)
treefbf6f45d1208c1cdcad1b1f7dfe7a6a503b36f81
parent70b422d0fbc9c6c4fd4607ac9aabe51c5ec6554e (diff)
downloadlibssh-e4c521d896dba8750f7e3cc054e5fdd56dca5252.tar.gz
libssh-e4c521d896dba8750f7e3cc054e5fdd56dca5252.tar.xz
libssh-e4c521d896dba8750f7e3cc054e5fdd56dca5252.zip
Use a reference counter for the crypto functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@533 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--libssh/dh.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/libssh/dh.c b/libssh/dh.c
index 619a4d2a..bb22fcf5 100644
--- a/libssh/dh.c
+++ b/libssh/dh.c
@@ -72,7 +72,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;
+static unsigned int ssh_crypto_initialized_ref_count = 0;
int ssh_get_random(void *where, int len, int strong){
@@ -101,7 +101,7 @@ int ssh_get_random(void *where, int len, int strong){
* FIXME: Make the function thread safe by adding a semaphore or mutex.
*/
int ssh_crypto_init(void) {
- if (ssh_crypto_inited == 0) {
+ if (ssh_crypto_initialized_ref_count == 0) {
#ifdef HAVE_LIBGCRYPT
gcry_check_version(NULL);
@@ -134,19 +134,23 @@ int ssh_crypto_init(void) {
bignum_bin2bn(p_value, P_LEN, p);
OpenSSL_add_all_algorithms();
#endif
- ssh_crypto_inited++;
}
+ ssh_crypto_initialized_ref_count++;
+
return 0;
}
void ssh_crypto_finalize(void) {
- if(ssh_crypto_inited) {
+ if (ssh_crypto_initialized_ref_count) {
+ ssh_crypto_initialized_ref_count--;
+ }
+
+ if (ssh_crypto_initialized_ref_count == 0) {
bignum_free(g);
g = NULL;
bignum_free(p);
p = NULL;
- ssh_crypto_inited = 0;
}
}