From be55bb2d5db56d2f54c4d78ed698c6d585ad593e Mon Sep 17 00:00:00 2001 From: Aditya Deshpande Date: Tue, 21 Feb 2023 18:07:13 +0000 Subject: [PATCH] Use psa_generate_random() instead of mbedtls_ctr_dbrg Signed-off-by: Aditya Deshpande --- 3rdparty/p256-m/p256-m/p256-m.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/3rdparty/p256-m/p256-m/p256-m.c b/3rdparty/p256-m/p256-m/p256-m.c index 9e23a2de8f..0360ea2470 100644 --- a/3rdparty/p256-m/p256-m/p256-m.c +++ b/3rdparty/p256-m/p256-m/p256-m.c @@ -6,8 +6,7 @@ */ #include "p256-m.h" -#include "mbedtls/entropy.h" -#include "mbedtls/ctr_drbg.h" +#include "psa/crypto.h" #include #include #include @@ -1158,31 +1157,13 @@ static int scalar_from_bytes(uint32_t s[8], const uint8_t p[32]) */ int p256_generate_random(uint8_t *output, unsigned output_size) { -#if defined(MBEDTLS_CTR_DRBG_C) - mbedtls_entropy_context entropy; - mbedtls_ctr_drbg_context ctr_drbg; - char *personalization = "p256m"; - mbedtls_entropy_init(&entropy); - mbedtls_ctr_drbg_init(&ctr_drbg); int ret; + ret = psa_generate_random(output, output_size); - ret = mbedtls_ctr_drbg_seed(&ctr_drbg , mbedtls_entropy_func, &entropy, - (const unsigned char *) personalization, - strlen(personalization)); - if (ret != 0) { - goto exit; + if (ret != 0){ + return P256_RANDOM_FAILED; } - - ret = mbedtls_ctr_drbg_random(&ctr_drbg, output, output_size); - if (ret != 0) { - goto exit; - } - return P256_SUCCESS; -#endif - -exit: - return P256_RANDOM_FAILED; } /*