Skip to content
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

Make sure that calls to Fingerprint::combine do not undermine collision safety #44337

Closed
arielb1 opened this issue Sep 5, 2017 · 3 comments
Closed
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Sep 5, 2017

Fingerprint::combine is not a cryptographic hash, so when we use it we might lose the "cryptographic" guarantee of collision safety. Potentially even worse, Fingerprint::combine is associative: Fingerprint::combine(Fingerprint::combine(a, b), c) = Fingerprint::combine(a, Fingerprint::combine(b, c)), and that might cause "algebraic" collisions in some cases.

For example:

def_path_hash_0.0.combine(def_path_hash_1.0)

fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
let mut fingerprint = Fingerprint::zero();
for &def_id in self.0.iter() {
let def_path_hash = tcx.def_path_hash(def_id);
fingerprint = fingerprint.combine(def_path_hash.0);
}
fingerprint
}

And another case added by my PR:
https://github.com/arielb1/rust/blob/d14ed92f6b5aa23fd06f8affe4554f2c370bc79d/src/librustc/dep_graph/dep_node.rs#L647-L657

I believe the only requirement for DepNode is that the map from QueryKey -> (DepKind, Fingerprint) is injective. It might be a good idea to have a good sense of the requirements there to avoid accidental collisions.

@michaelwoerister
Copy link
Member

Just to clarify, we do not require these Fingerprint values to be cryptographically secure in any way. We just need them to be (roughly) as unlikely to collide as random 128 bit numbers would be.

@arielb1
Copy link
Contributor Author

arielb1 commented Sep 7, 2017

@michaelwoerister

But cryptographic collision-resistance is a nice property, because it is fairly robust and implies we don't have to worry about odd interactions.

@TimNN TimNN added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 17, 2017
@Enselic
Copy link
Member

Enselic commented Sep 15, 2023

Triage: Closing as won't fix since I don't see how keeping this open can lead anywhere. Making a case for cryptographic collision-resistance of these hashes is probably better done in an RFC or perhaps even better in Zulip.

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants