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

Added basic support for CH32V003. #153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

CharlesScoville
Copy link

Added basic support for CH32V003. Entropy is observed from reading LSb of ADC pointed to "Vrefint" channel. (Physical entropy source is thermal noise of charge carriers at sample capacitor.) To make use of these changes, of course, one needs a proper CH32V003 project with the corresponding application support. Particularly, one needs to define “CH32V0XX” at the global level as well as implement the RNG_GetCondensedEntropy() function call.

…b of ADC pointed to "Vrefint" channel. (Physical entropy source is thermal noise of charge carriers at sample capacitor.) To make use of these changes, of course, one needs a proper CH32V003 project with the corresponding application support. Particularly, one needs to define “CH32V0XX” at the global level as well as implement the RNG_GetCondensedEntropy() function call.
@CharlesScoville
Copy link
Author

CharlesScoville commented May 8, 2024

Currently working on minimal PoC project for official CH32V003 IDE, "MounRiver Studio - Community." Should be ready by the end of this weekend. (Will make what I have now available upon request, however.)

@CharlesScoville
Copy link
Author

CharlesScoville commented May 8, 2024

Screenshot of public key signature example number one after running to completion once.

libhydrogen CH32V003

@CharlesScoville
Copy link
Author

... Should be ready by the end of this weekend.

Just kidding! (... Apparently)

https://github.com/CharlesScoville/CH32V003F4P6-libhydrogen-PoC/tree/main

@jedisct1
Copy link
Owner

jedisct1 commented May 8, 2024

Thanks!

But if RNG_GetCondensedEntropy() needs to be defined by the application, these changes don't look very useful.

Couldn't an implemented of RNG_GetCondensedEntropy() be included?

@CharlesScoville
Copy link
Author

Couldn't an implemented of RNG_GetCondensedEntropy() be included?

...Perhaps... I'd have to really think about exactly how without it becoming a big frail mess.

As submitted, it's got the best possible decoupling between libhydrogen and any CH32V003 project code, which was the entire idea behind the minimal changes that you are seeing in this PR.

The next smallest step isn't very small I fear... it would be to try and pull the LSb accumulator and Von Neumann extractor in. Which, to do this, would likely require doing all the ADC care and feeding from within libhydrogen's part specific header. That's where the nightmare is going to be.

I guess we could also go really deep and add a template / PoC project directly to libhydrogen? This way, moving the Von Neumann extractor code out of the CH32V003 project and into libhydrogen has potential to be less frail, though it would still be very coupled.

No matter what, the end user is going to have to observe that libhydrogen is using it's resources, and so take care not to mangle them. Re-configuring the ADC to probe some voltage, for example, would probably almost instantly break the system.

... hummmmm ...

Anyway, like I said, I'd have to think about precisely how to do it. I'm open to suggestions though! PoC code is linked in post 4.

…man extractor code has been pulled in from CH32V003 project. A simple check was added to verify that the ADC unit is actually on as well.
@CharlesScoville
Copy link
Author

OK @jedisct1. Take a look at the new changes and tell me what you think. Basically, I followed paragraph two from my last post above.

Other than fighting with the IDE, it wasn't actually that hard. The trick was to separate at the internal voltage reference buffer, rather than having all the extractor and accumulator code in with the ADC. It also turned out to be better system design as a whole since now the ADC code is strictly doing ADC things, and simply handing the data off to the entropy shim via an async buffer. The entropy collecting portion of libhydrogen will block while polling for entropy now, but it doesn't strictly have to. It could easily be changed to doing something useful while waiting if so inclined.

That's the good news...

The bad news is that I have discovered egregious bias in the resulting collected entropy under very certain power conditions; a situation I was really hoping we avoided by using the internal voltage reference rather than an externally accessible ADC input. Good bypass capacitors right at the power pins, plus cranking the ebits value can work around the problem somewhat. An extra layer could also be added by augmenting the entropy collection process with some XOR mixing/whitening.

An interesting alternative that I'm considering is combining the top problem of blocking and waiting around with the bottom problem of dilute entropy by running hydro_hash_update() each time the ADC poll misses an ADC sample. This would be a pretty slick trick if it all works out like I think it does. Basically, hydro_hash_update() would just need to be invoked in a way that just "stirred the pot," so to speak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants