Skip to content

[runtime] Add better control over the random hashing seed #15207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2018

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Mar 13, 2018

This changes the runtime to look for the SWIFT_DETERMINISTIC_HASHING environment variable, and, if it is set to 1 during process startup, arrange to disable randomized hashing in the stdlib.

This mechanism replaces the old mutable _Hasher._secretKey property with a read-only _Hasher._seed var, and adds a new _Hasher._isDeterministic boolean property indicating whether Set and Dictionary should ensure repeatable ordering.

The seed generator is updated to make better use of the system-provided RNGs.

Swift's lit config is updated to run executable tests with deterministic hashing enabled by default, on all platforms.

- Hash seed randomization can now be disabled by defining the SWIFT_DETERMINISTIC_HASHING environment value with a value of "1".
- The random hash seed is now generated using arc4random, where available. On platforms where it isn't, don't construct std::random_device twice.
- _Hasher._secretKey is renamed _Hashing._seed, with no setter.
- _Hasher._isDeterministic is a new property exposing whether we're running with non-random hashes. (Set/Dictionary will need this information to decide if they're allowed to use per-instance seeding.)
The hash seed is not settable at runtime anymore; update lit config to set the SWIFT_DETERMINISTIC_HASHING environment variable instead.
@lorentey lorentey requested a review from milseman March 13, 2018 16:30
@lorentey
Copy link
Member Author

@swift-ci please test

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// FIXME(hasher): Remove
@_inlineable // FIXME(sil-serialize-all)
@_versioned
@_transparent
internal static func getExecutionSeed() -> UInt64 {
// FIXME: This needs to be a per-execution seed. This is just a placeholder
// implementation.
let seed: UInt64 = 0xff51afd7ed558ccd
return _HashingDetail.fixedSeedOverride == 0 ? seed : fixedSeedOverride
return 0xff51afd7ed558ccd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return 0xff51afd7ed558ccd // Chosen by fair dice role. Guaranteed to be random

Copy link
Contributor

@moiseev moiseev Mar 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0xffffffffffffffff sided die.

@lorentey lorentey merged commit b010833 into swiftlang:master Mar 13, 2018
@lorentey lorentey deleted the seedless-hashes branch March 16, 2018 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants