diff options
author | Kim Alvefur <zash@zash.se> | 2017-02-25 17:57:22 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-02-25 17:57:22 +0100 |
commit | 0b7b8b674bcfd32d3b683146bceefa35db9d1fb2 (patch) | |
tree | 6f1d36e95d5835c1125bd03f557df69104bd273f /util-src/crand.c | |
parent | c99a49ae0284e06e194d680553942156498a41bd (diff) | |
download | prosody-0b7b8b674bcfd32d3b683146bceefa35db9d1fb2.tar.gz prosody-0b7b8b674bcfd32d3b683146bceefa35db9d1fb2.zip |
util.crand: Throw error if OpenSSLs RNG is not seeded
Diffstat (limited to 'util-src/crand.c')
-rw-r--r-- | util-src/crand.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/util-src/crand.c b/util-src/crand.c index cc2047eb..e7caf683 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -67,6 +67,11 @@ int Lrandom(lua_State *L) { 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 @@ int luaopen_util_crand(lua_State *L) { #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 @@ int luaopen_util_crand(lua_State *L) { #endif lua_setfield(L, -2, "_source"); -#if defined(WITH_OPENSSL) && defined(_WIN32) - /* TODO Do we need to seed this on Windows? */ -#endif - return 1; } |