From: Amos Jeffries Date: Sun, 8 Feb 2015 16:53:31 +0000 (-0800) Subject: Convert libntlm to C++11 random engine X-Git-Tag: merge-candidate-3-v1~109^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85b08f120e94733c06d021dcf1c380d70d0eceee;p=thirdparty%2Fsquid.git Convert libntlm to C++11 random engine --- diff --git a/lib/ntlmauth/ntlmauth.cc b/lib/ntlmauth/ntlmauth.cc index e134b56afd..52f1757133 100644 --- a/lib/ntlmauth/ntlmauth.cc +++ b/lib/ntlmauth/ntlmauth.cc @@ -12,6 +12,7 @@ #include "squid.h" #include +#include #if HAVE_STRINGS_H #include #endif @@ -178,21 +179,16 @@ ntlm_add_to_payload(const ntlmhdr *packet_hdr, /* ************************************************************************* */ /* - * Generates a challenge request nonce. The randomness of the 8 byte - * challenge strings can be guarenteed to be poor at best. + * Generates a challenge request nonce. */ void ntlm_make_nonce(char *nonce) { - static unsigned hash; - uint32_t r = static_cast(rand()); - r = (hash ^ r) + r; + static std::mt19937 mt(time(0)); + static std::uniform_int_distribution dist; - for (int i = 0; i < NTLM_NONCE_LEN; ++i) { - nonce[i] = static_cast(r & 0xFF); - r = (r >> 2) ^ r; - } - hash = r; + for (int i = 0; i < NTLM_NONCE_LEN; ++i) + nonce[i] = static_cast(dist(mt) & 0xFF); } /**