From: <lab...@us...> - 2018-12-14 11:19:50
|
Revision: 1570 http://sourceforge.net/p/opengtoolkit/svn/1570 Author: labviewer Date: 2018-12-14 11:19:48 +0000 (Fri, 14 Dec 2018) Log Message: ----------- Add fallback on Linux for when libbsd is not installed Modified Paths: -------------- trunk/lvzip/c_source/README trunk/lvzip/c_source/crypt.c Modified: trunk/lvzip/c_source/README =================================================================== --- trunk/lvzip/c_source/README 2018-12-13 11:34:58 UTC (rev 1569) +++ trunk/lvzip/c_source/README 2018-12-14 11:19:48 UTC (rev 1570) @@ -1,6 +1,6 @@ ZLIB DATA COMPRESSION LIBRARY -zlib 1.2.8 is a general purpose data compression library. All the code is +zlib 1.2.11 is a general purpose data compression library. All the code is thread safe. The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and @@ -84,7 +84,7 @@ Copyright notice: - (C) 1995-2013 Jean-loup Gailly and Mark Adler + (C) 1995-2017 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages Modified: trunk/lvzip/c_source/crypt.c =================================================================== --- trunk/lvzip/c_source/crypt.c 2018-12-13 11:34:58 UTC (rev 1569) +++ trunk/lvzip/c_source/crypt.c 2018-12-14 11:19:48 UTC (rev 1570) @@ -38,6 +38,7 @@ # include <sys/stat.h> # include <fcntl.h> # include <unistd.h> +# include <dlfcn.h> #endif #include "zlib.h" @@ -85,8 +86,13 @@ } /***************************************************************************/ - #ifndef NOCRYPT +#if Unix +#ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +#endif +typedef void (*arc4random_func)(void *, unsigned int); +#endif unsigned int cryptrand(unsigned char *buf, unsigned int len) { #ifdef _WIN32 @@ -108,8 +114,46 @@ } #elif VxWorks return read_random(buf, len); -#else - arc4random_buf(buf, len); +#else // Unix + int frand; + unsigned int rlen; + static calls = 0; + static void *lib = NULL; + if (!lib) + lib = dlopen("libbsd.so", RTLD_LOCAL); + if (lib) + { + static arc4random_func func = NULL; + if (!func) + { + dlerror(); /* Clear any existing error */ + *(void**)(&func) = dlsym(lib, "arc4random"); + if (!func || dlerror()) + { + func = NULL; + } + } + if (func) + { + (*func)(buf, len); + return len; + } + } + /* arc4random could not be found */ + frand = open("/dev/urandom", O_RDONLY); + if (frand != -1) + { + rlen = (unsigned int)read(frand, buf, len); + close(frand); + } + if (rlen < len) + { + /* Ensure different random header each time */ + if (++calls == 1) + srand((unsigned int)(time(NULL) ^ ZCR_SEED2)); + while (rlen < len) + buf[rlen++] = (unsigned char)(rand() >> 7) & 0xff; + } #endif return len; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |