mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Split stuff from util to PlatformMacros and RandomNumbers
This commit is contained in:
@@ -32,6 +32,15 @@
|
||||
#include <boost/asio.hpp> // for stupid parseIpPort
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
// VFALCO: TODO, Replace OpenSSL randomness with a dependency-free implementation
|
||||
// Perhaps Schneier's Yarrow or a variant. Abstract the collection of
|
||||
// entropy and provide OS-specific implementation. We can re-use the
|
||||
// BearShare source code for this.
|
||||
//
|
||||
// Add Random number generation to the new VFLib
|
||||
//
|
||||
#include <openssl/rand.h> // Because of ripple_RandomNumbers.cpp
|
||||
|
||||
// VFALCO: TODO, fix these warnings!
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length"
|
||||
@@ -52,6 +61,8 @@
|
||||
#include "memory/ripple_ByteOrder.cpp"
|
||||
#include "memory/ripple_StringUtilities.cpp"
|
||||
|
||||
#include "system/ripple_RandomNumbers.cpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
@@ -101,4 +101,7 @@ namespace boost {
|
||||
|
||||
#include "events/ripple_UptimeTimer.h"
|
||||
|
||||
#include "system/ripple_PlatformMacros.h"
|
||||
#include "system/ripple_RandomNumbers.h"
|
||||
|
||||
#endif
|
||||
|
||||
52
modules/ripple_basics/system/ripple_PlatformMacros.h
Normal file
52
modules/ripple_basics/system/ripple_PlatformMacros.h
Normal file
@@ -0,0 +1,52 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or 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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_PLATFORMMACROS_H
|
||||
#define RIPPLE_PLATFORMMACROS_H
|
||||
|
||||
// VFALCO: TODO Clean this up
|
||||
|
||||
#if (!defined(FORCE_NO_C11X) && (__cplusplus > 201100L)) || defined(FORCE_C11X)
|
||||
|
||||
#define C11X
|
||||
#include <functional>
|
||||
#define UPTR_T std::unique_ptr
|
||||
#define MOVE_P(p) std::move(p)
|
||||
#define BIND_TYPE std::bind
|
||||
#define FUNCTION_TYPE std::function
|
||||
#define P_1 std::placeholders::_1
|
||||
#define P_2 std::placeholders::_2
|
||||
#define P_3 std::placeholders::_3
|
||||
#define P_4 std::placeholders::_4
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#define UPTR_T std::auto_ptr
|
||||
#define MOVE_P(p) (p)
|
||||
#define BIND_TYPE boost::bind
|
||||
#define FUNCTION_TYPE boost::function
|
||||
#define P_1 _1
|
||||
#define P_2 _2
|
||||
#define P_3 _3
|
||||
#define P_4 _4
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
30
modules/ripple_basics/system/ripple_RandomNumbers.cpp
Normal file
30
modules/ripple_basics/system/ripple_RandomNumbers.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or 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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
void getRand(unsigned char *buf, int num)
|
||||
{
|
||||
#ifdef PURIFY
|
||||
memset(buf, 0, num);
|
||||
#endif
|
||||
if (RAND_bytes(buf, num) != 1)
|
||||
{
|
||||
assert(false);
|
||||
throw std::runtime_error("Entropy pool not seeded");
|
||||
}
|
||||
}
|
||||
|
||||
46
modules/ripple_basics/system/ripple_RandomNumbers.h
Normal file
46
modules/ripple_basics/system/ripple_RandomNumbers.h
Normal file
@@ -0,0 +1,46 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or 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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_RANDOMNUMBERS_H
|
||||
#define RIPPLE_RANDOMNUMBERS_H
|
||||
|
||||
// Cryptographically secure random number source
|
||||
|
||||
// VFALCO: TODO Clean this up, rename stuff
|
||||
// Seriously...wtf...rename "num" to bytes, or make it work
|
||||
// using a template so the destination can be a vector of objects.
|
||||
//
|
||||
// VFALCO: Should accept void* not unsigned char*
|
||||
//
|
||||
extern void getRand (unsigned char *buf, int num);
|
||||
|
||||
inline static void getRand (char *buf, int num)
|
||||
{
|
||||
return getRand (reinterpret_cast<unsigned char *>(buf), num);
|
||||
}
|
||||
|
||||
// VFALCO: TODO Clean this
|
||||
// "num" is really bytes this should just be called getRandomBytes()
|
||||
// This function is unnecessary!
|
||||
//
|
||||
inline static void getRand (void *buf, int num)
|
||||
{
|
||||
return getRand (reinterpret_cast<unsigned char *>(buf), num);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user