summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/ntru/ntru_drbg.c
diff options
context:
space:
mode:
authorRomain Francoise <rfrancoise@debian.org>2014-04-15 19:34:32 +0200
committerRomain Francoise <rfrancoise@debian.org>2014-04-15 19:34:32 +0200
commitc5ebfc7b9c16551fe825dc1d79c3f7e2f096f6c9 (patch)
treed4e2118cbd411caa1a0528eac831030109bc6e65 /src/libstrongswan/plugins/ntru/ntru_drbg.c
parent15fb7904f4431a6e7c305fd08732458f7f885e7e (diff)
downloadvyos-strongswan-c5ebfc7b9c16551fe825dc1d79c3f7e2f096f6c9.tar.gz
vyos-strongswan-c5ebfc7b9c16551fe825dc1d79c3f7e2f096f6c9.zip
Import upstream version 5.1.3
Diffstat (limited to 'src/libstrongswan/plugins/ntru/ntru_drbg.c')
-rw-r--r--src/libstrongswan/plugins/ntru/ntru_drbg.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/libstrongswan/plugins/ntru/ntru_drbg.c b/src/libstrongswan/plugins/ntru/ntru_drbg.c
index 181a58939..ef0d3d9c8 100644
--- a/src/libstrongswan/plugins/ntru/ntru_drbg.c
+++ b/src/libstrongswan/plugins/ntru/ntru_drbg.c
@@ -67,6 +67,10 @@ struct private_ntru_drbg_t {
*/
chunk_t value;
+ /**
+ * reference count
+ */
+ refcount_t ref;
};
/**
@@ -180,13 +184,23 @@ METHOD(ntru_drbg_t, generate, bool,
return TRUE;
}
+METHOD(ntru_drbg_t, get_ref, ntru_drbg_t*,
+ private_ntru_drbg_t *this)
+{
+ ref_get(&this->ref);
+ return &this->public;
+}
+
METHOD(ntru_drbg_t, destroy, void,
private_ntru_drbg_t *this)
{
- this->hmac->destroy(this->hmac);
- chunk_clear(&this->key);
- chunk_clear(&this->value);
- free(this);
+ if (ref_put(&this->ref))
+ {
+ this->hmac->destroy(this->hmac);
+ chunk_clear(&this->key);
+ chunk_clear(&this->value);
+ free(this);
+ }
}
/*
@@ -238,6 +252,7 @@ ntru_drbg_t *ntru_drbg_create(u_int32_t strength, chunk_t pers_str,
.get_strength = _get_strength,
.reseed = _reseed,
.generate = _generate,
+ .get_ref = _get_ref,
.destroy = _destroy,
},
.strength = strength,
@@ -247,6 +262,7 @@ ntru_drbg_t *ntru_drbg_create(u_int32_t strength, chunk_t pers_str,
.value = chunk_alloc(hmac->get_block_size(hmac)),
.max_requests = max_requests,
.reseed_counter = 1,
+ .ref = 1,
);
memset(this->key.ptr, 0x00, this->key.len);