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

sys/auto_init: cpuid as seed for random_init #5321

Closed

Conversation

cgundogan
Copy link
Member

@cgundogan cgundogan commented Apr 14, 2016

Choose a sane seed number instead of defaulting to 0. This PR utilizes the cpuid, if present.

Rationale: Trickle timers rely on random offsets to generate increasing intervals. This way, if a network protocol relies on trickle timers, packets of different nodes will not be sent at the same time, but with a little offset applied.

Currently, in case of RPL, many nodes send out DIO messages at the same time, because the "randomness" is the same for all nodes (same seed, and booted at same time).

@cgundogan cgundogan added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation ugly labels Apr 14, 2016
@cgundogan cgundogan added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Apr 14, 2016
@cgundogan
Copy link
Member Author

I am aware of #4294, #4989, #5150 and #5153. My solution here is more or less a temporary "quick-fix" (given that this discussion is several years old now), hence the ugly label.

@cgundogan cgundogan added this to the Release 2016.07 milestone Apr 15, 2016
@OlegHahm
Copy link
Member

IMO it makes sense to have initialize the PRNG with something that is at least different on each board.

@kaspar030
Copy link
Contributor

Well, if a CPUID is available, this is the way to go. Simple, and for crypto safety we'd need sth else anyways.

thoughts:

  • AFAIR random_init() is available for all prngs, so should we initialize them all?
  • why are you adding up the cpuid? wouldn't be using the first four bytes directly, then XOR'ing the rest, result in slightly more distributed numbers?
  • I'd prefer to just call random_auto_init() in auto_init.c and move the code to sys/random/auto_init_random.c, or whatever location seems suitable.

@jnohlgard
Copy link
Member

@kaspar030 why would xor be more random than add? Addition is only an xor with carry.

@cgundogan I would suggest that you concatenate some bytes or integrate some bit shifts to get to the full width of the seed value, otherwise the upper 20-something bits will always be zero for a 32 bit seed value. Another option would be to use one of the functions provided by sys/hashes and sys/checksum.

@miri64
Copy link
Member

miri64 commented Apr 17, 2016

@cgundogan how about using #5153 instead to get a random value and add CPUID as a fallback random value?

@kaspar030
Copy link
Contributor

@cgundogan Could you factor out the code from auto_init somewhere into sys/prng, so auto_init.c gets less cluttered? Also maybe call it for every PRNG, not just tinymt.

@kYc0o
Copy link
Contributor

kYc0o commented Jul 22, 2016

PRs about RNG should be postponed, since there are several addressing similar issues.

@kYc0o kYc0o modified the milestones: Release 2016.10, Release 2016.07 Jul 22, 2016
@miri64
Copy link
Member

miri64 commented Oct 31, 2016

Postponed due to feature freeze

@miri64 miri64 modified the milestones: Release 2017.01, Release 2016.10 Oct 31, 2016
@OlegHahm
Copy link
Member

@cgundogan, what's up?

@PeterKietzmann PeterKietzmann modified the milestones: Release 2017.01, Release 2017.04 Jan 26, 2017
@PeterKietzmann
Copy link
Member

CPUID is old-school, luid is the thing (see #7547 for example)! @cgundogan thanks for your initial input on this!

@cgundogan cgundogan deleted the pr/auto_init/random_seed_cpuid branch October 26, 2017 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants