HMAC DRBG requires more entropy than what Mbed Crypto's entropy implementation offers #237
Labels
No labels
api-spec
bug
CLA requested
CLA valid
compliance
DO NOT MERGE
duplicate
enhancement
feature branch
good first issue
HEADER FORMATTING ISSUE
help wanted
Information
invalid
Jira status: AWAITING REVIEW
Jira status: CLOSED
Jira status: DONE
Jira status: IN PROGRESS
Jira status: IN REVIEW
Jira status: OPEN
Jira status: REOPENED
Jira status: RESOLVED
mirrored
mirror internally
needs: backports
needs: ci
needs: design review
needs: preceding PR
needs: review
needs: work
notabug
open for community contribution
Product Backlog
question
ready for merge
security
stale
type: bug
type: enhancement
type: question
web pages
wontfix
writing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-ARMmbed/mbed-crypto#237
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a report on behalf of @artokin who discovered this issue.
Summary: Mbed Crypto's HMAC DRBG implementation doesn't work together with Mbed Crypto's default entropy implementation if
MBEDTLS_SHA512_Cis disabled, due to a mismatch in the amount of entropy HMAC DRBG requires in this case, and what the entropy module can provide.Details: During seeding, the HMAC DRBG implementation queries the configured entropy callback for entropy, the amount of which depending on the digest function chosen:
github.com/ARMmbed/mbed-crypto@85c78b48a9/library/hmac_drbg.c (L236-L250)In particular, if the chosen hash is not SHA-1, this requires at least
24 * 3/2 = 36Bytes to beprovided by the underlying entropy callback
entropy(). However, because ofgithub.com/ARMmbed/mbed-crypto@85c78b48a9/library/entropy.c (L326-L333)Mbed Crypto's entropy implementation rejects requests beyond
MBEDTLS_ENTROPY_BLOCK_SIZEBytes, that is, beyond 32 Bytes ifMBEDTLS_SHA512_Cis disabled:github.com/ARMmbed/mbed-crypto@85c78b48a9/include/mbedtls/entropy.h (L77-L81)This leads to failures when trying to use HMAC DRBG with the default entropy module in SHA-256-only configurations.
Apart from the issue itself, this also highlights a test gap, because we should test this very natural combination. When considering the use of Mbed Crypto in Mbed TLS, for example, the
ssl_client2andssl_server2example application should be able to use HMAC DRBG instead of CTR DRBG if the latter is disabled, which would trigger this bug. (Internal: See PR https://github.com/ARMmbed/mbedtls-restricted/pull/646).I have a patch for that in https://github.com/gilles-peskine-arm/mbedtls/tree/build_with_only_montgomery_curves which is an earlier version of https://github.com/ARMmbed/mbedtls/pull/2019 which is still waiting for me or someone else to rework it.