The QHashSeed
class is used to convey the QHash
seed. This is used internally by QHash
and provides three static member functions to allow users to obtain the hash and to reset it.
QHash
and the functions implement what is called as “salted hash”. The intent is that different applications and different instances of the same application will produce different hashing values for the same input, thus causing the ordering of elements in QHash
to be unpredictable by external observers. This improves the applications’ resilience against attacks that attempt to force hashing tables into degenerate mode.
Most applications will not need to deal directly with the hash seed, as QHash
will do so when needed. However, applications may wish to use this for their own purposes in the same way as QHash
does: as an application-global random value (but see QRandomGenerator
too). Note that the global hash seed may change during the application’s lifetime, if the resetRandomGlobalSeed()
function is called. Users of the global hash need to store the value they are using and not rely on getting it again.
This class also implements functionality to set the hash seed to a deterministic value, which the functions will take to mean that they should use a fixed hashing function on their data too. This functionality is only meant to be used in debugging applications. This behavior can also be controlled by setting the QT_HASH_SEED
environment variable to the value zero (any other value is ignored).
See also
QHash
QRandomGenerator
Constructs a new QHashSeed
object using data
as the seed.
Returns the current global QHash
seed. The value returned by this function will be zero if setDeterministicGlobalSeed()
has been called or if the QT_HASH_SEED
environment variable is set to zero.
Converts the returned hash seed into a size_t
.
Reseeds the Qt hashing seed to a new, random value. Calling this function is not necessary, but long-running applications may want to do so after a long period of time in which information about its hash may have been exposed to potential attackers.
If the environment variable QT_HASH_SEED
is set to zero, calling this function will result in a no-op.
Qt never calls this function during the execution of the application, but unless the QT_HASH_SEED
variable is set to 0, the hash seed returned by globalSeed()
will be a random value as if this function had been called.
Forces the Qt hash seed to a deterministic value (zero) and asks the functions to use a pre-determined hashing function. This mode is only useful for debugging and should not be used in production code.
Regular operation can be restored by calling resetRandomGlobalSeed()
.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.