mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 10:39:02 -04:00
Use getentropy() from POSIX 2024 if it is available.
This commit is contained in:
parent
c3c97b917d
commit
610688e410
1
configure
vendored
1
configure
vendored
@ -183,6 +183,7 @@ my %compiler = get_compiler_info($config{CXX});
|
||||
|
||||
$config{HAS_ARC4RANDOM_BUF} = run_test 'arc4random_buf()', test_file($config{CXX}, 'arc4random_buf.cpp');
|
||||
$config{HAS_CLOCK_GETTIME} = run_test 'clock_gettime()', test_file($config{CXX}, 'clock_gettime.cpp', $^O eq 'darwin' ? undef : '-lrt');
|
||||
$config{HAS_GETENTROPY} = run_test 'getentropy()', test_file($config{CXX}, 'getentropy.cpp');
|
||||
|
||||
my @socketengines;
|
||||
push @socketengines, 'epoll' if run_test 'epoll', test_header $config{CXX}, 'sys/epoll.h';
|
||||
|
@ -58,4 +58,7 @@
|
||||
/** Whether the clock_gettime() function was available at compile time. */
|
||||
%define HAS_CLOCK_GETTIME
|
||||
|
||||
/** Whether the getentropy() function was available at compile time. */
|
||||
%define HAS_GETENTROPY
|
||||
|
||||
#endif
|
||||
|
26
make/test/getentropy.cpp
Normal file
26
make/test/getentropy.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* InspIRCd -- Internet Relay Chat Daemon
|
||||
*
|
||||
* Copyright (C) 2024 Sadie Powell <sadie@witchery.services>
|
||||
*
|
||||
* This file is part of InspIRCd. InspIRCd is free software: you can
|
||||
* redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation, version 2.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
char buffer[100];
|
||||
getentropy(buffer, sizeof(buffer));
|
||||
return 0;
|
||||
}
|
@ -456,7 +456,11 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max) const
|
||||
// This is overridden by a higher-quality algorithm when TLS support is loaded
|
||||
void InspIRCd::DefaultGenRandom(char* output, size_t max)
|
||||
{
|
||||
#if defined HAS_ARC4RANDOM_BUF
|
||||
#ifdef HAS_GETENTROPY
|
||||
if (getentropy(output, max) == 0)
|
||||
return;
|
||||
#endif
|
||||
#ifdef HAS_ARC4RANDOM_BUF
|
||||
arc4random_buf(output, max);
|
||||
#else
|
||||
static std::random_device device;
|
||||
|
Loading…
x
Reference in New Issue
Block a user