summaryrefslogtreecommitdiffstats
path: root/src/lib/cryptolink/botan_link.cc
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2018-08-23 18:10:10 +0200
committerFrancis Dupont <fdupont@isc.org>2018-11-04 07:05:08 +0100
commit9e742d3034280a840481b7ad6f321f8e95e6029b (patch)
tree92eba61e1eb3cba1922c37216232ac44ff3cd2b0 /src/lib/cryptolink/botan_link.cc
parent[master] Added ChangeLog for #194. (diff)
downloadkea-9e742d3034280a840481b7ad6f321f8e95e6029b.tar.xz
kea-9e742d3034280a840481b7ad6f321f8e95e6029b.zip
[29-cryptolink-random-generator] Added RNG support
Diffstat (limited to 'src/lib/cryptolink/botan_link.cc')
-rw-r--r--src/lib/cryptolink/botan_link.cc41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/lib/cryptolink/botan_link.cc b/src/lib/cryptolink/botan_link.cc
index c7f40cb182..714663d507 100644
--- a/src/lib/cryptolink/botan_link.cc
+++ b/src/lib/cryptolink/botan_link.cc
@@ -9,9 +9,11 @@
#include <cryptolink/cryptolink.h>
#include <cryptolink/crypto_hash.h>
#include <cryptolink/crypto_hmac.h>
+#include <cryptolink/crypto_rng.h>
#include <botan/exceptn.h>
#include <botan/version.h>
+#include <botan/auto_rng.h>
namespace isc {
namespace cryptolink {
@@ -25,16 +27,53 @@ CryptoLink::~CryptoLink() {
delete impl_;
}
+/// \brief Botan implementation of RNG.
+class RNGImpl : public RNG {
+public:
+ RNGImpl() {
+ rng.reset(new Botan::AutoSeeded_RNG());
+ }
+
+ ~RNGImpl() {
+ }
+
+private:
+ std::vector<uint8_t> random(size_t len) {
+ std::vector<uint8_t> data;
+ if (len > 0) {
+ data.resize(len);
+ try {
+ rng->randomize(&data[0], len);
+ } catch (const Botan::Exception& ex) {
+ isc_throw(isc::cryptolink::LibraryError,
+ "Botan error: " << ex.what());
+ }
+ }
+ return (data);
+ }
+
+ boost::shared_ptr<Botan::RandomNumberGenerator> rng;
+};
+
void
CryptoLink::initialize() {
CryptoLink& c = getCryptoLinkInternal();
- if (c.impl_ == NULL) {
+ if (!c.impl_) {
try {
c.impl_ = new CryptoLinkImpl();
} catch (const Botan::Exception& ex) {
isc_throw(InitializationError, "Botan error: " << ex.what());
}
}
+ if (!c.rng_) {
+ try {
+ c.rng_.reset(new RNGImpl());
+ } catch (const Botan::Exception& ex) {
+ isc_throw(InitializationError, "Botan error: " << ex.what());
+ }
+ }
+ // A not yet fixed bug makes RNG to be destroyed after memory pool...
+ atexit([]{ getCryptoLink().getRNG().reset(); });
}
std::string