2013-11-20 06:46:18 -04:00
|
|
|
#ifndef Py_HASH_H
|
|
|
|
#define Py_HASH_H
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef Py_LIMITED_API
|
|
|
|
/* hash function definition */
|
|
|
|
typedef struct {
|
|
|
|
Py_hash_t (*const hash)(const void *, Py_ssize_t);
|
|
|
|
const char *name;
|
|
|
|
const int hash_bits;
|
|
|
|
const int seed_bits;
|
|
|
|
} PyHash_FuncDef;
|
|
|
|
|
|
|
|
PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2023-07-22 10:49:37 -03:00
|
|
|
/* Cutoff for small string DJBX33A optimization in range [1, cutoff).
|
2013-11-20 06:46:18 -04:00
|
|
|
*
|
|
|
|
* About 50% of the strings in a typical Python application are smaller than
|
|
|
|
* 6 to 7 chars. However DJBX33A is vulnerable to hash collision attacks.
|
|
|
|
* NEVER use DJBX33A for long strings!
|
|
|
|
*
|
|
|
|
* A Py_HASH_CUTOFF of 0 disables small string optimization. 32 bit platforms
|
|
|
|
* should use a smaller cutoff because it is easier to create colliding
|
|
|
|
* strings. A cutoff of 7 on 64bit platforms and 5 on 32bit platforms should
|
|
|
|
* provide a decent safety margin.
|
|
|
|
*/
|
|
|
|
#ifndef Py_HASH_CUTOFF
|
|
|
|
# define Py_HASH_CUTOFF 0
|
|
|
|
#elif (Py_HASH_CUTOFF > 7 || Py_HASH_CUTOFF < 0)
|
|
|
|
# error Py_HASH_CUTOFF must in range 0...7.
|
|
|
|
#endif /* Py_HASH_CUTOFF */
|
|
|
|
|
|
|
|
|
2023-07-22 10:49:37 -03:00
|
|
|
/* Hash algorithm selection
|
2013-11-20 06:46:18 -04:00
|
|
|
*
|
2021-10-10 05:29:46 -03:00
|
|
|
* The values for Py_HASH_* are hard-coded in the
|
2013-11-20 06:46:18 -04:00
|
|
|
* configure script.
|
|
|
|
*
|
2021-10-10 05:29:46 -03:00
|
|
|
* - FNV and SIPHASH* are available on all platforms and architectures.
|
2013-11-20 06:46:18 -04:00
|
|
|
* - With EXTERNAL embedders can provide an alternative implementation with::
|
|
|
|
*
|
|
|
|
* PyHash_FuncDef PyHash_Func = {...};
|
|
|
|
*
|
|
|
|
* XXX: Figure out __declspec() for extern PyHash_FuncDef.
|
|
|
|
*/
|
|
|
|
#define Py_HASH_EXTERNAL 0
|
|
|
|
#define Py_HASH_SIPHASH24 1
|
|
|
|
#define Py_HASH_FNV 2
|
2021-10-10 05:29:46 -03:00
|
|
|
#define Py_HASH_SIPHASH13 3
|
2013-11-20 06:46:18 -04:00
|
|
|
|
|
|
|
#ifndef Py_HASH_ALGORITHM
|
2016-09-06 17:24:00 -03:00
|
|
|
# ifndef HAVE_ALIGNED_REQUIRED
|
2021-10-10 05:29:46 -03:00
|
|
|
# define Py_HASH_ALGORITHM Py_HASH_SIPHASH13
|
2013-11-20 06:46:18 -04:00
|
|
|
# else
|
|
|
|
# define Py_HASH_ALGORITHM Py_HASH_FNV
|
|
|
|
# endif /* uint64_t && uint32_t && aligned */
|
|
|
|
#endif /* Py_HASH_ALGORITHM */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2023-07-22 10:49:37 -03:00
|
|
|
#endif // !Py_HASH_H
|