Comparison

util-src/crand.c @ 7932:6c5e4f24b51e

util.crand: Move comment block
author Kim Alvefur <zash@zash.se>
date Wed, 01 Mar 2017 22:39:01 +0100
parent 7931:b619b85e01aa
child 7933:c91ec7689424
comparison
equal deleted inserted replaced
7931:b619b85e01aa 7932:6c5e4f24b51e
34 34
35 #ifndef SYS_getrandom 35 #ifndef SYS_getrandom
36 #error getrandom() requires Linux 3.17 or later 36 #error getrandom() requires Linux 3.17 or later
37 #endif 37 #endif
38 38
39 /*
40 * This acts like a read from /dev/urandom with the exception that it
41 * *does* block if the entropy pool is not yet initialized.
42 */
43 int getrandom(void *buf, size_t len, int flags) { 39 int getrandom(void *buf, size_t len, int flags) {
44 return syscall(SYS_getrandom, buf, len, flags); 40 return syscall(SYS_getrandom, buf, len, flags);
45 } 41 }
46 42
47 #elif defined(WITH_ARC4RANDOM) 43 #elif defined(WITH_ARC4RANDOM)
56 int ret = 0; 52 int ret = 0;
57 size_t len = (size_t)luaL_checkinteger(L, 1); 53 size_t len = (size_t)luaL_checkinteger(L, 1);
58 void *buf = lua_newuserdata(L, len); 54 void *buf = lua_newuserdata(L, len);
59 55
60 #if defined(WITH_GETRANDOM) 56 #if defined(WITH_GETRANDOM)
57 /*
58 * This acts like a read from /dev/urandom with the exception that it
59 * *does* block if the entropy pool is not yet initialized.
60 */
61 ret = getrandom(buf, len, 0); 61 ret = getrandom(buf, len, 0);
62 62
63 if(ret < 0) { 63 if(ret < 0) {
64 lua_pushstring(L, strerror(errno)); 64 lua_pushstring(L, strerror(errno));
65 return lua_error(L); 65 return lua_error(L);