mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 18:49:03 -04:00
Use arc4random_buf() instead of random() when available.
This commit is contained in:
parent
b7716ed577
commit
ec6bdd1ae9
1
configure
vendored
1
configure
vendored
@ -159,6 +159,7 @@ unless ($config{CXX}) {
|
|||||||
}
|
}
|
||||||
my %compiler = get_compiler_info($config{CXX});
|
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_CLOCK_GETTIME} = run_test 'clock_gettime()', test_file($config{CXX}, 'clock_gettime.cpp', $^O eq 'darwin' ? undef : '-lrt');
|
||||||
$config{HAS_EVENTFD} = run_test 'eventfd()', test_file($config{CXX}, 'eventfd.cpp');
|
$config{HAS_EVENTFD} = run_test 'eventfd()', test_file($config{CXX}, 'eventfd.cpp');
|
||||||
|
|
||||||
|
26
make/test/arc4random_buf.cpp
Normal file
26
make/test/arc4random_buf.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* InspIRCd -- Internet Relay Chat Daemon
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Peter Powell <petpow@saberuk.com>
|
||||||
|
*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
char buffer[100];
|
||||||
|
arc4random_buf(buffer, sizeof(buffer));
|
||||||
|
return 0;
|
||||||
|
}
|
@ -477,8 +477,11 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max)
|
|||||||
// This is overridden by a higher-quality algorithm when SSL support is loaded
|
// This is overridden by a higher-quality algorithm when SSL support is loaded
|
||||||
void InspIRCd::DefaultGenRandom(char* output, size_t max)
|
void InspIRCd::DefaultGenRandom(char* output, size_t max)
|
||||||
{
|
{
|
||||||
for(unsigned int i=0; i < max; i++)
|
#if defined HAS_ARC4RANDOM_BUF
|
||||||
#ifdef _WIN32
|
arc4random_buf(output, max);
|
||||||
|
#else
|
||||||
|
for (unsigned int i = 0; i < max; ++i)
|
||||||
|
# ifdef _WIN32
|
||||||
{
|
{
|
||||||
unsigned int uTemp;
|
unsigned int uTemp;
|
||||||
if(rand_s(&uTemp) != 0)
|
if(rand_s(&uTemp) != 0)
|
||||||
@ -486,7 +489,8 @@ void InspIRCd::DefaultGenRandom(char* output, size_t max)
|
|||||||
else
|
else
|
||||||
output[i] = uTemp;
|
output[i] = uTemp;
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
output[i] = random();
|
output[i] = random();
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user