mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Add full X11 implementation and block hashing
This commit is contained in:
parent
f164aeaadc
commit
0e82f2f91c
1
TODO.md
1
TODO.md
@ -23,6 +23,7 @@ MUST-HAVE:
|
|||||||
- Adjust difficulty/subsidity (KGW, DGW based on blockheight)
|
- Adjust difficulty/subsidity (KGW, DGW based on blockheight)
|
||||||
- Add masternode payment checks a.k.a. enforcement (based on blockheight)
|
- Add masternode payment checks a.k.a. enforcement (based on blockheight)
|
||||||
- Remove bitcoin dead weight (SHA256, hardcoded keys, nodes)
|
- Remove bitcoin dead weight (SHA256, hardcoded keys, nodes)
|
||||||
|
- Adjust wallet keypool size and add loading indicator on fresh wallet
|
||||||
|
|
||||||
|
|
||||||
ADD-ON:
|
ADD-ON:
|
||||||
|
19
configure.ac
19
configure.ac
@ -137,7 +137,7 @@ AC_PATH_PROG(XGETTEXT,xgettext)
|
|||||||
AC_PATH_PROG(HEXDUMP,hexdump)
|
AC_PATH_PROG(HEXDUMP,hexdump)
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
|
|
||||||
# Enable debug
|
# Enable debug
|
||||||
AC_ARG_ENABLE([debug],
|
AC_ARG_ENABLE([debug],
|
||||||
[AS_HELP_STRING([--enable-debug],
|
[AS_HELP_STRING([--enable-debug],
|
||||||
[use debug compiler flags and macros (default is no)])],
|
[use debug compiler flags and macros (default is no)])],
|
||||||
@ -148,11 +148,11 @@ if test "x$enable_debug" = xyes; then
|
|||||||
if test "x$GCC" = xyes; then
|
if test "x$GCC" = xyes; then
|
||||||
CFLAGS="-g3 -O0 -DDEBUG"
|
CFLAGS="-g3 -O0 -DDEBUG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x$GXX" = xyes; then
|
if test "x$GXX" = xyes; then
|
||||||
CXXFLAGS="-g3 -O0 -DDEBUG"
|
CXXFLAGS="-g3 -O0 -DDEBUG"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## TODO: Remove these hard-coded paths and flags. They are here for the sake of
|
## TODO: Remove these hard-coded paths and flags. They are here for the sake of
|
||||||
## compatibility with the legacy buildsystem.
|
## compatibility with the legacy buildsystem.
|
||||||
@ -354,7 +354,9 @@ fi
|
|||||||
if test x$use_hardening != xno; then
|
if test x$use_hardening != xno; then
|
||||||
AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
|
AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
|
||||||
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
|
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
|
||||||
AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"])
|
|
||||||
|
### -fPIE breaks X11 linking (sph_*)
|
||||||
|
# AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"])
|
||||||
|
|
||||||
AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
|
AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
|
||||||
AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
|
AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
|
||||||
@ -368,10 +370,11 @@ if test x$use_hardening != xno; then
|
|||||||
AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
|
AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"])
|
||||||
AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
|
AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"])
|
||||||
|
|
||||||
if test x$TARGET_OS != xwindows; then
|
### -fPIE breaks X11 linking (sph_*)
|
||||||
# -pie will link successfully with MinGW, but it's unsupported and leads to undeterministic binaries
|
# if test x$TARGET_OS != xwindows; then
|
||||||
AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"])
|
# # -pie will link successfully with MinGW, but it's unsupported and leads to undeterministic binaries
|
||||||
fi
|
# AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"])
|
||||||
|
# fi
|
||||||
|
|
||||||
CXXFLAGS="$CXXFLAGS $HARDENED_CXXFLAGS"
|
CXXFLAGS="$CXXFLAGS $HARDENED_CXXFLAGS"
|
||||||
CPPFLAGS="$CPPFLAGS $HARDENED_CPPFLAGS"
|
CPPFLAGS="$CPPFLAGS $HARDENED_CPPFLAGS"
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
vAlertPubKey = ParseHex("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9");
|
vAlertPubKey = ParseHex("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9");
|
||||||
nDefaultPort = 9999;
|
nDefaultPort = 9999;
|
||||||
nRPCPort = 9998;
|
nRPCPort = 9998;
|
||||||
bnProofOfWorkLimit = CBigNum(~uint256(0) >> 32);
|
bnProofOfWorkLimit = CBigNum(~uint256(0) >> 20); // Darkcoin starting difficulty is 1 / 2^12
|
||||||
nSubsidyHalvingInterval = 210000;
|
nSubsidyHalvingInterval = 210000;
|
||||||
|
|
||||||
// Genesis block
|
// Genesis block
|
||||||
@ -59,13 +59,6 @@ public:
|
|||||||
genesis.nNonce = 28917698;
|
genesis.nNonce = 28917698;
|
||||||
|
|
||||||
hashGenesisBlock = genesis.GetHash();
|
hashGenesisBlock = genesis.GetHash();
|
||||||
|
|
||||||
/* exit without failure */ /* @TODO Debug remove! */
|
|
||||||
printf("%s #HASH\n", hashGenesisBlock.ToString().c_str()); /* @TODO Debug remove! */
|
|
||||||
printf("%s #HARD\n", uint256("0x00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6").ToString().c_str()); /* @TODO Debug remove! */
|
|
||||||
printf("So far so good... Next: Update X11! \n"); /* @TODO Debug remove! */
|
|
||||||
exit(0); /* @TODO Debug remove! */
|
|
||||||
|
|
||||||
assert(hashGenesisBlock == uint256("0x00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6"));
|
assert(hashGenesisBlock == uint256("0x00000ffd590b1485b3caadc19b22e6379c733355108f107a430458cdf3407ab6"));
|
||||||
assert(genesis.hashMerkleRoot == uint256("0xe0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7"));
|
assert(genesis.hashMerkleRoot == uint256("0xe0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7"));
|
||||||
|
|
||||||
@ -131,13 +124,6 @@ public:
|
|||||||
genesis.nNonce = 3861367235;
|
genesis.nNonce = 3861367235;
|
||||||
|
|
||||||
hashGenesisBlock = genesis.GetHash();
|
hashGenesisBlock = genesis.GetHash();
|
||||||
|
|
||||||
/* exit without failure */ /* @TODO Debug remove! */
|
|
||||||
printf("%s #HASH\n", hashGenesisBlock.ToString().c_str()); /* @TODO Debug remove! */
|
|
||||||
printf("%s #HARD\n", uint256("0x00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c").ToString().c_str()); /* @TODO Debug remove! */
|
|
||||||
printf("So far so good... Next: Update X11! \n"); /* @TODO Debug remove! */
|
|
||||||
exit(0); /* @TODO Debug remove! */
|
|
||||||
|
|
||||||
assert(hashGenesisBlock == uint256("0x00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c"));
|
assert(hashGenesisBlock == uint256("0x00000bafbc94add76cb75e2ec92894837288a481e5c005f6563d91623bf8bc2c"));
|
||||||
|
|
||||||
vFixedSeeds.clear();
|
vFixedSeeds.clear();
|
||||||
@ -171,11 +157,11 @@ public:
|
|||||||
genesis.nTime = 1296688602;
|
genesis.nTime = 1296688602;
|
||||||
genesis.nBits = 0x207fffff;
|
genesis.nBits = 0x207fffff;
|
||||||
genesis.nNonce = 2;
|
genesis.nNonce = 2;
|
||||||
hashGenesisBlock = genesis.GetHash();
|
|
||||||
nDefaultPort = 19994;
|
nDefaultPort = 19994;
|
||||||
strDataDir = "regtest";
|
strDataDir = "regtest";
|
||||||
|
|
||||||
assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
|
hashGenesisBlock = genesis.GetHash();
|
||||||
|
assert(hashGenesisBlock == uint256("0xa86aac1aa39f8296820ea3d710d07178492e201ff66cc311d4ad25042bb399d0"));
|
||||||
|
|
||||||
vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
|
vSeeds.clear(); // Regtest mode doesn't have any DNS seeds.
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
// Copyright (c) 2009-2014 The Bitcoin developers
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
||||||
|
// Copyright (c) 2014 vertoe & the Darkcoin developers
|
||||||
// Distributed under the MIT/X11 software license, see the accompanying
|
// Distributed under the MIT/X11 software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@ -214,7 +215,7 @@ uint64_t CTxOutCompressor::DecompressAmount(uint64_t x)
|
|||||||
|
|
||||||
uint256 CBlockHeader::GetHash() const
|
uint256 CBlockHeader::GetHash() const
|
||||||
{
|
{
|
||||||
return Hash(BEGIN(nVersion), END(nNonce));
|
return HashX11(BEGIN(nVersion), END(nNonce));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 CBlock::BuildMerkleTree() const
|
uint256 CBlock::BuildMerkleTree() const
|
||||||
|
122
src/hash.h
122
src/hash.h
@ -1,5 +1,6 @@
|
|||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
// Copyright (c) 2009-2013 The Bitcoin developers
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
||||||
|
// Copyright (c) 2014 vertoe & the Darkcoin developers
|
||||||
// Distributed under the MIT/X11 software license, see the accompanying
|
// Distributed under the MIT/X11 software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@ -10,11 +11,63 @@
|
|||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
#include "sph_blake.h"
|
||||||
|
#include "sph_bmw.h"
|
||||||
|
#include "sph_groestl.h"
|
||||||
|
#include "sph_jh.h"
|
||||||
|
#include "sph_keccak.h"
|
||||||
|
#include "sph_skein.h"
|
||||||
|
#include "sph_luffa.h"
|
||||||
|
#include "sph_cubehash.h"
|
||||||
|
#include "sph_shavite.h"
|
||||||
|
#include "sph_simd.h"
|
||||||
|
#include "sph_echo.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <openssl/ripemd.h>
|
#include <openssl/ripemd.h>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
|
#ifdef GLOBALDEFINED
|
||||||
|
#define GLOBAL
|
||||||
|
#else
|
||||||
|
#define GLOBAL extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GLOBAL sph_blake512_context z_blake;
|
||||||
|
GLOBAL sph_bmw512_context z_bmw;
|
||||||
|
GLOBAL sph_groestl512_context z_groestl;
|
||||||
|
GLOBAL sph_jh512_context z_jh;
|
||||||
|
GLOBAL sph_keccak512_context z_keccak;
|
||||||
|
GLOBAL sph_skein512_context z_skein;
|
||||||
|
GLOBAL sph_luffa512_context z_luffa;
|
||||||
|
GLOBAL sph_cubehash512_context z_cubehash;
|
||||||
|
GLOBAL sph_shavite512_context z_shavite;
|
||||||
|
GLOBAL sph_simd512_context z_simd;
|
||||||
|
GLOBAL sph_echo512_context z_echo;
|
||||||
|
|
||||||
|
#define fillz() do { \
|
||||||
|
sph_blake512_init(&z_blake); \
|
||||||
|
sph_bmw512_init(&z_bmw); \
|
||||||
|
sph_groestl512_init(&z_groestl); \
|
||||||
|
sph_jh512_init(&z_jh); \
|
||||||
|
sph_keccak512_init(&z_keccak); \
|
||||||
|
sph_skein512_init(&z_skein); \
|
||||||
|
sph_luffa512_init(&z_luffa); \
|
||||||
|
sph_cubehash512_init(&z_cubehash); \
|
||||||
|
sph_shavite512_init(&z_shavite); \
|
||||||
|
sph_simd512_init(&z_simd); \
|
||||||
|
sph_echo512_init(&z_echo); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ZBLAKE (memcpy(&ctx_blake, &z_blake, sizeof(z_blake)))
|
||||||
|
#define ZBMW (memcpy(&ctx_bmw, &z_bmw, sizeof(z_bmw)))
|
||||||
|
#define ZGROESTL (memcpy(&ctx_groestl, &z_groestl, sizeof(z_groestl)))
|
||||||
|
#define ZJH (memcpy(&ctx_jh, &z_jh, sizeof(z_jh)))
|
||||||
|
#define ZKECCAK (memcpy(&ctx_keccak, &z_keccak, sizeof(z_keccak)))
|
||||||
|
#define ZSKEIN (memcpy(&ctx_skein, &z_skein, sizeof(z_skein)))
|
||||||
|
|
||||||
|
/* ----------- Bitcoin Hash ------------------------------------------------- */
|
||||||
template<typename T1>
|
template<typename T1>
|
||||||
inline uint256 Hash(const T1 pbegin, const T1 pend)
|
inline uint256 Hash(const T1 pbegin, const T1 pend)
|
||||||
{
|
{
|
||||||
@ -136,4 +189,71 @@ int HMAC_SHA512_Init(HMAC_SHA512_CTX *pctx, const void *pkey, size_t len);
|
|||||||
int HMAC_SHA512_Update(HMAC_SHA512_CTX *pctx, const void *pdata, size_t len);
|
int HMAC_SHA512_Update(HMAC_SHA512_CTX *pctx, const void *pdata, size_t len);
|
||||||
int HMAC_SHA512_Final(unsigned char *pmd, HMAC_SHA512_CTX *pctx);
|
int HMAC_SHA512_Final(unsigned char *pmd, HMAC_SHA512_CTX *pctx);
|
||||||
|
|
||||||
|
/* ----------- Darkcoin Hash ------------------------------------------------ */
|
||||||
|
template<typename T1>
|
||||||
|
inline uint256 HashX11(const T1 pbegin, const T1 pend)
|
||||||
|
|
||||||
|
{
|
||||||
|
sph_blake512_context ctx_blake;
|
||||||
|
sph_bmw512_context ctx_bmw;
|
||||||
|
sph_groestl512_context ctx_groestl;
|
||||||
|
sph_jh512_context ctx_jh;
|
||||||
|
sph_keccak512_context ctx_keccak;
|
||||||
|
sph_skein512_context ctx_skein;
|
||||||
|
sph_luffa512_context ctx_luffa;
|
||||||
|
sph_cubehash512_context ctx_cubehash;
|
||||||
|
sph_shavite512_context ctx_shavite;
|
||||||
|
sph_simd512_context ctx_simd;
|
||||||
|
sph_echo512_context ctx_echo;
|
||||||
|
static unsigned char pblank[1];
|
||||||
|
|
||||||
|
uint512 hash[17]; /* @TODO uint512 not declared */
|
||||||
|
|
||||||
|
sph_blake512_init(&ctx_blake);
|
||||||
|
sph_blake512 (&ctx_blake, (pbegin == pend ? pblank : static_cast<const void*>(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0]));
|
||||||
|
sph_blake512_close(&ctx_blake, static_cast<void*>(&hash[0]));
|
||||||
|
|
||||||
|
sph_bmw512_init(&ctx_bmw);
|
||||||
|
sph_bmw512 (&ctx_bmw, static_cast<const void*>(&hash[0]), 64);
|
||||||
|
sph_bmw512_close(&ctx_bmw, static_cast<void*>(&hash[1]));
|
||||||
|
|
||||||
|
sph_groestl512_init(&ctx_groestl);
|
||||||
|
sph_groestl512 (&ctx_groestl, static_cast<const void*>(&hash[1]), 64);
|
||||||
|
sph_groestl512_close(&ctx_groestl, static_cast<void*>(&hash[2]));
|
||||||
|
|
||||||
|
sph_skein512_init(&ctx_skein);
|
||||||
|
sph_skein512 (&ctx_skein, static_cast<const void*>(&hash[2]), 64);
|
||||||
|
sph_skein512_close(&ctx_skein, static_cast<void*>(&hash[3]));
|
||||||
|
|
||||||
|
sph_jh512_init(&ctx_jh);
|
||||||
|
sph_jh512 (&ctx_jh, static_cast<const void*>(&hash[3]), 64);
|
||||||
|
sph_jh512_close(&ctx_jh, static_cast<void*>(&hash[4]));
|
||||||
|
|
||||||
|
sph_keccak512_init(&ctx_keccak);
|
||||||
|
sph_keccak512 (&ctx_keccak, static_cast<const void*>(&hash[4]), 64);
|
||||||
|
sph_keccak512_close(&ctx_keccak, static_cast<void*>(&hash[5]));
|
||||||
|
|
||||||
|
sph_luffa512_init(&ctx_luffa);
|
||||||
|
sph_luffa512 (&ctx_luffa, static_cast<void*>(&hash[5]), 64);
|
||||||
|
sph_luffa512_close(&ctx_luffa, static_cast<void*>(&hash[6]));
|
||||||
|
|
||||||
|
sph_cubehash512_init(&ctx_cubehash);
|
||||||
|
sph_cubehash512 (&ctx_cubehash, static_cast<const void*>(&hash[6]), 64);
|
||||||
|
sph_cubehash512_close(&ctx_cubehash, static_cast<void*>(&hash[7]));
|
||||||
|
|
||||||
|
sph_shavite512_init(&ctx_shavite);
|
||||||
|
sph_shavite512(&ctx_shavite, static_cast<const void*>(&hash[7]), 64);
|
||||||
|
sph_shavite512_close(&ctx_shavite, static_cast<void*>(&hash[8]));
|
||||||
|
|
||||||
|
sph_simd512_init(&ctx_simd);
|
||||||
|
sph_simd512 (&ctx_simd, static_cast<const void*>(&hash[8]), 64);
|
||||||
|
sph_simd512_close(&ctx_simd, static_cast<void*>(&hash[9]));
|
||||||
|
|
||||||
|
sph_echo512_init(&ctx_echo);
|
||||||
|
sph_echo512 (&ctx_echo, static_cast<const void*>(&hash[9]), 64);
|
||||||
|
sph_echo512_close(&ctx_echo, static_cast<void*>(&hash[10]));
|
||||||
|
|
||||||
|
return hash[10].trim256();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
126
src/uint256.h
126
src/uint256.h
@ -1,5 +1,6 @@
|
|||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
// Copyright (c) 2009-2013 The Bitcoin developers
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
||||||
|
// Copyright (c) 2014 vertoe & the Darkcoin developers
|
||||||
// Distributed under the MIT/X11 software license, see the accompanying
|
// Distributed under the MIT/X11 software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
@ -396,10 +397,12 @@ public:
|
|||||||
|
|
||||||
friend class uint160;
|
friend class uint160;
|
||||||
friend class uint256;
|
friend class uint256;
|
||||||
|
friend class uint512;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef base_uint<160> base_uint160;
|
typedef base_uint<160> base_uint160;
|
||||||
typedef base_uint<256> base_uint256;
|
typedef base_uint<256> base_uint256;
|
||||||
|
typedef base_uint<512> base_uint512;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -632,4 +635,125 @@ inline const uint256 operator|(const uint256& a, const uint256& b) { return
|
|||||||
inline const uint256 operator+(const uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; }
|
inline const uint256 operator+(const uint256& a, const uint256& b) { return (base_uint256)a + (base_uint256)b; }
|
||||||
inline const uint256 operator-(const uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; }
|
inline const uint256 operator-(const uint256& a, const uint256& b) { return (base_uint256)a - (base_uint256)b; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// uint512
|
||||||
|
//
|
||||||
|
|
||||||
|
/** 512-bit unsigned integer */
|
||||||
|
class uint512 : public base_uint512
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef base_uint512 basetype;
|
||||||
|
|
||||||
|
uint512()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < WIDTH; i++)
|
||||||
|
pn[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint512(const basetype& b)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < WIDTH; i++)
|
||||||
|
pn[i] = b.pn[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint512& operator=(const basetype& b)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < WIDTH; i++)
|
||||||
|
pn[i] = b.pn[i];
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint512(uint64_t b)
|
||||||
|
{
|
||||||
|
pn[0] = (unsigned int)b;
|
||||||
|
pn[1] = (unsigned int)(b >> 32);
|
||||||
|
for (int i = 2; i < WIDTH; i++)
|
||||||
|
pn[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint512& operator=(uint64_t b)
|
||||||
|
{
|
||||||
|
pn[0] = (unsigned int)b;
|
||||||
|
pn[1] = (unsigned int)(b >> 32);
|
||||||
|
for (int i = 2; i < WIDTH; i++)
|
||||||
|
pn[i] = 0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit uint512(const std::string& str)
|
||||||
|
{
|
||||||
|
SetHex(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit uint512(const std::vector<unsigned char>& vch)
|
||||||
|
{
|
||||||
|
if (vch.size() == sizeof(pn))
|
||||||
|
memcpy(pn, &vch[0], sizeof(pn));
|
||||||
|
else
|
||||||
|
*this = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256 trim256() const
|
||||||
|
{
|
||||||
|
uint256 ret;
|
||||||
|
for (unsigned int i = 0; i < uint256::WIDTH; i++){
|
||||||
|
ret.pn[i] = pn[i];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator==(const uint512& a, uint64_t b) { return (base_uint512)a == b; }
|
||||||
|
inline bool operator!=(const uint512& a, uint64_t b) { return (base_uint512)a != b; }
|
||||||
|
inline const uint512 operator<<(const base_uint512& a, unsigned int shift) { return uint512(a) <<= shift; }
|
||||||
|
inline const uint512 operator>>(const base_uint512& a, unsigned int shift) { return uint512(a) >>= shift; }
|
||||||
|
inline const uint512 operator<<(const uint512& a, unsigned int shift) { return uint512(a) <<= shift; }
|
||||||
|
inline const uint512 operator>>(const uint512& a, unsigned int shift) { return uint512(a) >>= shift; }
|
||||||
|
|
||||||
|
inline const uint512 operator^(const base_uint512& a, const base_uint512& b) { return uint512(a) ^= b; }
|
||||||
|
inline const uint512 operator&(const base_uint512& a, const base_uint512& b) { return uint512(a) &= b; }
|
||||||
|
inline const uint512 operator|(const base_uint512& a, const base_uint512& b) { return uint512(a) |= b; }
|
||||||
|
inline const uint512 operator+(const base_uint512& a, const base_uint512& b) { return uint512(a) += b; }
|
||||||
|
inline const uint512 operator-(const base_uint512& a, const base_uint512& b) { return uint512(a) -= b; }
|
||||||
|
|
||||||
|
inline bool operator<(const base_uint512& a, const uint512& b) { return (base_uint512)a < (base_uint512)b; }
|
||||||
|
inline bool operator<=(const base_uint512& a, const uint512& b) { return (base_uint512)a <= (base_uint512)b; }
|
||||||
|
inline bool operator>(const base_uint512& a, const uint512& b) { return (base_uint512)a > (base_uint512)b; }
|
||||||
|
inline bool operator>=(const base_uint512& a, const uint512& b) { return (base_uint512)a >= (base_uint512)b; }
|
||||||
|
inline bool operator==(const base_uint512& a, const uint512& b) { return (base_uint512)a == (base_uint512)b; }
|
||||||
|
inline bool operator!=(const base_uint512& a, const uint512& b) { return (base_uint512)a != (base_uint512)b; }
|
||||||
|
inline const uint512 operator^(const base_uint512& a, const uint512& b) { return (base_uint512)a ^ (base_uint512)b; }
|
||||||
|
inline const uint512 operator&(const base_uint512& a, const uint512& b) { return (base_uint512)a & (base_uint512)b; }
|
||||||
|
inline const uint512 operator|(const base_uint512& a, const uint512& b) { return (base_uint512)a | (base_uint512)b; }
|
||||||
|
inline const uint512 operator+(const base_uint512& a, const uint512& b) { return (base_uint512)a + (base_uint512)b; }
|
||||||
|
inline const uint512 operator-(const base_uint512& a, const uint512& b) { return (base_uint512)a - (base_uint512)b; }
|
||||||
|
|
||||||
|
inline bool operator<(const uint512& a, const base_uint512& b) { return (base_uint512)a < (base_uint512)b; }
|
||||||
|
inline bool operator<=(const uint512& a, const base_uint512& b) { return (base_uint512)a <= (base_uint512)b; }
|
||||||
|
inline bool operator>(const uint512& a, const base_uint512& b) { return (base_uint512)a > (base_uint512)b; }
|
||||||
|
inline bool operator>=(const uint512& a, const base_uint512& b) { return (base_uint512)a >= (base_uint512)b; }
|
||||||
|
inline bool operator==(const uint512& a, const base_uint512& b) { return (base_uint512)a == (base_uint512)b; }
|
||||||
|
inline bool operator!=(const uint512& a, const base_uint512& b) { return (base_uint512)a != (base_uint512)b; }
|
||||||
|
inline const uint512 operator^(const uint512& a, const base_uint512& b) { return (base_uint512)a ^ (base_uint512)b; }
|
||||||
|
inline const uint512 operator&(const uint512& a, const base_uint512& b) { return (base_uint512)a & (base_uint512)b; }
|
||||||
|
inline const uint512 operator|(const uint512& a, const base_uint512& b) { return (base_uint512)a | (base_uint512)b; }
|
||||||
|
inline const uint512 operator+(const uint512& a, const base_uint512& b) { return (base_uint512)a + (base_uint512)b; }
|
||||||
|
inline const uint512 operator-(const uint512& a, const base_uint512& b) { return (base_uint512)a - (base_uint512)b; }
|
||||||
|
|
||||||
|
inline bool operator<(const uint512& a, const uint512& b) { return (base_uint512)a < (base_uint512)b; }
|
||||||
|
inline bool operator<=(const uint512& a, const uint512& b) { return (base_uint512)a <= (base_uint512)b; }
|
||||||
|
inline bool operator>(const uint512& a, const uint512& b) { return (base_uint512)a > (base_uint512)b; }
|
||||||
|
inline bool operator>=(const uint512& a, const uint512& b) { return (base_uint512)a >= (base_uint512)b; }
|
||||||
|
inline bool operator==(const uint512& a, const uint512& b) { return (base_uint512)a == (base_uint512)b; }
|
||||||
|
inline bool operator!=(const uint512& a, const uint512& b) { return (base_uint512)a != (base_uint512)b; }
|
||||||
|
inline const uint512 operator^(const uint512& a, const uint512& b) { return (base_uint512)a ^ (base_uint512)b; }
|
||||||
|
inline const uint512 operator&(const uint512& a, const uint512& b) { return (base_uint512)a & (base_uint512)b; }
|
||||||
|
inline const uint512 operator|(const uint512& a, const uint512& b) { return (base_uint512)a | (base_uint512)b; }
|
||||||
|
inline const uint512 operator+(const uint512& a, const uint512& b) { return (base_uint512)a + (base_uint512)b; }
|
||||||
|
inline const uint512 operator-(const uint512& a, const uint512& b) { return (base_uint512)a - (base_uint512)b; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user