]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[29-cryptolink-random-generator] Updated random users 29-cryptolink-random-generator
authorFrancis Dupont <fdupont@isc.org>
Thu, 23 Aug 2018 17:02:00 +0000 (19:02 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sun, 4 Nov 2018 06:05:08 +0000 (01:05 -0500)
src/lib/dhcpsrv/host.cc
src/lib/util/random/random_number_generator.h
src/lib/util/range_utilities.h

index 1899e1c6dcea9019eca200e45667d5d701b93116..b225cce0ea9b5c70813afa76e015d40119e30aef 100644 (file)
@@ -5,16 +5,15 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <config.h>
+
 #include <dhcp/pkt4.h>
 #include <dhcpsrv/host.h>
 #include <util/encode/hex.h>
 #include <util/strutil.h>
 #include <asiolink/io_address.h>
-#include <boost/random.hpp>
-#include <boost/random/uniform_int_distribution.hpp>
-#include <boost/random/mersenne_twister.hpp>
+#include <cryptolink/crypto_rng.h>
 #include <exceptions/exceptions.h>
-#include <random>
+
 #include <sstream>
 
 using namespace isc::data;
@@ -23,7 +22,6 @@ using namespace isc::asiolink;
 namespace isc {
 namespace dhcp {
 
-
 AuthKey::AuthKey(const std::string key) {
     setAuthKey(key);
 }
@@ -34,23 +32,17 @@ AuthKey::AuthKey(void) {
 
 std::string
 AuthKey::getRandomKeyString() {
-    std::array <char, AuthKey::KEY_LEN> randomString;
-    
-    std::random_device rd;
-    boost::random::mt19937 gen(rd());
-
-    std::for_each(randomString.begin(), randomString.end() - 1,
-        [&gen](char& a){ boost::random::uniform_int_distribution<char> dist('!', '~');
-        a = dist(gen); } );
-
-    return std::string(randomString.begin(), randomString.end());
+    std::vector<uint8_t> rs = isc::cryptolink::random(AuthKey::KEY_LEN);
+    std::string result;
+    result.resize(rs.size());
+    memmove(&result[0], &rs[0], result.size());
+    return (result);
 }
 
 std::string 
 AuthKey::ToText() const {
-    //this will need enhancement if the stored container is not
-    //string
-    return authKey_;
+    // this will need enhancement if the stored container is not a string
+    return (authKey_);
 }
 
 void
index 3e63830e7c7e66fa7e4eab42de0c9dc72050326b..da3f0be407c444b2768ac32af955ea2d2bf0bdbc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -20,6 +20,8 @@
 #include <boost/random/uniform_real.hpp>
 #include <boost/random/variate_generator.hpp>
 
+/// PLEASE DO NOT USE THIS IN CRYPTOGRAPHICALLY SENSITIVE CODE.
+
 namespace isc {
 namespace util {
 namespace random {
index f11f0bc1cd8b78ba591c3d83dc0e194a7d4dc3f5..3af37e7b655a70cc34e538e7523ba16214c7f7ca 100644 (file)
@@ -39,8 +39,8 @@ isRangeZero(Iterator begin, Iterator end) {
 /// after every start of your process.  Calling srand() is enough. This
 /// method uses default rand(), which is usually a LCG pseudo-random
 /// number generator, so it is not suitable for security
-/// purposes. Please get a decent PRNG implementation, like Mersenne
-/// twister, if you are doing anything related with security.
+/// purposes. Please use cryptolink RNG if you are doing anything
+/// related with security.
 ///
 /// PRNG initialization is left out of this function on purpose. It may
 /// be initialized to specific value on purpose, e.g. to repeat exactly