Skip to content
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

Alternative random generator support for PSA #3895

Merged
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
90edc99
Create a header file for PSA crypto random generator abstraction
gilles-peskine-arm Nov 13, 2020
30524eb
psa_crypto: create random and drbg abstraction
gilles-peskine-arm Nov 13, 2020
f08b3f8
Autonomous random driver: create configuration option
gilles-peskine-arm Nov 13, 2020
514a8fd
Create a file for PSA crypto test helpers
gilles-peskine-arm Nov 13, 2020
b8af228
Autonomous random driver: declare the type and function
gilles-peskine-arm Nov 13, 2020
1c49f1a
Include headers in psa_crypto.h for mbedtls_to_psa_error
gilles-peskine-arm Nov 13, 2020
4fc21fd
Implement MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
gilles-peskine-arm Nov 13, 2020
82e57d1
PSA: support HMAC_DRBG
gilles-peskine-arm Nov 13, 2020
ed03890
PSA: allow the configuration to favor HMAC_DRBG
gilles-peskine-arm Nov 13, 2020
68cc434
PSA support for HMAC_DRBG: changelog entry
gilles-peskine-arm Nov 13, 2020
14c332b
Fix a Doxygen warning
gilles-peskine-arm Nov 14, 2020
89ffb28
Fix option compatibility check
gilles-peskine-arm Nov 18, 2020
b663a60
Note the expectations on mbedtls_psa_external_get_random()
gilles-peskine-arm Nov 18, 2020
c096301
Document mbedtls_psa_external_random_context_t
gilles-peskine-arm Nov 18, 2020
c109b37
Test MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
gilles-peskine-arm Nov 23, 2020
bee96c8
Explain the conditions for checking DRBG error codes
gilles-peskine-arm Nov 23, 2020
b0a748e
Copyediting
gilles-peskine-arm Nov 30, 2020
e995b9b
Clarify statuses from mbedtls_psa_external_get_random
gilles-peskine-arm Nov 30, 2020
5894e8e
Replace mbedtls_psa_random_state( ... ) by MBEDTLS_PSA_RANDOM_STATE
gilles-peskine-arm Dec 14, 2020
8814fc4
Make mbedtls_psa_get_random more usable outside psa_crypto.c
gilles-peskine-arm Dec 14, 2020
b2b64d3
Rename psa_crypto_random.h to psa_crypto_random_impl.h
gilles-peskine-arm Dec 14, 2020
b3cd963
Pacify check-names.sh
gilles-peskine-arm Dec 14, 2020
88fa5c4
Minor documentation improvements
gilles-peskine-arm Jan 4, 2021
71ddab9
Simplify the chunk loop in psa_generate_random
gilles-peskine-arm Jan 4, 2021
0c59ba8
Fix the error detection in psa_generate_random
gilles-peskine-arm Jan 5, 2021
9c3e060
Explain the design of mbedtls_psa_get_random better
gilles-peskine-arm Jan 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -6394,21 +6394,18 @@ psa_status_t psa_generate_random( uint8_t *output,

#else /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */

int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;

while( output_size > MBEDTLS_PSA_RANDOM_MAX_REQUEST )
int ret = 0;
while( output_size > 0 )
{
ret = mbedtls_psa_get_random(
MBEDTLS_PSA_RANDOM_STATE,
output, MBEDTLS_PSA_RANDOM_MAX_REQUEST );
if( ret != 0 )
return( mbedtls_to_psa_error( ret ) );
output += MBEDTLS_PSA_RANDOM_MAX_REQUEST;
output_size -= MBEDTLS_PSA_RANDOM_MAX_REQUEST;
size_t request_size =
( output_size > MBEDTLS_PSA_RANDOM_MAX_REQUEST ?
MBEDTLS_PSA_RANDOM_MAX_REQUEST :
output_size );
ret = mbedtls_psa_get_random( MBEDTLS_PSA_RANDOM_STATE,
output, request_size );
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to get out of the loop if ret is not equal to zero.

output_size -= request_size;
output += request_size;
}

ret = mbedtls_psa_get_random( MBEDTLS_PSA_RANDOM_STATE,
output, output_size );
return( mbedtls_to_psa_error( ret ) );
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
}
Expand Down