Overview
Comment: | Add a per-hashtable seed.
This should make it impossible to retrieve of_hash_seed by inserting |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
590fa6ed790121e57f7b8fe067652a34 |
User & Date: | js on 2012-12-04 09:59:09 |
Other Links: | manifest | tags |
Context
2012-12-05
| ||
12:22 | OFLocking: Add property for lock name. check-in: 5918fe8ab2 user: js tags: trunk | |
2012-12-04
| ||
09:59 | Add a per-hashtable seed. check-in: 590fa6ed79 user: js tags: trunk | |
09:19 | Randomize hashes. check-in: f60e4012b7 user: js tags: trunk | |
Changes
Modified src/OFMapTable.h from [dcccbffbc5] to [5b6730706a].
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | */ @interface OFMapTable: OFObject <OFCopying, OFFastEnumeration> { of_map_table_functions_t keyFunctions, valueFunctions; struct of_map_table_bucket **buckets; uint32_t minCapacity, capacity, count; unsigned long mutations; } /*! * @brief Creates a new OFMapTable with the specified key and value functions. * * @param keyFunctions A structure of functions for handling keys * @param valueFunctions A structure of functions for handling values | > | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | */ @interface OFMapTable: OFObject <OFCopying, OFFastEnumeration> { of_map_table_functions_t keyFunctions, valueFunctions; struct of_map_table_bucket **buckets; uint32_t minCapacity, capacity, count; unsigned long mutations; uint32_t seed; } /*! * @brief Creates a new OFMapTable with the specified key and value functions. * * @param keyFunctions A structure of functions for handling keys * @param valueFunctions A structure of functions for handling values |
︙ | ︙ |
Modified src/OFMapTable.m from [c18a26ad1f] to [fac29d9273].
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <string.h> #import "OFMapTable.h" #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" | > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <stdlib.h> #include <string.h> #include <sys/time.h> #import "OFMapTable.h" #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" |
︙ | ︙ | |||
143 144 145 146 147 148 149 150 151 152 153 154 155 156 | minCapacity = capacity; buckets = [self allocMemoryWithSize: sizeof(*buckets) count: capacity]; memset(buckets, 0, capacity * sizeof(*buckets)); } @catch (id e) { [self release]; @throw e; } return self; } | > > > > > > > > > > | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | minCapacity = capacity; 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; } return self; } |
︙ | ︙ | |||
220 221 222 223 224 225 226 | @try { uint32_t i; for (i = 0; i < capacity; i++) if (buckets[i] != NULL && buckets[i] != &deleted) [copy OF_setValue: buckets[i]->value forKey: buckets[i]->key | | | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | @try { uint32_t i; 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 ^ seed]; } @catch (id e) { [copy release]; @throw e; } copy->minCapacity = MIN_CAPACITY; |
︙ | ︙ | |||
245 246 247 248 249 250 251 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; | | | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; hash = keyFunctions.hash(key) ^ seed; last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; if (keyFunctions.equal(buckets[i]->key, key)) |
︙ | ︙ | |||
345 346 347 348 349 350 351 352 353 354 355 356 357 358 | if (key == NULL || value == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; if (keyFunctions.equal(buckets[i]->key, key)) break; | > | 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | if (key == NULL || value == NULL) @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; if (keyFunctions.equal(buckets[i]->key, key)) break; |
︙ | ︙ | |||
439 440 441 442 443 444 445 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; | | | 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | uint32_t i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; hash = keyFunctions.hash(key) ^ seed; last = capacity; for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { if (buckets[i] == &deleted) continue; if (keyFunctions.equal(buckets[i]->key, key)) { |
︙ | ︙ |