-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add SoftDevice rng version to MicroBitDevice::seedRandom()
.
#448
base: master
Are you sure you want to change the base?
Conversation
@martinwork could you review this PR? This version is slightly slower, but it might be safer, would you agree? |
MicroBitDevice::seedRandom()
.
Otherwise, calling this function when BLE is running results in 0xBBC5EED always being used as the seed.
e39ab00
to
70fa832
Compare
Build diffBase commit: bd446c49f5501584e2cef3b5f53ebb826928e47b
|
Elsewhere, SOFTDEVICE_PRESENT and ble_running() have been nested the other way. Would another BLE implementation also block direct access to NRF_RNG, etc? codal-microbit-v2/source/MicroBitFlash.cpp Line 118 in e88ca61
Does using sd_rand_application_bytes_available_get make it safer? If sd_rand_application_bytes_available_get will eventually say 4 bytes are available, then a simple loop on sd_rand_application_vector_get should eventually succeed. The only error sd_rand_application_vector_get returns is not enough bytes. In that case it has not written to the buffer. Maybe there's a faint to non-existent possibility that an interrupt could steal a byte between sd_rand_application_bytes_available_get and sd_rand_application_vector_get? I experimented some more, for interest... sd_rand_application_pool_capacity_get returns 64. Immediately after uBit.init() there are 1-3 bytes available. It takes >6500us for bytes_available to be 64. After that, claiming 4 bytes repeatedly takes <20us for the first 17 requests, then each request takes 300-500us. With a loop like this, I haven't seen count go over 100.
Assuming any call like sd_rand_application_vector_get will eventually succeed makes me nervous, but I suppose it's just like this.
|
Yeah, we have discussed in the past exploring other BLE stacks, definitely not in the short term, but it is possible in the future that
Right, not safer than checking the return state of
Do you mean a loop trying to get one byte at a time instead of trying to get 4 bytes out in one go?
Ah, or do you mean to try in a loop until success? while (sd_rand_application_vector_get((uint8_t*)&random_value, sizeof(random_value)) != NRF_SUCCESS);
Yes, but I think in those edge cases is probably fine for the default seed to be returned. |
I think the original idea was not to burden a no-BLE build with checking ble_running, and that maybe only softdevice precludes using the direct calls. On adding a non-softdevice BLE: if nested the old way it might just work; this way, it would initially revert to doing nothing, and need to be edited even if using NRF_RNG is OK.
Yes, instead of a loop trying sd_rand_application_bytes_available_get. It's a bit hard to see in |
Otherwise, calling this function when BLE is running results in 0xBBC5EED as always being used as the seed.