Skip to content

Commit

Permalink
Merge pull request #2705 from div72/closessl
Browse files Browse the repository at this point in the history
build, crypto, script: remove most of OpenSSL usage
  • Loading branch information
jamescowens authored Oct 23, 2023
2 parents 7548e6c + e7bc015 commit d609b9e
Show file tree
Hide file tree
Showing 26 changed files with 768 additions and 1,174 deletions.
6 changes: 4 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 @@ -358,6 +357,7 @@ nodist_libgridcoin_util_a_SOURCES = $(srcdir)/obj/build.h


# crypto primitives library
crypto_libgridcoin_crypto_base_a_CFLAGS = $(AM_CFLAGS) $(PIE_FLAGS)
crypto_libgridcoin_crypto_base_a_CPPFLAGS = $(AM_CPPFLAGS)
crypto_libgridcoin_crypto_base_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
crypto_libgridcoin_crypto_base_a_SOURCES = \
Expand All @@ -383,7 +383,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

0 comments on commit d609b9e

Please sign in to comment.