Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build, crypto, script: remove most of OpenSSL usage #2705

Merged
merged 12 commits into from
Oct 23, 2023
5 changes: 3 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ GRIDCOIN_CORE_H = \
attributes.h \
banman.h \
base58.h \
bignum.h \
chainparams.h \
chainparamsbase.h \
checkpoints.h \
Expand Down Expand Up @@ -383,7 +382,9 @@ crypto_libgridcoin_crypto_base_a_SOURCES = \
crypto/sha512.cpp \
crypto/sha512.h \
crypto/siphash.cpp \
crypto/siphash.h
crypto/siphash.h \
gridcoin/md5.c \
gridcoin/md5.h

if USE_ASM
crypto_libgridcoin_crypto_base_a_SOURCES += crypto/sha256_sse4.cpp
Expand Down
1 change: 0 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ GRIDCOIN_TESTS =\
test/base32_tests.cpp \
test/base58_tests.cpp \
test/base64_tests.cpp \
test/bignum_tests.cpp \
test/bip32_tests.cpp \
test/compilerbug_tests.cpp \
test/crypto_tests.cpp \
Expand Down
21 changes: 20 additions & 1 deletion src/arith_uint256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <uint256.h>
#include <crypto/common.h>
#include <util/strencodings.h>


template <unsigned int BITS>
Expand Down Expand Up @@ -146,7 +147,13 @@ double base_uint<BITS>::getdouble() const
template <unsigned int BITS>
std::string base_uint<BITS>::GetHex() const
{
return ArithToUint256(*this).GetHex();
static constexpr ssize_t BYTES = BITS / 8;

uint8_t pn_rev[BYTES];
for (int i = 0; i < BYTES; ++i) {
pn_rev[i] = ((uint8_t*)&pn)[BYTES - 1 - i];
}
return HexStr(pn_rev);
}

template <unsigned int BITS>
Expand Down Expand Up @@ -257,3 +264,15 @@ arith_uint256 UintToArith256(const uint256 &a)
b.pn[x] = ReadLE32(a.begin() + x*4);
return b;
}

// Explicit instantiations for base_uint<320>
template base_uint<320>& base_uint<320>::operator<<=(unsigned int);
template base_uint<320>& base_uint<320>::operator*=(const base_uint<320>& b);
template int base_uint<320>::CompareTo(const base_uint<320>&) const;
template std::string base_uint<320>::GetHex() const;

arith_uint320::arith_uint320(const uint256& b) {
std::memset(pn, 0, sizeof(pn));
std::memcpy(pn, b.data(), b.size());
}

17 changes: 17 additions & 0 deletions src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>

class uint256;
class arith_uint320;

class uint_error : public std::runtime_error {
public:
Expand Down Expand Up @@ -279,6 +280,22 @@ class arith_uint256 : public base_uint<256> {

friend uint256 ArithToUint256(const arith_uint256 &);
friend arith_uint256 UintToArith256(const uint256 &);
friend class arith_uint320;
};

/** 320-bit unsigned big integer. */
class arith_uint320 : public base_uint<320> {
public:
arith_uint320() {}
arith_uint320(const base_uint<320>& b) : base_uint<320>(b) {}
arith_uint320(uint64_t b) : base_uint<320>(b) {}

arith_uint320(const arith_uint256& b) {
std::memset(pn, 0, sizeof(pn));
std::memcpy(pn, b.pn, sizeof(b.pn));
}

arith_uint320(const uint256& b);
};

uint256 ArithToUint256(const arith_uint256 &);
Expand Down
Loading