Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The performance arguments given in #48 and #102 are perfectly valid reasons to not use
crypto/rand
for every message ID but that doesn't mean you have to use the default seed (which is literally just1
) when usingmath/rand
.This patch simply reads out a random
int64
usingcrypto/rand
on package initialization and uses it to seed the defaultmath/rand
source. While there are obviously other more viable attacks this should make message ID spoofing/prediction much harder when using the defaultId
.This also changes
id()
to just use a randint32
and bound it to the max size of auint16
instead of usingtime.Now
since it's a relatively easy to guess variable so it shouldn't actually provide that many useful bits (since someone analyzing the messages will generally know the period the messages were generated in).