feat(mbedtls): Add mbedtls_esp_random()

Suitable for passing as f_rng to various Mbed-TLS APIs that require it
This commit is contained in:
Deomid rojer Ryabkov
2025-03-30 00:49:08 +02:00
committed by BOT
parent ab2829d65f
commit aa581523c9
2 changed files with 36 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "esp_random.h" #include "esp_random.h"
#include "mbedtls/esp_random.h"
#include <entropy_poll.h> #include <entropy_poll.h>
@@ -23,3 +24,9 @@ int mbedtls_hardware_poll( void *data,
*olen = len; *olen = len;
return 0; return 0;
} }
int mbedtls_esp_random(void *ctx, unsigned char *buf, size_t len)
{
esp_fill_random(buf, len);
return 0;
}

View File

@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief MbedTLS-compatible RNG function
*
* @note Suitable for passing as f_rng to various Mbed-TLS APIs that require it.
*
* @param ctx User-supplied context
* @param buf Pointer to buffer to fill with random numbers.
* @param len Length of buffer in bytes
*
* @return 0 (success)
*/
int mbedtls_esp_random(void *ctx, unsigned char *buf, size_t len);
#ifdef __cplusplus
}
#endif