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 fixes a bug when instantiating repeatedly a DRBG, below is an example on how to trigger the bug with the current master branch, using the test entropy source flag at compile time.
The bug is a combination of a logic bug in the DRBG interface, and of an improper uninitialization of the entropy pool in the test entropy source.
The test entropy source is improperly uninitialized with clear_entropy(), with the current position of the cursor pool not being reset. This eventually leads to the clear_entropy() function failing its sanity check and returning an error code.
The error code triggers a goto instruction in _drbg_instantiate(), as is the common pattern throughout the codebase, but in this case, the goto instruction happens after the label. This causes an infinite loop. Removing the goto instruction avoids the infinite loop, and does not prevent further entropy clearing.
Additionally, I made it so the drbg_uninstantiate() function returns an error code if needed, while still enforcing proper uninitialization (prior to that, it always returned DRBG_OK).
The PR may need to be formated to your own code style. I am not used to PRs from a fork, so I am eager to receive any feedback.