Software /
code /
prosody
Annotate
util-src/crand.c @ 8238:1339d7ed54d5
Makefile: Update `make test` to use the "busted" test runner
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 16 Sep 2017 03:46:55 -0400 |
parent | 8127:3e443d6791e6 |
child | 8422:6eecf82ccd8e |
rev | line source |
---|---|
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 /* Prosody IM |
7829
1fb477d19fdd
util.crand: Update copyright header
Kim Alvefur <zash@zash.se>
parents:
7826
diff
changeset
|
2 -- Copyright (C) 2008-2017 Matthew Wild |
1fb477d19fdd
util.crand: Update copyright header
Kim Alvefur <zash@zash.se>
parents:
7826
diff
changeset
|
3 -- Copyright (C) 2008-2017 Waqas Hussain |
1fb477d19fdd
util.crand: Update copyright header
Kim Alvefur <zash@zash.se>
parents:
7826
diff
changeset
|
4 -- Copyright (C) 2016-2017 Kim Alvefur |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 -- |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 */ |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 /* |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 * crand.c |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 * C PRNG interface |
7830
b9910a507250
util.crand: Add comment describing purpose of module
Kim Alvefur <zash@zash.se>
parents:
7829
diff
changeset
|
14 * |
b9910a507250
util.crand: Add comment describing purpose of module
Kim Alvefur <zash@zash.se>
parents:
7829
diff
changeset
|
15 * The purpose of this module is to provide access to a PRNG in |
b9910a507250
util.crand: Add comment describing purpose of module
Kim Alvefur <zash@zash.se>
parents:
7829
diff
changeset
|
16 * environments without /dev/urandom |
b9910a507250
util.crand: Add comment describing purpose of module
Kim Alvefur <zash@zash.se>
parents:
7829
diff
changeset
|
17 * |
b9910a507250
util.crand: Add comment describing purpose of module
Kim Alvefur <zash@zash.se>
parents:
7829
diff
changeset
|
18 * Caution! This has not been extensively tested. |
b9910a507250
util.crand: Add comment describing purpose of module
Kim Alvefur <zash@zash.se>
parents:
7829
diff
changeset
|
19 * |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 */ |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
7931
b619b85e01aa
util.pposix, configure: Move _GNU_SOURCE macro into source files
Kim Alvefur <zash@zash.se>
parents:
7918
diff
changeset
|
22 #define _DEFAULT_SOURCE |
b619b85e01aa
util.pposix, configure: Move _GNU_SOURCE macro into source files
Kim Alvefur <zash@zash.se>
parents:
7918
diff
changeset
|
23 |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 #include "lualib.h" |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 #include "lauxlib.h" |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 #include <string.h> |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 #include <errno.h> |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 #if defined(WITH_GETRANDOM) |
7934
485b9e66fedf
util.crand: Only include getrandom shiv with glibc older than 2.25
Kim Alvefur <zash@zash.se>
parents:
7933
diff
changeset
|
31 |
8127
3e443d6791e6
util.crand: Build with musl/non-glibc (can't have undefined argument-taking macros?)
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
32 #ifndef __GLIBC_PREREQ |
3e443d6791e6
util.crand: Build with musl/non-glibc (can't have undefined argument-taking macros?)
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
33 #define __GLIBC_PREREQ(a,b) 0 |
3e443d6791e6
util.crand: Build with musl/non-glibc (can't have undefined argument-taking macros?)
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
34 #endif |
3e443d6791e6
util.crand: Build with musl/non-glibc (can't have undefined argument-taking macros?)
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
35 |
7934
485b9e66fedf
util.crand: Only include getrandom shiv with glibc older than 2.25
Kim Alvefur <zash@zash.se>
parents:
7933
diff
changeset
|
36 #if ! __GLIBC_PREREQ(2,25) |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 #include <unistd.h> |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 #include <sys/syscall.h> |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 #ifndef SYS_getrandom |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 #error getrandom() requires Linux 3.17 or later |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 #endif |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 |
7934
485b9e66fedf
util.crand: Only include getrandom shiv with glibc older than 2.25
Kim Alvefur <zash@zash.se>
parents:
7933
diff
changeset
|
44 /* This wasn't present before glibc 2.25 */ |
7933
c91ec7689424
util.crand: Change argumen names to match some man page
Kim Alvefur <zash@zash.se>
parents:
7932
diff
changeset
|
45 int getrandom(void *buf, size_t buflen, unsigned int flags) { |
c91ec7689424
util.crand: Change argumen names to match some man page
Kim Alvefur <zash@zash.se>
parents:
7932
diff
changeset
|
46 return syscall(SYS_getrandom, buf, buflen, flags); |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 } |
7934
485b9e66fedf
util.crand: Only include getrandom shiv with glibc older than 2.25
Kim Alvefur <zash@zash.se>
parents:
7933
diff
changeset
|
48 #else |
485b9e66fedf
util.crand: Only include getrandom shiv with glibc older than 2.25
Kim Alvefur <zash@zash.se>
parents:
7933
diff
changeset
|
49 #include <sys/random.h> |
485b9e66fedf
util.crand: Only include getrandom shiv with glibc older than 2.25
Kim Alvefur <zash@zash.se>
parents:
7933
diff
changeset
|
50 #endif |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 #elif defined(WITH_ARC4RANDOM) |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 #include <stdlib.h> |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 #elif defined(WITH_OPENSSL) |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 #include <openssl/rand.h> |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 #else |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 #error util.crand compiled without a random source |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 #endif |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 int Lrandom(lua_State *L) { |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 int ret = 0; |
7823
9b66ada1487c
util.crand: Switch to luaL_checkinteger since checkint is deprecated in Lua 5.3
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
62 size_t len = (size_t)luaL_checkinteger(L, 1); |
7824
56552733742e
util.crand: Let Lua handle allocation, freeing and error handling for buffer
Kim Alvefur <zash@zash.se>
parents:
7823
diff
changeset
|
63 void *buf = lua_newuserdata(L, len); |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 #if defined(WITH_GETRANDOM) |
7932 | 66 /* |
67 * This acts like a read from /dev/urandom with the exception that it | |
68 * *does* block if the entropy pool is not yet initialized. | |
69 */ | |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 ret = getrandom(buf, len, 0); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 if(ret < 0) { |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 lua_pushstring(L, strerror(errno)); |
7826 | 74 return lua_error(L); |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 } |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 #elif defined(WITH_ARC4RANDOM) |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 arc4random_buf(buf, len); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 ret = len; |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 #elif defined(WITH_OPENSSL) |
7915
e3d3ebd417f4
util.crand: Throw error if OpenSSLs RNG is not seeded
Kim Alvefur <zash@zash.se>
parents:
7832
diff
changeset
|
81 if(!RAND_status()) { |
e3d3ebd417f4
util.crand: Throw error if OpenSSLs RNG is not seeded
Kim Alvefur <zash@zash.se>
parents:
7832
diff
changeset
|
82 lua_pushliteral(L, "OpenSSL PRNG not seeded"); |
7918
12e5a54907b6
util.crand: Clarify that lua_error does not return
Kim Alvefur <zash@zash.se>
parents:
7915
diff
changeset
|
83 return lua_error(L); |
7915
e3d3ebd417f4
util.crand: Throw error if OpenSSLs RNG is not seeded
Kim Alvefur <zash@zash.se>
parents:
7832
diff
changeset
|
84 } |
e3d3ebd417f4
util.crand: Throw error if OpenSSLs RNG is not seeded
Kim Alvefur <zash@zash.se>
parents:
7832
diff
changeset
|
85 |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 ret = RAND_bytes(buf, len); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 if(ret == 1) { |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 ret = len; |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 } else { |
7832 | 91 /* TODO ERR_get_error() */ |
7826 | 92 lua_pushstring(L, "RAND_bytes() failed"); |
93 return lua_error(L); | |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 } |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 #endif |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 |
7824
56552733742e
util.crand: Let Lua handle allocation, freeing and error handling for buffer
Kim Alvefur <zash@zash.se>
parents:
7823
diff
changeset
|
98 lua_pushlstring(L, buf, ret); |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 return 1; |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 } |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 int luaopen_util_crand(lua_State *L) { |
7818
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
7439
diff
changeset
|
103 #if (LUA_VERSION_NUM > 501) |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
7439
diff
changeset
|
104 luaL_checkversion(L); |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
7439
diff
changeset
|
105 #endif |
7915
e3d3ebd417f4
util.crand: Throw error if OpenSSLs RNG is not seeded
Kim Alvefur <zash@zash.se>
parents:
7832
diff
changeset
|
106 |
7969
1c6a07606309
util-src: Specify size of various tables to be allocated
Kim Alvefur <zash@zash.se>
parents:
7934
diff
changeset
|
107 lua_createtable(L, 0, 2); |
7187
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 lua_pushcfunction(L, Lrandom); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 lua_setfield(L, -2, "bytes"); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 #if defined(WITH_GETRANDOM) |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 lua_pushstring(L, "Linux"); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 #elif defined(WITH_ARC4RANDOM) |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 lua_pushstring(L, "arc4random()"); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 #elif defined(WITH_OPENSSL) |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 lua_pushstring(L, "OpenSSL"); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 #endif |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 lua_setfield(L, -2, "_source"); |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 return 1; |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 } |
3d2c2f0809ee
util.crand: C binding to one of OpenSSL, Linux getrandom() or OpenBSD arc4random() CSPRNG
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 |