1 #ifndef Py_HASH_H 2 #define Py_HASH_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 7 /* Cutoff for small string DJBX33A optimization in range [1, cutoff). 8 * 9 * About 50% of the strings in a typical Python application are smaller than 10 * 6 to 7 chars. However DJBX33A is vulnerable to hash collision attacks. 11 * NEVER use DJBX33A for long strings! 12 * 13 * A Py_HASH_CUTOFF of 0 disables small string optimization. 32 bit platforms 14 * should use a smaller cutoff because it is easier to create colliding 15 * strings. A cutoff of 7 on 64bit platforms and 5 on 32bit platforms should 16 * provide a decent safety margin. 17 */ 18 #ifndef Py_HASH_CUTOFF 19 # define Py_HASH_CUTOFF 0 20 #elif (Py_HASH_CUTOFF > 7 || Py_HASH_CUTOFF < 0) 21 # error Py_HASH_CUTOFF must in range 0...7. 22 #endif /* Py_HASH_CUTOFF */ 23 24 25 /* Hash algorithm selection 26 * 27 * The values for Py_HASH_* are hard-coded in the 28 * configure script. 29 * 30 * - FNV and SIPHASH* are available on all platforms and architectures. 31 * - With EXTERNAL embedders can provide an alternative implementation with:: 32 * 33 * PyHash_FuncDef PyHash_Func = {...}; 34 * 35 * XXX: Figure out __declspec() for extern PyHash_FuncDef. 36 */ 37 #define Py_HASH_EXTERNAL 0 38 #define Py_HASH_SIPHASH24 1 39 #define Py_HASH_FNV 2 40 #define Py_HASH_SIPHASH13 3 41 42 #ifndef Py_HASH_ALGORITHM 43 # ifndef HAVE_ALIGNED_REQUIRED 44 # define Py_HASH_ALGORITHM Py_HASH_SIPHASH13 45 # else 46 # define Py_HASH_ALGORITHM Py_HASH_FNV 47 # endif /* uint64_t && uint32_t && aligned */ 48 #endif /* Py_HASH_ALGORITHM */ 49 50 #ifndef Py_LIMITED_API 51 # define Py_CPYTHON_HASH_H 52 # include "cpython/pyhash.h" 53 # undef Py_CPYTHON_HASH_H 54 #endif 55 56 #ifdef __cplusplus 57 } 58 #endif 59 #endif // !Py_HASH_H 60