Skip to content

Add factory entropy injection to the example #6

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

Merged
merged 3 commits into from
Dec 4, 2018

Conversation

Patater
Copy link
Contributor

@Patater Patater commented Nov 30, 2018

Add a fake factory entropy injection example and instructions in the README.

Also update the application configuration to explicitly enable PSA to enable the example to run on more targets. The example will not be very interesting if PSA is not enabled...

@Patater Patater added the enhancement New feature or request label Nov 30, 2018
@Patater Patater force-pushed the factory-entropy-example branch from 0d588f0 to eeaefad Compare November 30, 2018 17:21
main.cpp Outdated
/* mbedtls_psa_inject_entropy() depends on both MBEDTLS_ENTROPY_NV_SEED and
* MBEDTLS_PSA_HAS_ITS_IO being enabled by the Mbed TLS configuration
* system. */
#if defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_PSA_HAS_ITS_IO)
Copy link
Contributor

@netanelgonen netanelgonen Dec 2, 2018

Choose a reason for hiding this comment

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

This may be wrong in case of 2 cores.
for example the Psoc6:
the M4 core will not have NV_SEED (so this function will not compile) but defined but the M0 will have it. (This comment applies on both of the defined )

Choose a reason for hiding this comment

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

Agreed. However, we may want to comment this is a generic implementation for single core systems and may need to be implemented on cases-by case basis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -1,7 +1,8 @@
{
"target_overrides": {
"*": {
"platform.stdio-convert-newlines": true
"platform.stdio-convert-newlines": true,
"target.extra_labels_add": ["PSA"]
Copy link
Contributor

Choose a reason for hiding this comment

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

currently, in addition to PSA label, you must add the MBEDTLS_PSA_CRYPTO_C.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added via new Mbed TLS user configuration file

Copy link
Contributor

@itayzafrir itayzafrir left a comment

Choose a reason for hiding this comment

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

A couple of minors.

main.cpp Outdated
seed[i] = i;
}

int status = mbedtls_psa_inject_entropy(seed, sizeof(seed));
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra space after = sign

Suggested change
int status = mbedtls_psa_inject_entropy(seed, sizeof(seed));
int status = mbedtls_psa_inject_entropy(seed, sizeof(seed));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

main.cpp Outdated
if (status) {
/* The device may already have an NV Seed injected, or another error
* may have happened during injection. */
mbedtls_printf("warning - this attempt at entropy injection failed\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe print the error code here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@MarceloSalazar
Copy link

Looks good.
Hope we can merged this to the mbed-os-5.11.0-oob branch to let us start the review asap.

@Patater Patater force-pushed the factory-entropy-example branch from eeaefad to aaed571 Compare December 3, 2018 12:28
Make the example demonstrate entropy injection by adding a new function,
called before psa_crypto_init(), that attempts to inject some fake
entropy into the system. Print a warning message if injecting entropy
fails.
This example requires PSA to be enabled in order for the PSA APIs to be
available for use. This example uses PSA Crypto APIs and thus requires
the target to have the PSA label in order to make those PSA APIs
available.
@Patater Patater force-pushed the factory-entropy-example branch from aaed571 to 087c018 Compare December 3, 2018 12:33
Since this example is not useful without PSA Crypto APIs, enable PSA
Crypto APIs by default via an Mbed TLS user configuration file, along
with a default implmentation of the PSA Entropy Injection API that
uses PSA storage (ITS).
Copy link
Contributor

@itayzafrir itayzafrir left a comment

Choose a reason for hiding this comment

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

LGTM

@Patater Patater force-pushed the factory-entropy-example branch from 087c018 to 276fde4 Compare December 3, 2018 14:51
@Patater
Copy link
Contributor Author

Patater commented Dec 3, 2018

Updated so that this example should work whether being built for the NSPE of a partitioned system, or a single v7-M target.

Copy link
Contributor

@netanelgonen netanelgonen left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@itayzafrir itayzafrir left a comment

Choose a reason for hiding this comment

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

LGTM

@Patater Patater merged commit 441daf7 into ARMmbed:master Dec 4, 2018
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.

4 participants