mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-25 09:02:48 +00:00
entropy_poll.c: Added looping logic to mbedtls_platform_entropy_poll()
.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
This commit is contained in:
parent
7afebccf69
commit
2c6e561ff8
@ -56,7 +56,6 @@
|
|||||||
int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,
|
int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,
|
||||||
size_t *olen)
|
size_t *olen)
|
||||||
{
|
{
|
||||||
ULONG len_as_ulong = 0;
|
|
||||||
((void) data);
|
((void) data);
|
||||||
*olen = 0;
|
*olen = 0;
|
||||||
|
|
||||||
@ -65,16 +64,18 @@ int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len,
|
|||||||
* 64-bit Windows platforms. Ensure len's value can be safely converted into
|
* 64-bit Windows platforms. Ensure len's value can be safely converted into
|
||||||
* a ULONG.
|
* a ULONG.
|
||||||
*/
|
*/
|
||||||
if (FAILED(SizeTToULong(len, &len_as_ulong))) {
|
while (len != 0) {
|
||||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
unsigned long ulong_bytes =
|
||||||
}
|
(len > ULONG_MAX) ? ULONG_MAX : (unsigned long) len;
|
||||||
|
|
||||||
if (!BCRYPT_SUCCESS(BCryptGenRandom(NULL, output, len_as_ulong,
|
if (!BCRYPT_SUCCESS(BCryptGenRandom(NULL, output, ulong_bytes,
|
||||||
BCRYPT_USE_SYSTEM_PREFERRED_RNG))) {
|
BCRYPT_USE_SYSTEM_PREFERRED_RNG))) {
|
||||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
*olen = len;
|
*olen += ulong_bytes;
|
||||||
|
len -= ulong_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user