Skip to content

Add random to ESP32-S2, fix it on STM32 #3324

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

Merged
merged 3 commits into from
Aug 27, 2020
Merged

Add random to ESP32-S2, fix it on STM32 #3324

merged 3 commits into from
Aug 27, 2020

Conversation

hierophect
Copy link
Collaborator

This PR adds the TRNG to ESP32-S2, based off the cxd56 implementation, which has a similar system call. This will enable use of os.random().

It also fixes a serious but overlooked issue with the STM32 os.random call where it would not supply values past the first 8 bit number. (Yikes!)

@hierophect hierophect added stm espressif applies to multiple Espressif chips labels Aug 25, 2020
@hierophect hierophect requested a review from tannewt August 25, 2020 18:05
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple questions.

@hierophect hierophect requested a review from tannewt August 25, 2020 19:42
@anecdata
Copy link
Member

I don't know what the right answer is here, but pseudo-random is fine for many purposes other than cryptographic. Users can also seed with their own entropy. It would be a shame to disable random completely when wi-fi is not up. Maybe an alert in the docs would suffice.

@hierophect
Copy link
Collaborator Author

hierophect commented Aug 25, 2020

I don't know what the right answer is here, but pseudo-random is fine for many purposes other than cryptographic. Users can also seed with their own entropy. It would be a shame to disable random completely when wi-fi is not up. Maybe an alert in the docs would suffice.

Circuitpython's built in random module is already pseudorandom, and should activate automatically when os.urandom is not available. But os.urandom itself is supposed to be TRNG (True Random Number Generation), and is represented as such in the documentation - I don't think we should provide pseudorandom numbers while advertising them as TRNG.

@hierophect
Copy link
Collaborator Author

@anecdata are you using the random module? You should still be able to access pseudorandom numbers without this specific OS feature. I may have mistaken CIRCUITPY_RANDOM for standing in for the TRNG when it was actually a flag for both. If that's the case, once it's re-enabled you'll be able to get pseudorandom values even when TRNG is turned off.

@anecdata
Copy link
Member

Sorry, yes, I conflated the two since the random module went away from esp32-s2 in a recent build, and I don't think os.urandom() was present either. So I think it will be all good. Thanks.

@hierophect
Copy link
Collaborator Author

Sorry, yes, I conflated the two since the random module went away from esp32-s2 in a recent build, and I don't think os.urandom() was present either. So I think it will be all good. Thanks.

That was probably my fault, I removed CIRCUITPY_RANDOM because I thought it was the flag for the TRNG only. It must have also disabled the pseudorandom numbers, which I didn't intend.

@dhalbert
Copy link
Collaborator

Merge conflicts here. Is this otherwise good to go? @tannewt did you have anything further?

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's all set.

@hierophect
Copy link
Collaborator Author

Doesn't look like I can merge until @tannewt signs off.

@dhalbert dhalbert merged commit 350e88d into adafruit:main Aug 27, 2020
@hierophect
Copy link
Collaborator Author

nevermind

@hierophect hierophect deleted the esp32-random branch August 27, 2020 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
espressif applies to multiple Espressif chips stm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants