mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-03 02:20:57 +02:00
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:
committed by
BOT
parent
ab2829d65f
commit
aa581523c9
@@ -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;
|
||||||
|
}
|
||||||
|
29
components/mbedtls/port/include/mbedtls/esp_random.h
Normal file
29
components/mbedtls/port/include/mbedtls/esp_random.h
Normal 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
|
Reference in New Issue
Block a user