Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Refactor] Refactor bignum header file into several files
  • Loading branch information
Warrows committed Apr 1, 2019
1 parent e488db7 commit d91ad90
Show file tree
Hide file tree
Showing 6 changed files with 1,046 additions and 981 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Expand Up @@ -1310,6 +1310,9 @@ openssl)
;;
esac

AM_CONDITIONAL([USE_NUM_GMP], [test "x$set_bignum" = "xgmp"])
AM_CONDITIONAL([USE_NUM_OPENSSL], [test "x$set_bignum" = "xopenssl"])

AC_MSG_CHECKING([whether to build test_pivx])
if test x$use_tests = xyes; then
AC_MSG_RESULT([yes])
Expand Down
9 changes: 8 additions & 1 deletion src/Makefile.am
Expand Up @@ -324,9 +324,9 @@ crypto_libbitcoin_crypto_a_SOURCES = \
libzerocoin_libbitcoin_zerocoin_a_CPPFLAGS = $(AM_CPPFLAGS) $(BOOST_CPPFLAGS)
libzerocoin_libbitcoin_zerocoin_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libzerocoin_libbitcoin_zerocoin_a_SOURCES = \
libzerocoin/bignum.h \
libzerocoin/Accumulator.h \
libzerocoin/AccumulatorProofOfKnowledge.h \
libzerocoin/bignum.h \
libzerocoin/Coin.h \
libzerocoin/CoinSpend.h \
libzerocoin/Commitment.h \
Expand All @@ -336,6 +336,7 @@ libzerocoin_libbitcoin_zerocoin_a_SOURCES = \
libzerocoin/SerialNumberSignatureOfKnowledge.h \
libzerocoin/SpendType.h \
libzerocoin/ZerocoinDefines.h \
libzerocoin/bignum.cpp \
libzerocoin/Accumulator.cpp \
libzerocoin/AccumulatorProofOfKnowledge.cpp \
libzerocoin/Coin.cpp \
Expand All @@ -345,6 +346,12 @@ libzerocoin_libbitcoin_zerocoin_a_SOURCES = \
libzerocoin/ParamGeneration.cpp \
libzerocoin/Params.cpp \
libzerocoin/SerialNumberSignatureOfKnowledge.cpp
if USE_NUM_GMP
libzerocoin_libbitcoin_zerocoin_a_SOURCES += libzerocoin/bignum_gmp.cpp
endif
if USE_NUM_OPENSSL
libzerocoin_libbitcoin_zerocoin_a_SOURCES += libzerocoin/bignum_openssl.cpp
endif

# common: shared between pivxd, and pivx-qt and non-server tools
libbitcoin_common_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
Expand Down
63 changes: 63 additions & 0 deletions src/libzerocoin/bignum.cpp
@@ -0,0 +1,63 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Copyright (c) 2017-2019 The PIVX developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "bignum.h"

#if defined(USE_NUM_GMP)
#include "bignum_gmp.cpp"
#endif

#if defined(USE_NUM_OPENSSL)
#include "bignum_openssl.cpp"
#endif

std::string CBigNum::GetHex() const
{
return ToString(16);
}

std::string CBigNum::GetDec() const
{
return ToString(10);
}

CBigNum CBigNum::pow(const int e) const
{
return this->pow(CBigNum(e));
}

void CBigNum::SetHex(const std::string& str)
{
SetHexBool(str);
}

CBigNum& CBigNum::operator/=(const CBigNum& b)
{
*this = *this / b;
return *this;
}

CBigNum& CBigNum::operator%=(const CBigNum& b)
{
*this = *this % b;
return *this;
}

const CBigNum CBigNum::operator++(int)
{
// postfix operator
const CBigNum ret = *this;
++(*this);
return ret;
}

const CBigNum CBigNum::operator--(int)
{
// postfix operator
const CBigNum ret = *this;
--(*this);
return ret;
}

0 comments on commit d91ad90

Please sign in to comment.