From fa9e319eab3d1a379db437239e28f2553af5b1b4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 23 Mar 2016 12:19:19 +0000 Subject: unified project for libevent git-svn-id: http://svn.miranda-ng.org/main/trunk@16525 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- libs/libevent/include/event2/event-config.h | 2 +- libs/libevent/libevent.vcxproj | 42 +++ libs/libevent/libevent.vcxproj.filters | 4 + libs/libevent/libevent_12.vcxproj | 212 ----------- libs/libevent/libevent_12.vcxproj.filters | 264 ------------- libs/libevent/src/arc4random.c | 556 ---------------------------- libs/libevent/src/arc4random.cxx | 556 ++++++++++++++++++++++++++++ libs/libevent/src/evutil_rand.c | 2 +- libs/libevent/src/stdafx.cxx | 2 + libs/libevent/src/stdafx.h | 2 + 10 files changed, 608 insertions(+), 1034 deletions(-) create mode 100644 libs/libevent/libevent.vcxproj create mode 100644 libs/libevent/libevent.vcxproj.filters delete mode 100644 libs/libevent/libevent_12.vcxproj delete mode 100644 libs/libevent/libevent_12.vcxproj.filters delete mode 100644 libs/libevent/src/arc4random.c create mode 100644 libs/libevent/src/arc4random.cxx create mode 100644 libs/libevent/src/stdafx.cxx create mode 100644 libs/libevent/src/stdafx.h (limited to 'libs') diff --git a/libs/libevent/include/event2/event-config.h b/libs/libevent/include/event2/event-config.h index 395396efa3..6fa812f3ed 100644 --- a/libs/libevent/include/event2/event-config.h +++ b/libs/libevent/include/event2/event-config.h @@ -290,7 +290,7 @@ /* #undef EVENT__HAVE_STRTOK_R */ /* Define to 1 if you have the `strtoll' function. */ -#define EVENT__HAVE_STRTOLL +/* #define EVENT__HAVE_STRTOLL */ /* Define to 1 if the system has the type `struct addrinfo'. */ #define EVENT__HAVE_STRUCT_ADDRINFO diff --git a/libs/libevent/libevent.vcxproj b/libs/libevent/libevent.vcxproj new file mode 100644 index 0000000000..87da0181b8 --- /dev/null +++ b/libs/libevent/libevent.vcxproj @@ -0,0 +1,42 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {46D53888-E60E-32A7-91EB-6336DE0D84D8} + libevent + + + + + + + .\include;.\src\compat;%(AdditionalIncludeDirectories) + HAVE_CONFIG_H;%(PreprocessorDefinitions) + + + ws2_32.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies) + + + + + NotUsing + + + \ No newline at end of file diff --git a/libs/libevent/libevent.vcxproj.filters b/libs/libevent/libevent.vcxproj.filters new file mode 100644 index 0000000000..de5ad9f66c --- /dev/null +++ b/libs/libevent/libevent.vcxproj.filters @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/libs/libevent/libevent_12.vcxproj b/libs/libevent/libevent_12.vcxproj deleted file mode 100644 index 11876a5aa9..0000000000 --- a/libs/libevent/libevent_12.vcxproj +++ /dev/null @@ -1,212 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {46D53888-E60E-32A7-91EB-6336DE0D84D8} - libevent - - - - v120_xp - DynamicLibrary - - - DynamicLibrary - v120_xp - - - DynamicLibrary - v120_xp - - - DynamicLibrary - v120_xp - - - - - - - - - - <_ProjectFileVersion>10.0.40219.1 - $(SolutionDir)\$(Configuration)\Libs\ - $(SolutionDir)\$(Configuration)64\Libs\ - $(SolutionDir)\$(Configuration)\Obj\$(ProjectName)\ - $(SolutionDir)\$(Configuration)64\Obj\$(ProjectName)\ - $(SolutionDir)\$(Configuration)\Libs\ - $(SolutionDir)\$(Configuration)64\Libs\ - $(SolutionDir)\$(Configuration)\Obj\$(ProjectName)\ - $(SolutionDir)\$(Configuration)64\Obj\$(ProjectName)\ - true - - - .mir - - - - include;src\compat;..\..\include;%(AdditionalIncludeDirectories) - Disabled - Level3 - _WINDOWS;_DEBUG;HAVE_CONFIG_H;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - - - ws2_32.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies) - ..\win32 - true - Windows - - - - - include;src\compat;..\..\include;%(AdditionalIncludeDirectories) - Full - Level3 - _WINDOWS;NDEBUG;HAVE_CONFIG_H;%(PreprocessorDefinitions) - - - ws2_32.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies) - ..\win32 - true - Windows - true - true - UseLinkTimeCodeGeneration - - - - - include;src\compat;..\..\include;%(AdditionalIncludeDirectories) - Disabled - Level3 - _WINDOWS;_DEBUG;HAVE_CONFIG_H;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - - - ws2_32.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies) - ..\win64 - true - Windows - - - - - include;src\compat;..\..\include;%(AdditionalIncludeDirectories) - Full - Level3 - _WINDOWS;NDEBUG;HAVE_CONFIG_H;%(PreprocessorDefinitions) - - - ws2_32.lib;libeay32.lib;ssleay32.lib;%(AdditionalDependencies) - ..\win64 - true - Windows - true - true - UseLinkTimeCodeGeneration - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libs/libevent/libevent_12.vcxproj.filters b/libs/libevent/libevent_12.vcxproj.filters deleted file mode 100644 index 52a3297f3a..0000000000 --- a/libs/libevent/libevent_12.vcxproj.filters +++ /dev/null @@ -1,264 +0,0 @@ - - - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Core - - - Source Extra - - - Source Extra - - - Source Extra - - - Source Extra - - - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Headers Private - - - Header Compat - - - Header Compat - - - Header Compat - - - Header Compat - - - Header Compat - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - Headers Public - - - - - {918036C9-880E-383E-A0A0-E2F1133C4BF0} - - - {403FD3F2-243C-3501-846D-EC6DB43B0865} - - - {6259BD7B-787D-3652-9A11-0698644E1128} - - - {D8BDFFA3-4BC2-3E42-BC8E-450D2147C8CA} - - - {70C5E5A7-1F69-39E0-8BF9-5F35EFB07481} - - - {D7733A27-70AE-358A-911E-F7687E9FECFF} - - - diff --git a/libs/libevent/src/arc4random.c b/libs/libevent/src/arc4random.c deleted file mode 100644 index a2338e692a..0000000000 --- a/libs/libevent/src/arc4random.c +++ /dev/null @@ -1,556 +0,0 @@ -/* Portable arc4random.c based on arc4random.c from OpenBSD. - * Portable version by Chris Davis, adapted for Libevent by Nick Mathewson - * Copyright (c) 2010 Chris Davis, Niels Provos, and Nick Mathewson - * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson - * - * Note that in Libevent, this file isn't compiled directly. Instead, - * it's included from evutil_rand.c - */ - -/* - * Copyright (c) 1996, David Mazieres - * Copyright (c) 2008, Damien Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Arc4 random number generator for OpenBSD. - * - * This code is derived from section 17.1 of Applied Cryptography, - * second edition, which describes a stream cipher allegedly - * compatible with RSA Labs "RC4" cipher (the actual description of - * which is a trade secret). The same algorithm is used as a stream - * cipher called "arcfour" in Tatu Ylonen's ssh package. - * - * Here the stream cipher has been modified always to include the time - * when initializing the state. That makes it impossible to - * regenerate the same random sequence twice, so this can't be used - * for encryption, but will generate good random numbers. - * - * RC4 is a registered trademark of RSA Laboratories. - */ - -#ifndef ARC4RANDOM_EXPORT -#define ARC4RANDOM_EXPORT -#endif - -#ifndef ARC4RANDOM_UINT32 -#define ARC4RANDOM_UINT32 uint32_t -#endif - -#ifndef ARC4RANDOM_NO_INCLUDES -#include "evconfig-private.h" -#ifdef _WIN32 -#include -#include -#else -#include -#include -#include -#include -#ifdef EVENT__HAVE_SYS_SYSCTL_H -#include -#endif -#endif -#include -#include -#include -#endif - -/* Add platform entropy 32 bytes (256 bits) at a time. */ -#define ADD_ENTROPY 32 - -/* Re-seed from the platform RNG after generating this many bytes. */ -#define BYTES_BEFORE_RESEED 1600000 - -struct arc4_stream { - unsigned char i; - unsigned char j; - unsigned char s[256]; -}; - -#ifdef _WIN32 -#define getpid _getpid -#define pid_t int -#endif - -static int rs_initialized; -static struct arc4_stream rs; -static pid_t arc4_stir_pid; -static int arc4_count; -static int arc4_seeded_ok; - -static inline unsigned char arc4_getbyte(void); - -static inline void -arc4_init(void) -{ - int n; - - for (n = 0; n < 256; n++) - rs.s[n] = n; - rs.i = 0; - rs.j = 0; -} - -static inline void -arc4_addrandom(const unsigned char *dat, int datlen) -{ - int n; - unsigned char si; - - rs.i--; - for (n = 0; n < 256; n++) { - rs.i = (rs.i + 1); - si = rs.s[rs.i]; - rs.j = (rs.j + si + dat[n % datlen]); - rs.s[rs.i] = rs.s[rs.j]; - rs.s[rs.j] = si; - } - rs.j = rs.i; -} - -#ifndef _WIN32 -static ssize_t -read_all(int fd, unsigned char *buf, size_t count) -{ - size_t numread = 0; - ssize_t result; - - while (numread < count) { - result = read(fd, buf+numread, count-numread); - if (result<0) - return -1; - else if (result == 0) - break; - numread += result; - } - - return (ssize_t)numread; -} -#endif - -#ifdef _WIN32 -#define TRY_SEED_WIN32 -static int -arc4_seed_win32(void) -{ - /* This is adapted from Tor's crypto_seed_rng() */ - static int provider_set = 0; - static HCRYPTPROV provider; - unsigned char buf[ADD_ENTROPY]; - - if (!provider_set) { - if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, - CRYPT_VERIFYCONTEXT)) { - if (GetLastError() != (DWORD)NTE_BAD_KEYSET) - return -1; - } - provider_set = 1; - } - if (!CryptGenRandom(provider, sizeof(buf), buf)) - return -1; - arc4_addrandom(buf, sizeof(buf)); - evutil_memclear_(buf, sizeof(buf)); - arc4_seeded_ok = 1; - return 0; -} -#endif - -#if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL) -#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_RANDOM && EVENT__HAVE_DECL_RANDOM_UUID -#define TRY_SEED_SYSCTL_LINUX -static int -arc4_seed_sysctl_linux(void) -{ - /* Based on code by William Ahern, this function tries to use the - * RANDOM_UUID sysctl to get entropy from the kernel. This can work - * even if /dev/urandom is inaccessible for some reason (e.g., we're - * running in a chroot). */ - int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID }; - unsigned char buf[ADD_ENTROPY]; - size_t len, n; - unsigned i; - int any_set; - - memset(buf, 0, sizeof(buf)); - - for (len = 0; len < sizeof(buf); len += n) { - n = sizeof(buf) - len; - - if (0 != sysctl(mib, 3, &buf[len], &n, NULL, 0)) - return -1; - } - /* make sure that the buffer actually got set. */ - for (i=0,any_set=0; i sizeof(buf)) - n = len - sizeof(buf); - if (sysctl(mib, 2, &buf[len], &n, NULL, 0) == -1) - return -1; - } - } - /* make sure that the buffer actually got set. */ - for (i=any_set=0; i 0xffffffffUL) - min = 0x100000000UL % upper_bound; -#else - /* Calculate (2**32 % upper_bound) avoiding 64-bit math */ - if (upper_bound > 0x80000000) - min = 1 + ~upper_bound; /* 2**32 - upper_bound */ - else { - /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ - min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; - } -#endif - - /* - * This could theoretically loop forever but each retry has - * p > 0.5 (worst case, usually far better) of selecting a - * number inside the range we need, so it should rarely need - * to re-roll. - */ - for (;;) { - r = arc4random(); - if (r >= min) - break; - } - - return r % upper_bound; -} -#endif diff --git a/libs/libevent/src/arc4random.cxx b/libs/libevent/src/arc4random.cxx new file mode 100644 index 0000000000..40d6642e58 --- /dev/null +++ b/libs/libevent/src/arc4random.cxx @@ -0,0 +1,556 @@ +/* Portable arc4random.c based on arc4random.c from OpenBSD. + * Portable version by Chris Davis, adapted for Libevent by Nick Mathewson + * Copyright (c) 2010 Chris Davis, Niels Provos, and Nick Mathewson + * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson + * + * Note that in Libevent, this file isn't compiled directly. Instead, + * it's included from evutil_rand.c + */ + +/* + * Copyright (c) 1996, David Mazieres + * Copyright (c) 2008, Damien Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Arc4 random number generator for OpenBSD. + * + * This code is derived from section 17.1 of Applied Cryptography, + * second edition, which describes a stream cipher allegedly + * compatible with RSA Labs "RC4" cipher (the actual description of + * which is a trade secret). The same algorithm is used as a stream + * cipher called "arcfour" in Tatu Ylonen's ssh package. + * + * Here the stream cipher has been modified always to include the time + * when initializing the state. That makes it impossible to + * regenerate the same random sequence twice, so this can't be used + * for encryption, but will generate good random numbers. + * + * RC4 is a registered trademark of RSA Laboratories. + */ + +#ifndef ARC4RANDOM_EXPORT +#define ARC4RANDOM_EXPORT +#endif + +#ifndef ARC4RANDOM_UINT32 +#define ARC4RANDOM_UINT32 uint32_t +#endif + +#ifndef ARC4RANDOM_NO_INCLUDES +#include "evconfig-private.h" +#ifdef _WIN32 +#include +#include +#include +#include +#else +#include +#include +#include +#include +#ifdef EVENT__HAVE_SYS_SYSCTL_H +#include +#endif +#endif +#include +#include +#include +#endif + +/* Add platform entropy 32 bytes (256 bits) at a time. */ +#define ADD_ENTROPY 32 + +/* Re-seed from the platform RNG after generating this many bytes. */ +#define BYTES_BEFORE_RESEED 1600000 + +struct arc4_stream { + unsigned char i; + unsigned char j; + unsigned char s[256]; +}; + +#ifdef _WIN32 +#define getpid _getpid +#define pid_t int +#endif + +static int rs_initialized; +static struct arc4_stream rs; +static pid_t arc4_stir_pid; +static int arc4_count; +static int arc4_seeded_ok; + +static unsigned char arc4_getbyte(void); + +static void arc4_init(void) +{ + int n; + + for (n = 0; n < 256; n++) + rs.s[n] = n; + rs.i = 0; + rs.j = 0; +} + +static void arc4_addrandom(const unsigned char *dat, int datlen) +{ + int n; + unsigned char si; + + rs.i--; + for (n = 0; n < 256; n++) { + rs.i = (rs.i + 1); + si = rs.s[rs.i]; + rs.j = (rs.j + si + dat[n % datlen]); + rs.s[rs.i] = rs.s[rs.j]; + rs.s[rs.j] = si; + } + rs.j = rs.i; +} + +#ifndef _WIN32 +static ssize_t +read_all(int fd, unsigned char *buf, size_t count) +{ + size_t numread = 0; + ssize_t result; + + while (numread < count) { + result = read(fd, buf+numread, count-numread); + if (result<0) + return -1; + else if (result == 0) + break; + numread += result; + } + + return (ssize_t)numread; +} +#endif + +#ifdef _WIN32 +#define TRY_SEED_WIN32 +static int +arc4_seed_win32(void) +{ + /* This is adapted from Tor's crypto_seed_rng() */ + static int provider_set = 0; + static HCRYPTPROV provider; + unsigned char buf[ADD_ENTROPY]; + + if (!provider_set) { + if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) { + if (GetLastError() != (DWORD)NTE_BAD_KEYSET) + return -1; + } + provider_set = 1; + } + if (!CryptGenRandom(provider, sizeof(buf), buf)) + return -1; + arc4_addrandom(buf, sizeof(buf)); + evutil_memclear_(buf, sizeof(buf)); + arc4_seeded_ok = 1; + return 0; +} +#endif + +#if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL) +#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_RANDOM && EVENT__HAVE_DECL_RANDOM_UUID +#define TRY_SEED_SYSCTL_LINUX +static int +arc4_seed_sysctl_linux(void) +{ + /* Based on code by William Ahern, this function tries to use the + * RANDOM_UUID sysctl to get entropy from the kernel. This can work + * even if /dev/urandom is inaccessible for some reason (e.g., we're + * running in a chroot). */ + int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID }; + unsigned char buf[ADD_ENTROPY]; + size_t len, n; + unsigned i; + int any_set; + + memset(buf, 0, sizeof(buf)); + + for (len = 0; len < sizeof(buf); len += n) { + n = sizeof(buf) - len; + + if (0 != sysctl(mib, 3, &buf[len], &n, NULL, 0)) + return -1; + } + /* make sure that the buffer actually got set. */ + for (i=0,any_set=0; i sizeof(buf)) + n = len - sizeof(buf); + if (sysctl(mib, 2, &buf[len], &n, NULL, 0) == -1) + return -1; + } + } + /* make sure that the buffer actually got set. */ + for (i=any_set=0; i 0xffffffffUL) + min = 0x100000000UL % upper_bound; +#else + /* Calculate (2**32 % upper_bound) avoiding 64-bit math */ + if (upper_bound > 0x80000000) + min = 1 + ~upper_bound; /* 2**32 - upper_bound */ + else { + /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ + min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; + } +#endif + + /* + * This could theoretically loop forever but each retry has + * p > 0.5 (worst case, usually far better) of selecting a + * number inside the range we need, so it should rarely need + * to re-roll. + */ + for (;;) { + r = arc4random(); + if (r >= min) + break; + } + + return r % upper_bound; +} +#endif diff --git a/libs/libevent/src/evutil_rand.c b/libs/libevent/src/evutil_rand.c index 046a14b07a..0402772db3 100644 --- a/libs/libevent/src/evutil_rand.c +++ b/libs/libevent/src/evutil_rand.c @@ -131,7 +131,7 @@ static void *arc4rand_lock; #define ARC4RANDOM_NORANDOM #define ARC4RANDOM_NOUNIFORM -#include "./arc4random.c" +#include "./arc4random.cxx" #ifndef EVENT__DISABLE_THREAD_SUPPORT int diff --git a/libs/libevent/src/stdafx.cxx b/libs/libevent/src/stdafx.cxx new file mode 100644 index 0000000000..0fb604da7c --- /dev/null +++ b/libs/libevent/src/stdafx.cxx @@ -0,0 +1,2 @@ + +#include "stdafx.h" \ No newline at end of file diff --git a/libs/libevent/src/stdafx.h b/libs/libevent/src/stdafx.h new file mode 100644 index 0000000000..d78b7834c8 --- /dev/null +++ b/libs/libevent/src/stdafx.h @@ -0,0 +1,2 @@ + +// just a stub \ No newline at end of file -- cgit v1.2.3