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

Expose the PSA RNG in mbedtls #4110

Commits on Feb 3, 2021

  1. Fix exit status if the RNG seeding failed

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 3, 2021
    Configuration menu
    Copy the full SHA
    4a23c98 View commit details
    Browse the repository at this point in the history
  2. Refuse reproducible mode with MBEDTLS_USE_PSA_CRYPTO

    With MBEDTLS_USE_PSA_CRYPTO, some of the randomness for the TLS
    connection is generated inside the PSA crypto subsystem, which has no
    reproducible mode. Whether there is a nonzero amount of randomness
    coming from inside the PSA subsystem rather than from the random
    generator set by mbedtls_ssl_conf_rng() depends on the choice of
    cipher suite and other connection parameters as well as the level of
    support for MBEDTLS_USE_PSA_CRYPTO. Rather than give unreliable
    results, conservatively abort with a clear error message.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 3, 2021
    Configuration menu
    Copy the full SHA
    aaedbdc View commit details
    Browse the repository at this point in the history
  3. Duplicate no-DRBG tests: with and without MBEDTLS_USE_PSA_CRYPTO

    Whether MBEDTLS_USE_PSA_CRYPTO is enabled makes a significant
    difference with respect to how random generators are used (and, for
    no-HMAC_DRBG, how ECDSA signature is dispatched), so test both with
    and without it.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 3, 2021
    Configuration menu
    Copy the full SHA
    2747d7d View commit details
    Browse the repository at this point in the history
  4. New test suite for random generation

    Test random generation as a whole. This is different from
    test_suite_*_drbg and test_suite_entropy, which respectively test PRNG
    modules and entropy collection.
    
    Start with basic tests: good-case tests, and do it twice and compare
    the results to validate that entropy collection doesn't repeat itself.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 3, 2021
    Configuration menu
    Copy the full SHA
    077599a View commit details
    Browse the repository at this point in the history

Commits on Feb 16, 2021

  1. Expose mbedtls_psa_get_random()

    Expose whatever RNG the PSA subsystem uses to applications using the
    mbedtls_xxx API.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    e3ed802 View commit details
    Browse the repository at this point in the history
  2. Support mbedtls_psa_get_random() in SSL test programs

    The SSL test programs can now use mbedtls_psa_get_random() rather than
    entropy+DRBG as a random generator. This happens if
    the configuration option MBEDTLS_USE_PSA_CRYPTO is enabled, or if
    MBEDTLS_TEST_USE_PSA_CRYPTO_RNG is set at build time.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    8eb2943 View commit details
    Browse the repository at this point in the history
  3. Add comments to a few #endif closing a long chunk

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    34babfc View commit details
    Browse the repository at this point in the history
  4. Fix psa_destroy_key called after mbedtls_psa_crypto_free

    Move the call to destroy the PSK to before freeing the SSL session
    data and calling rng_free(), which deinitializes the PSA subsystem.
    This particular ordering was chosen to make the ssl_client2 more
    similar to ssl_server2. This fixes the client failing on the
    psa_destroy_key() call in `ssl-opt.sh -f 'opaque psk on client'`.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    b8c4840 View commit details
    Browse the repository at this point in the history
  5. The PSA external RNG does not require MBEDTLS_USE_PSA_CRYPTO

    The dependency is on MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG plus
    MBEDTLS_PSA_CRYPTO_C. MBEDTLS_USE_PSA_CRYPTO is irrelevant.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    1dc19ff View commit details
    Browse the repository at this point in the history
  6. In external_rng tests, disable the entropy module

    The point of having an external RNG is that you can disable all
    built-in RNG functionality: both the entropy part and the DRBG part.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    38c12fd View commit details
    Browse the repository at this point in the history
  7. SSL test programs: always allow building with the PSA external RNG

    The SSL test programs can now use the PSA RNG, and the PSA RNG can use
    an external RNG. The build conditions hadn't been updated and didn't
    cover the case when MBEDTLS_TEST_USE_PSA_CRYPTO_RNG is enabled but
    MBEDTLS_USE_PSA_CRYPTO is disabled. Fix this.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    8133abd View commit details
    Browse the repository at this point in the history
  8. Fix the use of unitialized memory with MBEDTLS_TEST_NULL_ENTROPY

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    8e1e46e View commit details
    Browse the repository at this point in the history
  9. Exclude random_twice tests with MBEDTLS_TEST_NULL_ENTROPY

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    ddeb889 View commit details
    Browse the repository at this point in the history
  10. Initialize the test RNG whenever it's present

    It's no longer restricted to MBEDTLS_USE_PSA_CRYPTO.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    48113eb View commit details
    Browse the repository at this point in the history
  11. Clarify where mbedtls_psa_get_random might be useful

    Also fix some typos.
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    d548d96 View commit details
    Browse the repository at this point in the history
  12. Explain the "external RNG large" test case

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    cd2d648 View commit details
    Browse the repository at this point in the history
  13. Minor clarification in the public documentation

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    2cff7e2 View commit details
    Browse the repository at this point in the history
  14. Make it possible to include psa_crypto_random_impl.h with psa_util.h

    There was some intentional duplication between
    library/psa_crypto_random_impl.h and include/mbedtls/psa_util.h, with
    the intent that the compiler would complain if one file was edited in
    a way that's incompatible with the other file. However, the two files
    were never included together, and in fact could not be included
    together because some definitions can't be duplicated (type, static
    variable).
    
    Now library/psa_crypto_random_impl.h includes
    include/mbedtls/psa_util.h, so the compiler will check what it can.
    There is less redundancy since it isn't always possible to declare
    something twice (specifically, types can't be declared).
    
    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    996f216 View commit details
    Browse the repository at this point in the history
  15. Work around MSVC bug with duplicate static declarations

    Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
    gilles-peskine-arm committed Feb 16, 2021
    Configuration menu
    Copy the full SHA
    277a3a6 View commit details
    Browse the repository at this point in the history