diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index 47c0dc9bb6a..de6dfbe0d26 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -419,9 +419,19 @@ Ref CryptoMbedTLS::generate_self_signed_certificate(Ref 0) { + int to_read = MIN(left, MBEDTLS_CTR_DRBG_MAX_REQUEST); + int ret = mbedtls_ctr_drbg_random(&ctr_drbg, out.ptrw() + pos, to_read); + ERR_FAIL_COND_V_MSG(ret != 0, PackedByteArray(), vformat("Failed to generate %d random bytes(s). Error: %d.", p_bytes, ret)); + left -= to_read; + pos += to_read; + } return out; }