#! /bin/sh /usr/share/dpatch/dpatch-run ## boost1.48-ftbfs.dpatch by ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' witty-3.1.10~/src/web/random_device.cpp witty-3.1.10/src/web/random_device.cpp --- witty-3.1.10~/src/web/random_device.cpp 2010-11-25 10:36:39.000000000 +0100 +++ witty-3.1.10/src/web/random_device.cpp 2012-01-12 07:48:58.000000000 +0100 @@ -1,54 +1,133 @@ /* boost random_device.cpp implementation * * Copyright Jens Maurer 2000 + * Copyright Steven Watanabe 2010-2011 * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * - * $Id: random_device.cpp,v 1.4 2008/05/14 09:34:04 kdf Exp $ + * $Id: random_device.cpp 71018 2011-04-05 21:27:52Z steven_watanabe $ * */ -#if WIN32 -// Don't link to boost_random -#define BOOST_RANDOM_NO_LIB -// And when compiling, don't add declspec to the classnames. -// We have our own implementation of random_device.cpp (older boosts -// didn't support windows well) -#ifdef BOOST_ALL_DYN_LINK -#undef BOOST_ALL_DYN_LINK -#endif -#ifdef BOOST_RANDOM_DYN_LINK -#undef BOOST_RANDOM_DYN_LINK -#endif -#endif +#define BOOST_RANDOM_SOURCE -#include -#include +#include +#include +#include +#include #include -#include -#ifndef WIN32 -# ifndef __CYGWIN__ -# define USE_URANDOM -# endif +#if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) && !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600)) +// A definition is required even for integral static constants +const bool boost::random::random_device::has_fixed_range; #endif -#if defined(WIN32) || defined(__CYGWIN__) -# define USE_WIN32_CRYPT -#endif -#ifdef USE_URANDOM -#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION -// A definition is required even for integral static constants -const bool boost::random_device::has_fixed_range; -const boost::random_device::result_type boost::random_device::min_value; -const boost::random_device::result_type boost::random_device::max_value; +#if defined(BOOST_WINDOWS) + +#include +#include +#include // std::invalid_argument + +#define BOOST_AUTO_LINK_NOMANGLE +#define BOOST_LIB_NAME "Advapi32" +#include + +#ifdef __MINGW32__ + +extern "C" { + +// mingw's wincrypt.h appears to be missing some things +WINADVAPI +BOOL +WINAPI +CryptEnumProvidersA( + DWORD dwIndex, + DWORD *pdwReserved, + DWORD dwFlags, + DWORD *pdwProvType, + LPSTR szProvName, + DWORD *pcbProvName + ); + +} + #endif +namespace { + +const char * const default_token = MS_DEF_PROV_A; + +} + +class boost::random::random_device::impl +{ +public: + impl(const std::string & token) : provider(token) { + char buffer[80]; + DWORD type; + DWORD len; + + // Find the type of the provider + for(DWORD i = 0; ; ++i) { + len = sizeof(buffer); + if(!CryptEnumProvidersA(i, NULL, 0, &type, buffer, &len)) { + error("Could not find provider name"); + } + if(buffer == provider) { + break; + } + } + + if(!CryptAcquireContextA(&hProv, NULL, provider.c_str(), type, + CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { + error("Could not acquire CSP context"); + } + } + + ~impl() { + if(!CryptReleaseContext(hProv, 0)) error("Could not release CSP context"); + } + + unsigned int next() { + unsigned int result; + + if(!CryptGenRandom(hProv, sizeof(result), + static_cast(static_cast(&result)))) { + error("error while reading"); + } + + return result; + } + +private: + void error(const std::string & msg) { + char buf[80]; + DWORD num = FormatMessageA( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + 0, + buf, + sizeof(buf), + NULL); + + throw std::invalid_argument("boost::random_device: " + msg + + " Cryptopraphic Service Provider " + provider + + ": " + std::string(&buf[0], &buf[0] + num)); + } + const std::string provider; + HCRYPTPROV hProv; +}; + +#else + +namespace { // the default is the unlimited capacity device, using some secure hash // try "/dev/random" for blocking when the entropy pool has drained -const char * const boost::random_device::default_token = "/dev/urandom"; +const char * const default_token = "/dev/urandom"; +} /* * This uses the POSIX interface for unbuffered reading. @@ -59,7 +138,7 @@ #if defined(__GNUC__) && defined(_CXXRT_STD_NAME) // I have severe difficulty to get the POSIX includes to work with -// -fhonor-std and Dietmar Kühl's standard C++ library. Hack around that +// -fhonor-std and Dietmar Kuhl's standard C++ library. Hack around that // problem for now. extern "C" { static const int O_RDONLY = 0; @@ -79,7 +158,7 @@ #include // std::invalid_argument -class boost::random_device::impl +class boost::random::random_device::impl { public: impl(const std::string & token) : path(token) { @@ -112,69 +191,27 @@ int fd; }; -#endif - -#ifdef USE_WIN32_CRYPT - -#include -#include -#include -const char * const boost::random_device::default_token = ""; - -// Note about thread-safety: according to my reading of the MSDN page -// 'Threading Issues with Cryptographic Service Providers', both the -// CryptAcquireContext and CryptGenRandom functions are thread-safe, -// as we specify CRYPT_VERIFYCONTEXT (IO operations will not be performed -// and aparently those are the only ones causing threading problems) - -class boost::random_device::impl -{ -public: - impl(const std::string & ) { - InitOk_ = CryptAcquireContext(&hProv_, 0, 0, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT|CRYPT_SILENT) ? true : false; - if (!InitOk_) error("error while initializing crypt random context"); - } - - ~impl() { if (InitOk_) CryptReleaseContext(hProv_, 0); } - - unsigned int next() { - unsigned int result = 0; - if((!InitOk_) || - (!CryptGenRandom(hProv_, sizeof(result), (BYTE*)&result))) { - error("error while generating random number"); - } - return result % RAND_MAX; - } +#endif // BOOST_WINDOWS -private: - void error(const std::string & msg) { - throw std::invalid_argument(msg + " ; error code " + boost::lexical_cast(GetLastError())); - } - bool InitOk_; - HCRYPTPROV hProv_; -}; -#endif +BOOST_RANDOM_DECL boost::random::random_device::random_device() + : pimpl(new impl(default_token)) +{} -boost::random_device::random_device(const std::string& token) +BOOST_RANDOM_DECL boost::random::random_device::random_device(const std::string& token) : pimpl(new impl(token)) -{ - assert((std::numeric_limits::max)() == max_value); -} +{} -boost::random_device::~random_device() +BOOST_RANDOM_DECL boost::random_device::~random_device() { - // the complete class impl is now visible, so we're safe - // (see comment in random.hpp) delete pimpl; } -double boost::random_device::entropy() const +BOOST_RANDOM_DECL double boost::random_device::entropy() const { return 10; } -unsigned int boost::random_device::operator()() +BOOST_RANDOM_DECL unsigned int boost::random_device::operator()() { return pimpl->next(); }