diff --git a/Builds/VisualStudio2012/Beast.props b/Builds/VisualStudio2012/Beast.props
index 4e9ca3e39..1d61359a3 100644
--- a/Builds/VisualStudio2012/Beast.props
+++ b/Builds/VisualStudio2012/Beast.props
@@ -7,6 +7,8 @@
Level4
_CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions)
+ true
+ false
diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj
index 4d97ef0b3..5a7a76e92 100644
--- a/Builds/VisualStudio2012/beast.vcxproj
+++ b/Builds/VisualStudio2012/beast.vcxproj
@@ -93,7 +93,6 @@
-
@@ -156,6 +155,7 @@
+
@@ -302,12 +302,6 @@
true
true
-
- true
- true
- true
- true
-
true
true
@@ -519,6 +513,12 @@
true
true
+
+ true
+ true
+ true
+ true
+
true
true
diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters
index b649d0e21..afed64c51 100644
--- a/Builds/VisualStudio2012/beast.vcxproj.filters
+++ b/Builds/VisualStudio2012/beast.vcxproj.filters
@@ -503,9 +503,6 @@
beast_basics\math
-
- beast_basics\math
-
beast_basics\memory
@@ -734,6 +731,9 @@
beast_sqdb\detail
+
+ beast_core\maths
+
@@ -991,9 +991,6 @@
beast_basics\events
-
- beast_basics\math
-
beast_basics\memory
@@ -1135,6 +1132,9 @@
beast_sqdb\source
+
+ beast_core\maths
+
diff --git a/TODO.txt b/TODO.txt
index 3849b7bc6..89513ae9a 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -2,6 +2,8 @@
BEAST TODO
--------------------------------------------------------------------------------
+- Implement HardenedHashFunctions
+
- Set sqlite thread safety model to '2' in beast_sqlite
- Document and rename all the sqdb files and classes
diff --git a/modules/beast_basics/beast_basics.cpp b/modules/beast_basics/beast_basics.cpp
index 235c8a004..aa1a8f8b5 100644
--- a/modules/beast_basics/beast_basics.cpp
+++ b/modules/beast_basics/beast_basics.cpp
@@ -45,8 +45,6 @@ namespace beast
#include "events/beast_DeadlineTimer.cpp"
#include "events/beast_OncePerSecond.cpp"
-#include "math/beast_MurmurHash.cpp"
-
#include "threads/beast_InterruptibleThread.cpp"
#include "threads/beast_Semaphore.cpp"
#include "memory/beast_FifoFreeStoreWithTLS.cpp"
diff --git a/modules/beast_basics/beast_basics.h b/modules/beast_basics/beast_basics.h
index 6ce25f9bc..78f59c2f6 100644
--- a/modules/beast_basics/beast_basics.h
+++ b/modules/beast_basics/beast_basics.h
@@ -250,7 +250,6 @@ namespace beast
#include "events/beast_DeadlineTimer.h"
#include "events/beast_OncePerSecond.h"
#include "math/beast_Math.h"
-#include "math/beast_MurmurHash.h"
#include "memory/beast_AllocatedBy.h"
#include "memory/beast_PagedFreeStore.h"
#include "memory/beast_GlobalPagedFreeStore.h"
diff --git a/modules/beast_core/beast_core.cpp b/modules/beast_core/beast_core.cpp
index f2387873f..ba3982a37 100644
--- a/modules/beast_core/beast_core.cpp
+++ b/modules/beast_core/beast_core.cpp
@@ -166,6 +166,7 @@ namespace beast
#include "maths/beast_BigInteger.cpp"
#include "maths/beast_Expression.cpp"
+#include "maths/beast_MurmurHash.cpp"
#include "maths/beast_Random.cpp"
#include "memory/beast_MemoryBlock.cpp"
diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h
index c19c149f2..62be31d08 100644
--- a/modules/beast_core/beast_core.h
+++ b/modules/beast_core/beast_core.h
@@ -262,6 +262,7 @@ namespace beast
#include "maths/beast_Expression.h"
#include "maths/beast_Interval.h"
#include "maths/beast_MathsFunctions.h"
+#include "maths/beast_MurmurHash.h"
#include "maths/beast_Random.h"
#include "maths/beast_Range.h"
#include "memory/beast_ByteOrder.h"
diff --git a/modules/beast_basics/math/beast_MurmurHash.cpp b/modules/beast_core/maths/beast_MurmurHash.cpp
similarity index 100%
rename from modules/beast_basics/math/beast_MurmurHash.cpp
rename to modules/beast_core/maths/beast_MurmurHash.cpp
diff --git a/modules/beast_basics/math/beast_MurmurHash.h b/modules/beast_core/maths/beast_MurmurHash.h
similarity index 100%
rename from modules/beast_basics/math/beast_MurmurHash.h
rename to modules/beast_core/maths/beast_MurmurHash.h
diff --git a/modules/beast_crypto/math/beast_UnsignedInteger.h b/modules/beast_crypto/math/beast_UnsignedInteger.h
index fc0fa167c..f8b5204a2 100644
--- a/modules/beast_crypto/math/beast_UnsignedInteger.h
+++ b/modules/beast_crypto/math/beast_UnsignedInteger.h
@@ -43,6 +43,42 @@ public:
typedef unsigned char* iterator;
typedef unsigned char const* const_iterator;
+ /** Hardened hash function for use with HashMap.
+
+ The seed is used to make the hash unpredictable. This prevents
+ attackers from exploiting crafted inputs to produce degenerate
+ containers.
+
+ @see HashMap
+ */
+ class HashFunction
+ {
+ public:
+ /** Construct a hash function.
+
+ If a seed is specified it will be used, else a random seed
+ will be generated from the system.
+
+ @param seedToUse An optional seed to use.
+ */
+ explicit HashFunction (int seedToUse = Random::getSystemRandom ().nextInt ())
+ : m_seed (seedToUse)
+ {
+ }
+
+ /** Generates a simple hash from an UnsignedInteger. */
+ int generateHash (UnsignedInteger const& key, const int upperLimit) const noexcept
+ {
+ uint32 hashCode;
+ Murmur::Hash (key.cbegin (), key.sizeInBytes, m_seed, &hashCode);
+ // Shouldn't produce negative numbers since upperLimit is an int?
+ return static_cast (hashCode % upperLimit);
+ }
+
+ private:
+ int m_seed;
+ };
+
/** Construct the object.
The values are uninitialized.