Changeset

7915:e3d3ebd417f4

util.crand: Throw error if OpenSSLs RNG is not seeded
author Kim Alvefur <zash@zash.se>
date Sat, 25 Feb 2017 17:57:22 +0100
parents 7914:a6eb3b6bf903
children 7917:1ea3a8dc7dd5
files util-src/crand.c
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/util-src/crand.c	Sat Feb 25 02:15:15 2017 +0100
+++ b/util-src/crand.c	Sat Feb 25 17:57:22 2017 +0100
@@ -67,6 +67,11 @@
 	arc4random_buf(buf, len);
 	ret = len;
 #elif defined(WITH_OPENSSL)
+	if(!RAND_status()) {
+		lua_pushliteral(L, "OpenSSL PRNG not seeded");
+		lua_error(L);
+	}
+
 	ret = RAND_bytes(buf, len);
 
 	if(ret == 1) {
@@ -87,6 +92,7 @@
 #if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
 #endif
+
 	lua_newtable(L);
 	lua_pushcfunction(L, Lrandom);
 	lua_setfield(L, -2, "bytes");
@@ -100,10 +106,6 @@
 #endif
 	lua_setfield(L, -2, "_source");
 
-#if defined(WITH_OPENSSL) && defined(_WIN32)
-	/* TODO Do we need to seed this on Windows? */
-#endif
-
 	return 1;
 }