]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Convert libntlm to C++11 random engine
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 16:53:31 +0000 (08:53 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 8 Feb 2015 16:53:31 +0000 (08:53 -0800)
lib/ntlmauth/ntlmauth.cc

index e134b56afd21813297b1148acf1be399782e4817..52f1757133736399f1c1b90f0da38c42314d32d6 100644 (file)
@@ -12,6 +12,7 @@
 #include "squid.h"
 
 #include <cstring>
+#include <random>
 #if HAVE_STRINGS_H
 #include <strings.h>
 #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<uint32_t>(rand());
-    r = (hash ^ r) + r;
+    static std::mt19937 mt(time(0));
+    static std::uniform_int_distribution<uint8_t> dist;
 
-    for (int i = 0; i < NTLM_NONCE_LEN; ++i) {
-        nonce[i] = static_cast<char>(r & 0xFF);
-        r = (r >> 2) ^ r;
-    }
-    hash = r;
+    for (int i = 0; i < NTLM_NONCE_LEN; ++i)
+        nonce[i] = static_cast<char>(dist(mt) & 0xFF);
 }
 
 /**