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

Fixed seed variable concatenation pointer. #3973

Merged
merged 10 commits into from
Jan 6, 2021
Merged

Fixed seed variable concatenation pointer. #3973

merged 10 commits into from
Jan 6, 2021

Conversation

stroebeljc
Copy link
Contributor

@stroebeljc stroebeljc commented Dec 24, 2020

Description

This request fixes a minor issue with random number generation in CTR_DRBG (issue #3819). The current implementation places the nonce value at the same starting location as the just retrieved seed value. However, the seed size is still incremented, resulting in a section of zeroes the same length as the nonce at the end of the seed.

This fix just moves the nonce to where it is supposed to be in the concatenated seed.

Fixes #3819

Status

READY

Backports needed?

NO - the feature with the problem is not present in any of the LTS branches.

Steps to test or reproduce

The self-test was updated to include nonce concatenation and expected results.

Signed-off-by: ENT\stroej1 <john.stroebel@medtronic.com>
@stroebeljc stroebeljc marked this pull request as ready for review December 24, 2020 01:37
@mpg
Copy link
Contributor

mpg commented Dec 24, 2020

Hi @stroebeljc and thanks for your contribution! Indeed the current behaviour of the code does no seem intentional: overwriting entropy with other entropy does not make sense, and is in direct contradiction with the documentation of mbedtls_ctr_drbg_seed() which clearly states that the outputs of the two calls to f_entropy are concatenated. Thanks for spotting that!

I'm taking the liberty of editing the PR description to add that backports are not needed, as the feature is not present in any of the LTS branches. Note: the feature was introduced in ARMmbed/mbed-crypto#305 and had this bug from the start.

@mpg mpg added bug Community needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Dec 24, 2020
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks absolutely good to me, so I'm going to focus on what's not there :)

  • I think this deserves a ChangeLog entry as a Bugfix, can you add one? (See ChangeLog.d/00README.md` for how to do that.)
  • I'm not fully convinced that this can't be tested so I think it's worth at least discussing that point a bit more. In tests/suites/test_suite_ctr_drbg.function we use a "fixed" entropy callback, mbedtls_test_entropy_func for several purposes including tracking how much "entropy" was consumed and validating output against test vectors. I think the same approach should work here. IMO the questions are: (1) can we find test vectors from a trusted source that covers the desired length? and (2) if not, would it still be worth adding a test based on values generated after your patch, just to avoid any regression in the future?

Could you look a bit more into how this could bit tested and let me know what you think? (Also, once less people are on holiday, a second team member is going to review this as well and might have opinions or suggestions on this too.)

ENT\stroej1 added 3 commits December 24, 2020 12:24
…eding.

Signed-off-by: ENT\stroej1 <john.stroebel@medtronic.com>
Signed-off-by: ENT\stroej1 <john.stroebel@medtronic.com>
…rray and updated results.

Signed-off-by: ENT\stroej1 <john.stroebel@medtronic.com>
@stroebeljc
Copy link
Contributor Author

stroebeljc commented Dec 25, 2020

I took a look at NIST DRBG test vectors to see if the CTR_CRBG algorithm is working as expected. Found that the self test routine was not complete and correct, so I updated the method and its data to verify proper operation with actual NIST test vectors.

Signed-off-by: ENT\stroej1 <john.stroebel@medtronic.com>
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very good! I'm just requesting a comment in the self-test function documenting the origin of the test data.

library/ctr_drbg.c Show resolved Hide resolved
@mpg mpg added needs-work and removed needs-review Every commit must be reviewed by at least two team members, labels Dec 28, 2020
Signed-off-by: ENT\stroej1 <john.stroebel@medtronic.com>
mpg
mpg previously approved these changes Dec 29, 2020
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reference! Looks all good to me now.

@mpg mpg removed the needs-work label Dec 29, 2020
@mpg
Copy link
Contributor

mpg commented Dec 29, 2020

Now the next step is for another team member to review, which is unlikely to happen this week as most of the team is on leave, but hopefully some time next week.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Thanks for finding and fixing this! I'm mostly happy but I'd like some minor documentation improvements.

I'd have preferred to keep the self-tests as they were and improve the unit tests, but since you've already changed the unit tests, let's go with that. I've filed a request for unit tests separately. We shouldn't have things that are only validated through self-tests and not through specific unit tests, but it'll do for now.

library/ctr_drbg.c Outdated Show resolved Hide resolved
library/ctr_drbg.c Outdated Show resolved Hide resolved
library/ctr_drbg.c Show resolved Hide resolved
ChangeLog.d/issue3819.txt Outdated Show resolved Hide resolved
@gilles-peskine-arm gilles-peskine-arm added needs-work and removed needs-reviewer This PR needs someone to pick it up for review labels Jan 4, 2021
Signed-off-by: stroebeljc <stroebeljc1@gmail.com>
Signed-off-by: stroebeljc <stroebeljc1@gmail.com>
Signed-off-by: stroebeljc <stroebeljc1@gmail.com>
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from the changelog entry.

ChangeLog.d/issue3819.txt Outdated Show resolved Hide resolved
Signed-off-by: stroebeljc <stroebeljc1@gmail.com>
@gilles-peskine-arm gilles-peskine-arm requested a review from mpg January 5, 2021 17:38
@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Jan 5, 2021
Copy link
Contributor

@mpg mpg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mpg mpg added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Jan 6, 2021
@mpg mpg merged commit 75fdd06 into Mbed-TLS:development Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mbedtls_ctr_drbg_reseed_internal issue
3 participants