@@ -14,11 +14,14 @@ * file. */ #include "config.h" +#include #include + +#include #import "OFMapTable.h" #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" @@ -145,10 +148,20 @@ buckets = [self allocMemoryWithSize: sizeof(*buckets) count: capacity]; memset(buckets, 0, capacity * sizeof(*buckets)); + + if (of_hash_seed != 0) { +#if defined(OF_HAVE_ARC4RANDOM) + seed = arc4random(); +#elif defined(OF_HAVE_RANDOM) + seed = random(); +#else + seed = rand(); +#endif + } } @catch (id e) { [self release]; @throw e; } @@ -222,11 +235,11 @@ for (i = 0; i < capacity; i++) if (buckets[i] != NULL && buckets[i] != &deleted) [copy OF_setValue: buckets[i]->value forKey: buckets[i]->key - hash: buckets[i]->hash]; + hash: buckets[i]->hash ^ seed]; } @catch (id e) { [copy release]; @throw e; } @@ -247,11 +260,11 @@ if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - hash = keyFunctions.hash(key); + hash = keyFunctions.hash(key) ^ seed; last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; @@ -347,10 +360,11 @@ @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; last = capacity; + hash ^= seed; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; @@ -441,11 +455,11 @@ if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - hash = keyFunctions.hash(key); + hash = keyFunctions.hash(key) ^ seed; last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue;