Seed Dict and Set

This changes Dict and Set to have a compilation depedent seed.
The seed is not exposed to userland in anyway.
This gets a much more DOS resistant Dict and Set with no cost.
This commit is contained in:
Brendan Hansknecht 2023-05-25 09:39:52 -07:00
parent 8ecbd8c071
commit b4c359588e
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
11 changed files with 69 additions and 30 deletions

View file

@ -436,3 +436,12 @@ test "increfC, static data" {
increfRcPtrC(ptr_to_refcount, 2);
try std.testing.expectEqual(mock_rc, REFCOUNT_MAX_ISIZE);
}
// This returns a compilation dependent pseudo random seed for dictionaries.
// The seed is the address of this function.
// This avoids all roc Dicts using a known seed and being trivial to DOS.
// Still not as secure as true random, but a lot better.
// This value must not change between calls unless Dict is changed to store the seed on creation.
pub fn dictPseudoSeed() callconv(.C) u64 {
return @intCast(u64, @ptrToInt(dictPseudoSeed));
}