Commit 609ddc69 authored by Francis Dupont's avatar Francis Dupont
Browse files

[29-cryptolink-random-generator] Updated random users

parent 9e742d30
......@@ -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
......
// 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 {
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment