Skip to content

DRBG documentation improvements #287

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

Conversation

gilles-peskine-arm
Copy link
Collaborator

@gilles-peskine-arm gilles-peskine-arm commented Oct 3, 2019

Improve the documentation of the CTR_DRBG and HMAC_DRBG modules. This part is a straightfoward forward-port of Mbed-TLS/mbedtls#2860: the 2.16 and 2.19 versions of hmac_drbg.h and ctr_drbg.h were near-identical and I changed them in identical ways.

git diff upstream-public/pr/2860  -- include/mbedtls/{ctr,hmac}_drbg.h

I am working on a separate pull request for the following changes (separate PR because it was getting really messy):

  1. mbedtls_hmac_drbg_seed() and mbedtls_ctr_drbg_seed() overrode the entropy length in the DRBG context, so calling mbedtls_hmac_drbg_set_entropy_len() or mbedtls_ctr_drbg_set_entropy_len() before calling xxx_seed() had no effect. Change the xxx_seed() functions to respect the entropy length set with xxx_set_entropy_len().
  2. In CTR_DRBG, systematically grab a nonce from the entropy source. This removes the difficulty of using the module in a NIST-compliant way.

Backports: 2.16 in Mbed-TLS/mbedtls#2860, 2.7 in Mbed-TLS/mbedtls#2878.

Internal ref: IOTCRYPT-180, IOTCRYPT-457

* State explicit whether several numbers are in bits or bytes.
* Clarify whether buffer pointer parameters can be NULL.
* Explain the value of constants that are dependent on the configuration.
@gilles-peskine-arm gilles-peskine-arm added bug Something isn't working enhancement New feature or request needs: review The pull request is ready for review. This generally means that it has no known issues. labels Oct 3, 2019
Document that a derivation function is used.

Document the security strength of the DRBG depending on the
compile-time configuration and how it is set up. In particular,
document how the nonce specified in SP 800-90A is set.

Mention how to link the ctr_drbg module with the entropy module.
Improve the formatting and writing of the documentation based on what
had been done for CTR_DRBG.

Document the maximum size and nullability of some buffer parameters.
NIST and many other sources call it a "personalization string", and
certainly not "device-specific identifiers" which is actually somewhat
misleading since this is just one of many things that might go into a
personalization string.
Explain how MBEDTLS_CTR_DRBG_ENTROPY_LEN is set next to the security
strength statement, rather than giving a partial explanation (current
setting only) in the documentation of MBEDTLS_CTR_DRBG_ENTROPY_LEN.
Separate the cases that achieve a 128-bit strength and the cases that
achieve a 256-bit strength.
In particular, don't use #MBEDTLS_xxx on macros that are undefined in
some configurations, since this would be typeset with a literal '#'.
It's an on/off feature, so it should be listed in version_features.
@gilles-peskine-arm gilles-peskine-arm added needs: work The pull request needs rework before it can be merged. and removed needs: review The pull request is ready for review. This generally means that it has no known issues. labels Oct 4, 2019
k-stachowiak
k-stachowiak previously approved these changes Oct 4, 2019
Copy link
Contributor

@k-stachowiak k-stachowiak left a comment

Choose a reason for hiding this comment

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

I have only found one potential editing issue (unless I've got the sentence wrong).

* mbedtls_hmac_drbg_set_entropy_len().
*
* \note The default entropy length is the security strength
* (converted from bits to bytes). You can override
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: This sentence is probably missing something like "You can override it with..."

The documentation of CTR_DRBG erroneously claimed that
mbedtls_ctr_drbg_set_entropy_len() had an impact on the initial
seeding. This is in fact not the case: mbedtls_ctr_drbg_seed() forces
the initial seeding to grab MBEDTLS_CTR_DRBG_ENTROPY_LEN bytes of
entropy. Fix the documentation and rewrite the discussion of the
entropy length and the security strength accordingly.
The documentation of HMAC_DRBG erroneously claimed that
mbedtls_hmac_drbg_set_entropy_len() had an impact on the initial
seeding. This is in fact not the case: mbedtls_hmac_drbg_seed() forces
the entropy length to its chosen value. Fix the documentation.
@gilles-peskine-arm gilles-peskine-arm added needs: review The pull request is ready for review. This generally means that it has no known issues. and removed needs: work The pull request needs rework before it can be merged. labels Oct 4, 2019
@gilles-peskine-arm gilles-peskine-arm changed the title DRBG documentation improvements and CTR_DRBG usage simplification DRBG documentation improvements Oct 4, 2019
k-stachowiak
k-stachowiak previously approved these changes Oct 7, 2019
This is a variant toggle, not an extra feature, so it should be tested
separately.
@gilles-peskine-arm
Copy link
Collaborator Author

CI failed in the Windows 2013 job. The failure is the CTR_DRBG selftest, The reason the selftest started failing is that I moved MBEDTLS_CTR_DRBG_USE_128_BIT_KEY to a different section in config.pl, so it got included in config.pl full. The selftest program has been failing when MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled ever since we introduced this option (#290) but we didn't realize until now because we were never enabling this option on the CI (#289).

I've excluded MBEDTLS_CTR_DRBG_USE_128_BIT_KEY from config.pl full. Fixing #289 and #290 is out of scope of this PR.

@gilles-peskine-arm
Copy link
Collaborator Author

The merge job passed except for check-generated-files.sh in TLS which is a known issue with a fix pending.

The head job failed because of some Jenkins wonkiness that's unrelated to the PR.

@AndrzejKurek AndrzejKurek self-requested a review October 11, 2019 08:06
@AndrzejKurek AndrzejKurek self-assigned this Oct 11, 2019
/**< The key size in bytes used by the cipher.
*
* Compile-time choice: 16 bytes (128 bits)
* because #MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between #MBEDTLS_CTR_DRBG_USE_128_BIT_KEY and \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY? Since I can see that both of these versions are used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#MACRO typesets MACRO and links to the definition of MACRO if MACRO is defined, but typesets #MACRO if MACRO is undefined, so it isn't good for preprocessor symbols that may or may not be defined. Hence the use of \c MACRO for symbols that may or may not be defined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY everywhere then? Or will doxygen ignore blocks that won't get compiled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It can be #MBEDTLS_CTR_DRBG_USE_128_BIT_KEY here because this comment is surrounded by #ifdef MBEDTLS_CTR_DRBG_USE_128_BIT_KEY.

* to achieve a 256-bit strength.
* - When using AES-128
* (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled)
* \p len must be at least 16 (in bytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't you mention previously that in such case the entropy len has to be at least 24?

128 bits if AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled)

  • and #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set to 24 or more (which is
  • always the case unless it is explicitly set to a different value
  • in config.h).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

24 for the initial seeding, 16 for subsequent reseeds. This function only influences subsequent reseeds. MBEDTLS_CTR_DRBG_ENTROPY_LEN influences both.

@gilles-peskine-arm
Copy link
Collaborator Author

CI ok. PR approved, near-identical PR for 2.16 approved, 2.7 backport approved. This is good to merge.

@gilles-peskine-arm gilles-peskine-arm removed the needs: review The pull request is ready for review. This generally means that it has no known issues. label Oct 11, 2019
@gilles-peskine-arm gilles-peskine-arm merged commit e5e9081 into ARMmbed:development Oct 11, 2019
gilles-peskine-arm added a commit to gilles-peskine-arm/mbed-crypto that referenced this pull request Nov 15, 2019
* ARMmbed#272: Insert doxygen comments on old algorithms so they appear in PSA documentation
* ARMmbed#285: SE driver: make persistent data work
* ARMmbed#279: Include IANA reference in the definition of ECC curves and DH groups
* ARMmbed#287: DRBG documentation improvements
* ARMmbed#297: Fix int overflow in mbedtls_asn1_get_int (Credit to OSS-Fuzz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants