Closed bjoernQ closed 4 months ago
Will take a look on Monday, thanks for a ping!
Here we need the function I created while working on a previous problem with TRNG, but it wasn't needed. It "undos" the TRNG changes to registers (which I called revert_trng
)
revert_trng
will make ADC work with TRNG initialized, BUT... The problem is TRNG
constructor changes ADC registers and stuff and calling the ADC constructor after it will configure things in a way to make ADC work (but RNG is not TRNG anymore)
Having TRNG
is nice, but working ADC
is way better, that is why we deprecated TRNG
functionality and corresponding CryptoRng
trait FOR NOW
Possible solutions:
1) have two separate constructors for RNG (normal) and TRNG (will also take ADC peripheral so user won't be able to use them together)
2) Just provide a revert_trng
for user, which is not a good solution from the point of "user-friendliness" (and many other points I guess)
3) somehow ensure that revert_trng was called where and when needed after TRNG initialization (is it possible?)
First one sounds a bit "hacky", third one sounds impossible/difficult.
IDF
seems to be using the second approach, which means that random_disable
function is being provided to user "on his own risk" : https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html
I like the IDF way in this case: We'll make "RNG" be "TRNG" by default, then provide function (revert_trng
) to revert the "True" part and make it be just RNG
again. However, it's not the most user-friendly approach, I'll think a bit more about other options.
On the other hand, having an explicit interface AND constructor for the TRNG
is better then giving the "unsafe sword" to the user.
Feel free to post your thoughts here
I don't think the first option is hacky - it's actually enabling Rng to operate in two different modes. Users could use it to seed a software rng from true random numbers and then drop it to use ADC if they really need to use it.
IMHO actually the cleanest option
Change the ADC example to look like this
The ADC reading will be 0, then.
cc @playfulFence