Skip to content

Conversation

gilles-peskine-arm
Copy link
Collaborator

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

Test MBEDTLS_CTR_DRBG_USE_128_BIT_KEY properly. Fix #289. Fix #290.

Follow-up of #287.

Needs backports: to 2.16 (almost identical); to 2.7 (only for the config.h and all.sh changes that are about MBEDTLS_ENTROPY_FORCE_SHA256).

@gilles-peskine-arm gilles-peskine-arm added bug Something isn't working enhancement New feature or request needs: preceding PR Requires another PR to be merged first needs: review The pull request is ready for review. This generally means that it has no known issues. labels Oct 7, 2019
@gilles-peskine-arm gilles-peskine-arm removed the needs: preceding PR Requires another PR to be merged first label Oct 11, 2019
@gilles-peskine-arm
Copy link
Collaborator Author

gilles-peskine-arm commented Nov 12, 2019

@gilles-peskine-arm gilles-peskine-arm added needs: ci Needs a passing full CI run and removed needs: ci Needs a passing full CI run labels Nov 12, 2019
@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 Nov 21, 2019
@gilles-peskine-arm
Copy link
Collaborator Author

I'll rebase again :(

@AndrzejKurek AndrzejKurek self-requested a review November 21, 2019 12:19
In the CTR_DRBG module, add selftest data for when
MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled.

I generated the test data by running our own code. This is ok because
we have other tests that ensure that the algorithm is implemented
correctly.

This makes programs/self/selftest pass when
MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled.
The test suites should always run self-tests for all enabled features.
Otherwise we miss failing self-tests in CI runs, because we don't
always run the selftest program independently.

There was one spurious dependency to remove:
MBEDTLS_CTR_DRBG_USE_128_BIT_KEY for ctr_drbg, which was broken but
has now been fixed.
This is a variant toggle, not an extra feature, so it should be tested
separately.

We test most of the effect of MBEDTLS_ENTROPY_FORCE_SHA256 (namely,
using SHA-256 in the entropy module) when we test the library with the
SHA512 module disabled (which we do at least via depends-hashes.pl).
This commit removes testing of the MBEDTLS_ENTROPY_FORCE_SHA256 option
itself, which should be added separately.
The size of the seedfile used by the entropy module when
MBEDTLS_ENTROPY_NV_SEED is enabled is 32 byte when
MBEDTLS_ENTROPY_FORCE_SHA256 is enabled or MBEDTLS_SHA512_C is
disabled, and 64 bytes otherwise. A larger seedfile is ok on
entry (the code just grabs the first N bytes), but a smaller seedfile
is not ok. Therefore, if you run a component with a 32-byte seedfile
and then a component with a 64-byte seedfile, the second component
fails in the unit tests (up to test_suite_entropy which erases the
seedfile and creates a fresh one).

This is ok up to now because we only enable MBEDTLS_ENTROPY_NV_SEED
together with MBEDTLS_ENTROPY_FORCE_SHA256. But it prevents enabling
MBEDTLS_ENTROPY_NV_SEED without MBEDTLS_ENTROPY_FORCE_SHA256.

To fix this, unconditionally create a seedfile before each component.
Test MBEDTLS_CTR_DRBG_USE_128_BIT_KEY and MBEDTLS_ENTROPY_FORCE_SHA256
together and separately.
@gilles-peskine-arm gilles-peskine-arm added needs: ci Needs a passing full CI run and removed needs: work The pull request needs rework before it can be merged. labels Nov 21, 2019
@gilles-peskine-arm
Copy link
Collaborator Author

@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: ci Needs a passing full CI run labels Nov 21, 2019
@piotr-now piotr-now self-requested a review December 13, 2019 10:23
static const unsigned char result_nopr[16] =
{ 0x6c, 0x25, 0x27, 0x95, 0xa3, 0x62, 0xd6, 0xdb,
0x90, 0xfd, 0x69, 0xb5, 0x42, 0x9, 0x4b, 0x84 };
#else /* MBEDTLS_CTR_DRBG_USE_128_BIT_KEY */
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you think it would be more readable if there was added one extra line before and one after #else? Just as in the line 681?

@gilles-peskine-arm gilles-peskine-arm merged commit 180850a into ARMmbed:development Dec 20, 2019
gilles-peskine-arm added a commit to gilles-peskine-arm/mbed-crypto that referenced this pull request Feb 3, 2020
Previously in d875285:
* ARMmbed#333: Streamline PSA key type encodings: prepare
* ARMmbed#323: Initialise return values to an error

Previously in dbcb442:
* ARMmbed#291: Test MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
* ARMmbed#334: Fix some pylint warnings

Previously in ceceedb:
* ARMmbed#348: Bump version to Mbed TLS 2.20.0 and crypto SO version to 4
* ARMmbed#354: Fix incrementing pointer instead of value

In this commit:
* ARMmbed#349: Fix minor defects found by Coverity
* ARMmbed#179: Add option to build SHA-512 without SHA-384
* ARMmbed#327: Implement psa_hash_compute and psa_hash_compare
* ARMmbed#330: Streamline PSA key type and curve encodings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The selftest program fails with MBEDTLS_CTR_DRBG_USE_128_BIT_KEY MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is not tested

3 participants