Implement pseudorandom number generator#14
Open
JesseDeMeulemeester wants to merge 5 commits intoproteus-core:mainfrom
Open
Implement pseudorandom number generator#14JesseDeMeulemeester wants to merge 5 commits intoproteus-core:mainfrom
JesseDeMeulemeester wants to merge 5 commits intoproteus-core:mainfrom
Conversation
Co-authored-by: Quinten Norga <43999019+qnorga1@users.noreply.github.com>
* Replaced AES core with Bivium core for more efficient random number generation. This reduces area usage and improves performance to 1 random number per clock cycle. * Refactored the connection between the RngCore and the RngFifos to remove unnecessary buffers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a pseudorandom number generator. It provides an
RngServicethat can be called in any component that requires random numbers. Each component holds its own RNG buffer to buffer outputs from the generator. The RNG component will fill these buffers in Round Robin fashion. The RNG component, in turn, also has an internal buffer to buffer values between the AES core and the individual RNG buffers.We currently use AES in OFB mode to generate a continuous random stream, where a single AES encryption produces four 32-bit (or two 64-bit) random values.
For this, we rely on a modified SpinalCrypto library:
I wasn't sure how to best include the modified AES core here. Currently I forked SpinalCrypto here and pull this forked repo.
Initialization
The initial seed for the AES core (i.e., the IV) can be set at runtime through CSRs. By default, the RNG component will not generate any random numbers until the seed has been updated. The RNG component can also be disabled through a control CSR. If the disable bit is set, timings will remain the same, but the RNG component will only return zero.
Usage
The usage is very similar to CSRs:
You add the RNG plugin (note that this plugin has to be added after any other plugin that requires it):
You register a buffer with the RngService:
And you can then get random numbers from this buffer:
Issues
There are still a few minor issues (most are marked with TODOs), most notably: