Skip to content

Add TRNG support for KW41Z #4050

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 1 commit into from
Mar 29, 2017

Conversation

mmahadevan108
Copy link
Contributor

@mmahadevan108 mmahadevan108 commented Mar 28, 2017

Add support to use the TRNG module for entropy generation.

Status

**READY

  • Tests
    Passed mbed compliance tests.

@0xc0170 0xc0170 changed the base branch from master to mbed-os-workshop-17q2 March 28, 2017 11:45
@0xc0170 0xc0170 requested review from yanesca and simonbutcher March 28, 2017 11:45
*output_length = length;
return 0;
} else {
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
Copy link
Contributor

@0xc0170 0xc0170 Mar 28, 2017

Choose a reason for hiding this comment

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

This should return -1 as documented. This mapping (HAL return codes to mbedtls) should be done in the mbedtls-HAL wrapper that is in the platform folder (it's missing as pinpointed by @stevew817 ).

@mmahadevan108
Copy link
Contributor Author

@maclobdell @0xc0170

Signed-off-by: Mahadevan Mahesh <[email protected]>
@0xc0170
Copy link
Contributor

0xc0170 commented Mar 28, 2017

any tests run - to be shared here?

@mmahadevan108
Copy link
Contributor Author

Ran "authcrypt" from mbed TLS Examples. Below is the log:


plaintext message: 536f6d65207468696e67732061726520626574746572206c65667420756e7265616400
ciphertext: 5fe6e3916ca609ad4e19575265179d8b097e404c3bc77e30ac545c2e700e367e9c49f8cf2f5561d6cd246329134990ed9275a55b1e76bda9012dae
decrypted: 536f6d65207468696e67732061726520626574746572206c65667420756e7265616400

DONE


@sg-
Copy link
Contributor

sg- commented Mar 28, 2017

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1769

All builds and test passed!

@sg- sg- merged commit 3661845 into ARMmbed:mbed-os-workshop-17q2 Mar 29, 2017
@mmahadevan108 mmahadevan108 deleted the Add_KW41_TRNG branch March 30, 2017 09:59
@@ -0,0 +1,60 @@
/*
* Hardware entropy collector for the K64F, using Freescale's RNGA
Copy link
Contributor

Choose a reason for hiding this comment

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

The target name seems to be incorrect on this line

*/

/*
* Reference: "K64 Sub-Family Reference Manual, Rev. 2", chapter 34
Copy link
Contributor

Choose a reason for hiding this comment

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

This reference is misleading here, it would be very helpful to have the right document 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.

Thank you. I have fixed this.

{
trng_config_t trngConfig;

TRNG_GetDefaultConfig(&trngConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the manual this function can return with an error. Because of the API we can't propagate this error, but we still need to make it sure that if an error has happened here then any subsequent calls to trng_get_bytes() will fail with an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error returned is in case the user passes an invalid argument (invalid uage of this API). This will not happen in mbed HAL.

/* Set sample mode of the TRNG ring oscillator to Von Neumann, for better random data.*/
trngConfig.sampleMode = kTRNG_SampleModeVonNeumann;
/* Initialize TRNG */
TRNG_Init(TRNG0, &trngConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the manual this function can return with an error. Because of the API we can't propagate this error, but we still need to make it sure that if an error has happened here then any subsequent calls to trng_get_bytes() will fail with an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error returned is in case the user passes an invalid argument (invalid uage of this API). This will not happen in mbed HAL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants