-
Notifications
You must be signed in to change notification settings - Fork 38
[tf-psa-crypto] MBEDTLS_PLATFORM_GET_ENTROPY_ALT in 4.0 #212
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
base: development
Are you sure you want to change the base?
[tf-psa-crypto] MBEDTLS_PLATFORM_GET_ENTROPY_ALT in 4.0 #212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a design review. I won't be able to do a full code review.
We just realized this morning that the issue description wasn't very clear, and several things were in Janos's mind and mine but we hadn't written them down. Sorry about this. I added a note to the issue and some comments here, hopefully that should clarify things.
* in such information, so the function must handle | ||
* this. | ||
*/ | ||
int mbedtls_entropy_hardware_poll(unsigned char *output, size_t output_size, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocker: since the function is now declared in platform.h
, should we call it mbedtls_platform_xxx
? Same question about the configuration option. Maybe MBEDTLS_PLATFORM_GET_ENTROPY_ALT
and mbedtls_platform_get_entropy()
?
* \param[out] entropy_content Measure of the entropy content (in bits) of the | ||
* data written in the \p output buffer. The pointer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the constraint that for the time being, the function must set entropy_content = 8 * *output_len
on success. The library will be extended later to support partial entropy.
* can be \c NULL in case the caller is not interested | ||
* in such information, so the function must handle | ||
* this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to support callers that don't want the value. entropy_content
is guaranteed to be non-null.
* \brief User defined callback function that is used from the entropy | ||
* module to gather entropy data from some hardware device. | ||
* | ||
* \warning This is not provided by Mbed TLS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think “not provided by Mbed TLS” is a useful warning. Also, it's TF-PSA-Crypto now.
On the other hand, the function's documentation should state that this function is only used when MBEDTLS_ENTROPY_HARDWARE_POLL
is defined. This is otherwise not visible when you read the Doxygen-rendered documentation.
ChangeLog.d/9618.txt
Outdated
`MBEDTLS_ENTROPY_HARDWARE_POLL_MIN` can optionally optinally define the | ||
minimum number of bytes that should be polled using that function before | ||
declaring entropy gathering completed. If not defined, then a default | ||
value of 32 bytes is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MBEDTLS_ENTROPY_HARDWARE_POLL_MIN
should not be a configuration parameter, at least not in this form. The RNG needs a certain amount of entropy. This minimum is up to the system configuration (and in particular the required cryptographic strength for the system), not up to the hardware integration. The person writing the TRNG device driver doesn't get to choose this value.
I think we should just use the existing MBEDTLS_ENTROPY_MIN_PLATFORM
here. The distinction between “platform source” and “hardware source” doesn't really make sense as it's currently described in entropy_poll.h
. Actually the “platform source” is the operating system integrations that the library supports out of the box, and the “hardware source” is the one for other systems where the integrator needs to provide a driver.
ChangeLog.d/9618.txt
Outdated
removed. | ||
|
||
Features | ||
* The new symbol `MBEDTLS_ENTROPY_HARDWARE_POLL` is added to allow the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog entries should probably mention the function names as well as the option names, for easier searching.
drivers/builtin/src/entropy_poll.h
Outdated
void *data, unsigned char *output, size_t len, size_t *olen) | ||
{ | ||
(void) data; | ||
return mbedtls_entropy_hardware_poll(output, len, olen, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapper should check the entropy content and fail if it's less than full entropy, i.e. if entropy_output < 8 * *olen
. Please add a unit test for that in test_suite_entropy
.
Also the entropy collection should fail if *olen
is too small and as a result there isn't enough entropy, collected from all sources. I believe this is covered by the existing tests in test_suite_entropy
, but please double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapper should check the entropy content and fail if it's less than full entropy, i.e. if entropy_output < 8 * *olen. Please add a unit test for that in test_suite_entropy.
While adding the check on the wrapper and testing it with the new component tf_psa_crypto_platform_get_entropy_alt
I found that tests are already failing if the returned entropy content is not correct, so there seems to be no need for a new test step. As reference implementation I'm using the one proposed in the companion PR Mbed-TLS/mbedtls-framework#151.
49842b8
to
a5de9ab
Compare
a5de9ab
to
17e588b
Compare
dfe34b3
to
92e6f42
Compare
I think that CI failures in |
92e6f42
to
fa5d3d3
Compare
I just forced push the last commit following the merge of Mbed-TLS/mbedtls-framework#151. No other change was made |
Thinking on this a bit more I think I can explain why |
0b4ca69
Signed-off-by: Valerio Setti <[email protected]>
Signed-off-by: Valerio Setti <[email protected]>
This is necessary to let entropy being able to gather entropy data from the native platform source. Signed-off-by: Valerio Setti <[email protected]>
…_entropy() Signed-off-by: Valerio Setti <[email protected]>
Signed-off-by: Valerio Setti <[email protected]>
Since this is now an internal function, output_size always comes from our library code, and we can assume that it has a “reasonable” size — tens of bytes, definitely less than ULONG_MAX which is 2^32. So the loop is no longer needed. Signed-off-by: Valerio Setti <[email protected]>
Signed-off-by: Valerio Setti <[email protected]>
Signed-off-by: Valerio Setti <[email protected]>
Signed-off-by: Valerio Setti <[email protected]>
Signed-off-by: Valerio Setti <[email protected]>
…py() Signed-off-by: Valerio Setti <[email protected]>
…alt() Signed-off-by: Valerio Setti <[email protected]>
…lt() Test also the case in which the callback is returning less data than requested. In this case the entropy module will call the callback until it reaches the minimum required amount of data. Signed-off-by: Valerio Setti <[email protected]>
…alt() Ensure that all forced values on mbedtls_platform_get_entropy() are reset before quitting the test functions. This prevents weird failures on subsequent tests that might be executed. Signed-off-by: Valerio Setti <[email protected]>
4320b04
525c5cb
to
4320b04
Compare
@gilles-peskine-arm @bjwtaylor I just updated the |
…ropy() Signed-off-by: Valerio Setti <[email protected]>
4320b04
to
ced4965
Compare
Remaining CI failures are:
which is reasonable since the main repo is tested on the |
It's problematic to merge something in the crypto repository that breaks the CI, since it means crypto will be broken on all branches that don't have this PR merged yet. Can you please add a transition function |
…py_poll() This is temporary and going to be removed by Mbed-TLS#273 Signed-off-by: Valerio Setti <[email protected]>
Signed-off-by: Valerio Setti <[email protected]>
ced4965
to
88c818c
Compare
@gilles-peskine-arm I just created #273 to track this |
@gilles-peskine-arm although I added the stub function for |
Description
This helps resolving Mbed-TLS/mbedtls#9618
CI note
Due to dependencies with the main repo PR please evaluate the CI of 10090 as validation of this PR.
PR checklist