diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-09 02:22:27 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-09 02:22:27 +0000 |
commit | aab7998583ca16590a32c7bdb80955a18b090700 (patch) | |
tree | a2b7f6d82a523e683347b7489ab77f0e940bdede /include | |
parent | db790d9d1516c9c7cd48738340e5df1c8a2bebe3 (diff) |
Add random number generation functions to InspIRCd class.
Default implementation uses libc random(), which can be better than rand().
If gnutls is loaded, gcrypt will be used to provide random numbers.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12404 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include')
-rw-r--r-- | include/dns.h | 7 | ||||
-rw-r--r-- | include/inspircd.h | 16 | ||||
-rw-r--r-- | include/modules.h | 2 |
3 files changed, 17 insertions, 8 deletions
diff --git a/include/dns.h b/include/dns.h index 3d326a69c..528490015 100644 --- a/include/dns.h +++ b/include/dns.h @@ -405,13 +405,6 @@ class CoreExport DNS : public EventHandler */ ~DNS(); - /** Portable random number generator, generates - * its random number from the ircd stats counters, - * effective user id, time of day and the rollover - * counter (currid) - */ - unsigned long PRNG(); - /** * Turn an in6_addr into a .ip6.arpa domain */ diff --git a/include/inspircd.h b/include/inspircd.h index 25ba846bc..b4fd12026 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -234,6 +234,7 @@ class serverstats }; DEFINE_HANDLER2(IsNickHandler, bool, const char*, size_t); +DEFINE_HANDLER2(GenRandomHandler, void, char*, size_t); DEFINE_HANDLER1(IsIdentHandler, bool, const char*); DEFINE_HANDLER1(FloodQuitUserHandler, void, User*); DEFINE_HANDLER2(IsChannelHandler, bool, const char*, size_t); @@ -310,6 +311,7 @@ class CoreExport InspIRCd IsChannelHandler HandleIsChannel; IsSIDHandler HandleIsSID; RehashHandler HandleRehash; + GenRandomHandler HandleGenRandom; /** Globally accessible fake user record. This is used to force mode changes etc across s2s, etc.. bit ugly, but.. better than how this was done in 1.1 * Reason for it: @@ -449,6 +451,20 @@ class CoreExport InspIRCd /** Update the current time. Don't call this unless you have reason to do so. */ void UpdateTime(); + /** Generate a random string with the given length + * @param length The length in bytes + * @param printable if false, the string will use characters 0-255; otherwise, + * it will be limited to 0x30-0x7E ('0'-'~', nonspace printable characters) + */ + std::string GenRandomStr(int length, bool printable = true); + /** Generate a random integer. + * This is generally more secure than rand() + */ + unsigned long GenRandomInt(unsigned long max); + + /** Fill a buffer with random bits */ + caller2<void, char*, size_t> GenRandom; + /** Bind all ports specified in the configuration file. * @return The number of ports bound without error */ diff --git a/include/modules.h b/include/modules.h index 25c57cb61..6e8e685aa 100644 --- a/include/modules.h +++ b/include/modules.h @@ -97,7 +97,7 @@ struct ModResult { /** If you change the module API in any way, increment this value. * This MUST be a pure integer, with no parenthesis */ -#define API_VERSION 138 +#define API_VERSION 139 /** * This #define allows us to call a method in all |