-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Support set *_drbg reseed interval before seed #3393
Conversation
Hi @gacquroff . Thanks for your contribution. It looks like this patch breaks our doxygen generation:
Could you please fix this before we review? Regards, Dan. |
For some reason (network glitch?) the Travis log wasn't linked automatically. |
Travis CI build passed, but I'm not sure about the PR-3393-head TLS Testing failure. Should I be able to see the log from that? |
Hi @gacquroff, the PR-3393-head TLS Testing failure was just a CI glitch (a repo cloning failed) thus from the CI point of view it is all good now. Thanks for reverting the comment changes. |
Hi @ronald-cron-arm, no problem. Let me know if I need to fix any other CI bugs. |
FreeBSD failed again in a re-run, but it isn't the fault of this PR. We'll need a clean run on FreeBSD before merging, but I don't expect any problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed a missing link in the documentation. Other than that, looks good to me, thanks.
2d66042
to
5185515
Compare
mbedtls_hmac_drbg_free( &ctx ); | ||
mbedtls_hmac_drbg_init( &ctx ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmac_drbg_no_reseed()
test was failing before this change due to the reseed_interval
not set to a non zero value after hmac_drbg_free()
. This caused the subsquent mbedtls_hmac_drbg_random_with_add()
to reseed, failing the test.
@ronald-cron-arm I would argue that we should not support using the DRBG after free()
but before another init()
, since free()
destroys the context mutex. However we don't say this anywhere in the documentation. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for this late reply. I've checked with @gilles-peskine-arm and in fact the test is right and thus shouldn't be changed. mbedtls_hmac_drbg_free() should reset the context to a state that's equivalent to its state after the initial call to mbedtls_hmac_drbg_init(). One could argue that is more a reset than a free probably but that's the convention across mbedtls interfaces. The same apply to ctr_drbg. If this is ok with you, while at it, you are welcome to update the documentation of the free()
functions to clarify their behavior. It would be much appreciated but no worries if you don't have time to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this 'reset' convention does not apply to the MBEDTLS_THREADING_C mutex as after mbedtls_hmac_drbg_free
the mutex handle is NULL. I added mbedtls_mutex_init
after mbedtls_platform_zeroize
in mbedtls_hmac_drbg_free
in the latest patch. Likewise with ctr_drbg
. This would be consistent with 'resetting context to state after initial call to mbedtls_hmac_drbg_init
'
@ronald-cron-arm Are those test failures another CI glitch? I'm happy to clean up anything else here. |
The CI failed due to this having the "needs: work" label. I've removed and re-triggered now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The free()
functions have to be fixed (see #3393 (comment)).
* #MBEDTLS_CTR_DRBG_RESEED_INTERVAL by default. | ||
* You can override it by calling | ||
* mbedtls_ctr_drbg_set_reseed_interval(). | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a changelog entry file in ChangeLog.d
. Suggested content:
Bugfix
* In CTR_DRBG and HMAC_DRBG, don't reset the reseed interval in seed().
Fixes #2927.
ChangeLog.d/bugfix-2927.txt
Outdated
@@ -0,0 +1,3 @@ | |||
Bugfix | |||
* In CTR_DRBG and HMAC_DRBG, don't reset the reseed interval in seed(). | |||
Fixes #2927. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a newline at the end of the file (Unix text encoding).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this. Apart from the CI issue pointed out by @gilles-peskine-arm this looks good to me. I've checked that by reverting the changes in ctr_drbg.c and hmac_drbg.c the non-regression tests are falling as expected and where expected. Looking forward for the backports so we can merge this PR.
Signed-off-by: gacquroff <[email protected]>
Description
Fixes #2927
Summary of change
mbedtls_hmac_drbg_seed()
andmbedtls_ctr_drbg_seed()
were setting the entropy contextreseed_interval
to the default value of 10 000 even whenset_reseed_interval()
had been called prior toseed()
. The documentation did not describe the API behaving this way, and it doesn't make sense thatseed()
would remove any prior preference forreseed_interval
so this behavior has been fixed. Now, the value set byset_reseed_interval()
will persist through after a call toseed()
.Impact of changes
This change would break any application that
reseed_interval
and expected it to be reset to the default value once they calledseed()
reseed_interval
and was unknowingly using the default value for the lifetime of theDRBG
objectThe first situation could be dangerous if the set interval was very high and the PRNG was never reseeded. It is an unlikely scenario however because a user that understood the prior behavior would probably not design their application in this way anyways.
In the second situation, this change could expose a vulnerability in the user's application, so this could provide them with a net benefit.
Migration actions required
None
Documentation
Pull request type
Test results
Modifies
*_drbg_entropy_usage()
so thatset_reseed_interval()
is called beforeseed()
. This would fail before this patch.