Add optional SCTP_USE_OPENSSL_RAND define to use openssll's RNG.
openssl's random number generation code is more robust, and in the case
of building with chromium, is able to bypass sandbox restrictions that
prevent opening /dev/urandom.
@@ -85,6 +85,36 @@ read_random(void *buf, size_t size)
return;
}
+void
+finish_random(void)
+{
+ return;
+}
+/* This define can be used to optionally use OpenSSL's random number utility,
+ * which is capable of bypassing the chromium sandbox which normally would
+ * prevent opening files, including /dev/urandom.
+ */
+#elif defined(SCTP_USE_OPENSSL_RAND)
+#include <openssl/rand.h>
+
+/* Requiring BoringSSL because it guarantees that RAND_bytes will succeed. */
+#ifndef OPENSSL_IS_BORINGSSL
+#error Only BoringSSL is supported with SCTP_USE_OPENSSL_RAND.
+#endif
+
+void
+init_random(void)
+{
+ return;
+}
+
+void
+read_random(void *buf, size_t size)
+{
+ RAND_bytes((uint8_t *)buf, size);
+ return;
+}
+
void
finish_random(void)
{
