Comparison

util-src/crand.c @ 7825:1dfa5847d49e

util.crand: Remove seeding
author Kim Alvefur <zash@zash.se>
date Fri, 20 Jan 2017 11:33:31 +0100
parent 7824:56552733742e
child 7826:7702ce682427
comparison
equal deleted inserted replaced
7824:56552733742e 7825:1dfa5847d49e
75 75
76 lua_pushlstring(L, buf, ret); 76 lua_pushlstring(L, buf, ret);
77 return 1; 77 return 1;
78 } 78 }
79 79
80 #ifdef ENABLE_SEEDING
81 int Lseed(lua_State *L) {
82 size_t len;
83 const char *seed = lua_tolstring(L, 1, &len);
84
85 #if defined(WITH_OPENSSL)
86 RAND_add(seed, len, len);
87 return 0;
88 #else
89 lua_pushnil(L);
90 lua_pushliteral(L, "not-supported");
91 return 2;
92 #endif
93 }
94 #endif
95
96 int luaopen_util_crand(lua_State *L) { 80 int luaopen_util_crand(lua_State *L) {
97 #if (LUA_VERSION_NUM > 501) 81 #if (LUA_VERSION_NUM > 501)
98 luaL_checkversion(L); 82 luaL_checkversion(L);
99 #endif 83 #endif
100 lua_newtable(L); 84 lua_newtable(L);
101 lua_pushcfunction(L, Lrandom); 85 lua_pushcfunction(L, Lrandom);
102 lua_setfield(L, -2, "bytes"); 86 lua_setfield(L, -2, "bytes");
103 #ifdef ENABLE_SEEDING
104 lua_pushcfunction(L, Lseed);
105 lua_setfield(L, -2, "seed");
106 #endif
107 87
108 #if defined(WITH_GETRANDOM) 88 #if defined(WITH_GETRANDOM)
109 lua_pushstring(L, "Linux"); 89 lua_pushstring(L, "Linux");
110 #elif defined(WITH_ARC4RANDOM) 90 #elif defined(WITH_ARC4RANDOM)
111 lua_pushstring(L, "arc4random()"); 91 lua_pushstring(L, "arc4random()");