diff --git a/.gitattributes b/.gitattributes index d5d380e..3c93bcf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,24 +1,25 @@ ############################################################################### # Handle line endings automatically for files detected as text # and leave all files detected as binary untouched. -* text=auto # Force the following filetypes to have unix eols and encoding, so that Windows does not break them. # If a file is going to be used on linux and windows, we want it invariant, # rather than automatically translated, because automatic translation always screw things up. -* text=auto eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 +* text=auto eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 .gitignore text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 .gitattributes text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 .gitmodules text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 -*.sh text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 +*.sh text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=bash *.c text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 -*.cpp text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 +*.cpp text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=cpp +*.rs text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=rust +*.py text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=python *.h text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 *.txt text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 -*.html text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 -*.htm text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 -*.md text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 +*.html text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=html +*.htm text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=html +*.md text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=markdown *.pandoc text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 -*.css text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 +*.css text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff=css *.manifest text eol=lf encoding=utf-8 whitespace=trailing-space,space-before-tab,tabwidth=4 diff --git a/docs/set_upstream.sh b/docs/set_upstream.sh index 0d49cc9..bb7c4b3 100644 --- a/docs/set_upstream.sh +++ b/docs/set_upstream.sh @@ -3,50 +3,50 @@ set -e set -x echo intended to be run in the event of moving repositories git remote -v -git remote set-url --push upstream git@rho.la:~/wallet.git +git remote set-url --push origin git@rho.la:~/wallet.git git submodule foreach --recursive 'git remote -v' cd libsodium -git remote set-url --push upstream git@rho.la:~/mpir.git -git remote set-url upstream https://github.com/jedisct1/libsodium.git +git remote set-url --push origin git@rho.la:~/mpir.git +git remote set-url origin https://github.com/jedisct1/libsodium.git cd .. cd mpir -git remote set-url --push upstream git@rho.la:~/mpir.git -git remote set-url upstream https://github.com/BrianGladman/mpir.git +git remote set-url --push origin git@rho.la:~/mpir.git +git remote set-url origin https://github.com/BrianGladman/mpir.git cd .. cd wxWidgets -git remote set-url --push upstream git@rho.la:~/wxWidgets.git -git remote set-url upstream https://github.com/wxWidgets/wxWidgets.git +git remote set-url --push origin git@rho.la:~/wxWidgets.git +git remote set-url origin https://github.com/wxWidgets/wxWidgets.git cd .. cd wxWidgets/3rdparty/catch -git remote set-url --push upstream git@rho.la:~/Catch.git -git remote set-url upstream https://github.com/wxWidgets/Catch.git +git remote set-url --push origin git@rho.la:~/Catch.git +git remote set-url origin https://github.com/wxWidgets/Catch.git cd ../../.. cd wxWidgets/3rdparty/nanosvg -git remote set-url --push upstream git@rho.la:~/nanosvg -git remote set-url upstream https://github.com/wxWidgets/nanosvg +git remote set-url --push origin git@rho.la:~/nanosvg +git remote set-url origin https://github.com/wxWidgets/nanosvg cd ../../.. cd wxWidgets/3rdparty/pcre -git remote set-url --push upstream git@rho.la:~/pcre -git remote set-url upstream https://github.com/wxWidgets/pcre +git remote set-url --push origin git@rho.la:~/pcre +git remote set-url origin https://github.com/wxWidgets/pcre cd ../../.. cd wxWidgets/src/expat -git remote set-url --push upstream git@rho.la:~/libexpat.git -git remote set-url upstream https://github.com/wxWidgets/libexpat.git +git remote set-url --push origin git@rho.la:~/libexpat.git +git remote set-url origin https://github.com/wxWidgets/libexpat.git cd ../../.. cd wxWidgets/src/jpeg -git remote set-url --push upstream git@rho.la:~/libjpeg-turbo.git -git remote set-url upstream https://github.com/wxWidgets/libjpeg-turbo.git +git remote set-url --push origin git@rho.la:~/libjpeg-turbo.git +git remote set-url origin https://github.com/wxWidgets/libjpeg-turbo.git cd ../../.. cd wxWidgets/src/png -git remote set-url --push upstream git@rho.la:~/libpng.git -git remote set-url upstream https://github.com/wxWidgets/libpng.git +git remote set-url --push origin git@rho.la:~/libpng.git +git remote set-url origin https://github.com/wxWidgets/libpng.git cd ../../.. cd wxWidgets/src/tiff -git remote set-url --push upstream git@rho.la:~/libtiff.git -git remote set-url upstream https://github.com/wxWidgets/libtiff.git +git remote set-url --push origin git@rho.la:~/libtiff.git +git remote set-url origin https://github.com/wxWidgets/libtiff.git cd ../../.. cd wxWidgets/src/zlib -git remote set-url --push upstream git@rho.la:~/zlib.git -git remote set-url upstream https://github.com/wxWidgets/zlib.git +git remote set-url --push origin git@rho.la:~/zlib.git +git remote set-url origin https://github.com/wxWidgets/zlib.git cd ../../.. winConfigure.sh diff --git a/msvc/winConfig.bat b/msvc/winConfig.bat index fb3fff9..f07f430 100644 --- a/msvc/winConfig.bat +++ b/msvc/winConfig.bat @@ -1,4 +1,4 @@ -echo off +echo on call C:\"Program Files (x86)"\"Microsoft Visual Studio"\2022\BuildTools\VC\Auxiliary\Build\vcvarsamd64_x86.bat call C:\"Program Files"\"Microsoft Visual Studio"\2022\Community\VC\Auxiliary\Build\vcvars64.bat" echo on diff --git a/src/app.cpp b/src/app.cpp index 07b88e7..224c8e1 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -19,12 +19,10 @@ App::~App() bool App::OnInit() { if (wxApp::OnInit()) { - SetVendorName(wxT("rho")); /* This causes the non volatile config data to be stored under the rho on - windows.*/ - SetAppName(wxT("wallet")); /* This causes the non volatile config data to be stored under rho\wallet + pConfig = std::unique_ptr(new wxConfig("wallet", "rho")); + /* This causes the non volatile config data to be stored under rho\wallet We will generally place data in the database, and if additional executables need their own data in the config, they will create their own subkey under Computer\HKEY_CURRENT_USER\Software\rho */ - pConfig = std::unique_ptr(wxConfigBase::Get()); pConfig->SetRecordDefaults(false); /* pConfig corresponds to the Windows Registry entry Computer\HKEY_CURRENT_USER\Software\rho\wallet diff --git a/src/app.h b/src/app.h index 69e26bd..3ccc13f 100644 --- a/src/app.h +++ b/src/app.h @@ -3,7 +3,7 @@ class App : public wxApp { public: - std::unique_ptrpConfig; + std::unique_ptrpConfig; // pConfig corresponds to the Windows Registry entry Computer\HKEY_CURRENT_USER\Software\ro\wallet // Don't use the registry for stuff better served by wxStandardPaths and sqlit3 files located // in locations specified by wxStandardPaths diff --git a/src/frame.cpp b/src/frame.cpp index f18e2c8..221b8fc 100644 --- a/src/frame.cpp +++ b/src/frame.cpp @@ -70,7 +70,7 @@ try { singletonFrame = this; SetIcon(wxICON(AAArho)); sqlite3_init(); - if (sodium_init() == -1) { + if (sodium_init() < 0) { szError = "Fatal Error: Encryption library did not init."; errorCode = 6; // Cannot log the error, because logging not set up yet, so logging itself causes an exception diff --git a/src/ristretto255.cpp b/src/ristretto255.cpp index 8e2e37c..620610a 100644 --- a/src/ristretto255.cpp +++ b/src/ristretto255.cpp @@ -1,28 +1,6 @@ #include "stdafx.h" void randombytes_buf(std::span in) { randombytes_buf(&in[0], in.size_bytes()); } void randombytes_buf(std::span< char> in) { randombytes_buf(&in[0], in.size_bytes()); } -bool operator ==(const std::span& p, const std::span& q) { - bool breturn{ true }; - for (auto xq = q.begin(); auto xp:p) { - if (xp != *xq++) { - breturn = false; - break; - } - } - return breturn; -} - -bool operator !=(const std::span& p, const std::span& q) { - bool breturn{ false }; - for (auto xq = q.begin(); auto xp:p) { - if (xp != *xq++) { - breturn = true; - break; - } - } - return breturn; -} - namespace ristretto255 { bool scalar::constant_time_required{ true }; bool point::constant_time_required{ true }; diff --git a/src/ristretto255.h b/src/ristretto255.h index 0460991..1a8c31a 100644 --- a/src/ristretto255.h +++ b/src/ristretto255.h @@ -54,8 +54,6 @@ void randombytes_buf(std::span in); void randombytes_buf(std::span in); -bool operator !=(const std::span&, const std::span&); -bool operator ==(const std::span&, const std::span&); namespace ro { // Decay to pointer is dangerously convenient, @@ -146,10 +144,11 @@ namespace ro { // template class that generates a std::span of bytes over the blob // field of any object containing a blob record, which is normally sufficient // for a machine independent representation of that object - template < - typename T, - decltype(std::size(std::declval().blob)) dummy_arg = 0 - > auto serialize(const T& pt) { + template + std::enable_if_t< + is_blob_field_type::value, + std::span + > serialize(const T& pt) { return serialize(pt.blob); } @@ -182,17 +181,17 @@ namespace ro { template, int> = 0> class userial : public std::span { public: - std::array::digits + 6) / 7> blob; + std::array::digits + 6) / 7> bblob; userial(T i) { - byte* p = &blob[0] + sizeof(blob); + byte* p = &bblob[0] + sizeof(bblob); *(--p) = i & 0x7f; i >>= 7; while (i != 0) { *(--p) = (i & 0x7f) | 0x80; i >>= 7; } - assert(p >= &blob[0]); - *static_cast*>(this) = std::span(p, &blob[0] + sizeof(blob));; + assert(p >= &bblob[0]); + *static_cast*>(this) = std::span(p, &bblob[0] + sizeof(bblob));; } }; @@ -200,10 +199,10 @@ namespace ro { template, int> = 0> class iserial : public std::span { public: - std::array::digits + 7) / 7> blob; + std::array::digits + 7) / 7> bblob; iserial(T i) { // Throw away the repeated leading bits, and g - byte* p = &blob[0] + sizeof(blob); + byte* p = &bblob[0] + sizeof(bblob); unsigned count; if (i < 0) { size_t ui = i; @@ -218,8 +217,8 @@ namespace ro { i >>= 7; *(--p) = (i & 0x7f) | 0x80; } - assert(p >= &blob[0]); - *static_cast*>(this) = std::span(p, &blob[0] + sizeof(blob));; + assert(p >= &bblob[0]); + *static_cast*>(this) = std::span(p, &bblob[0] + sizeof(bblob));; } }; @@ -447,6 +446,38 @@ namespace ristretto255 { }; assert(i == 0); } + + template + ristretto255::hsh& operator << (const T& j) { + if constexpr (std::is_same_v, std::span >) { + int i = crypto_generichash_blake2b_update( + &(this->st), + &j[0], + j.size() + ); + if (i) throw HashReuseException(); + return *this; + } + else if constexpr (std::is_same_v, const char*>) { + int i = crypto_generichash_blake2b_update( + &(this->st), + (const unsigned char*)(j), + strlen(j) + 1 + ); + if (i) throw HashReuseException(); + return *this; + } + else { + auto sj = ro::serialize(j); + int i = crypto_generichash_blake2b_update( + &(this->st), + (const unsigned char*)&sj[0], + sj.size() + ); + if (i) throw HashReuseException(); + return *this; + } + } template::value, int >::type dummy_arg = 0 >explicit hsh(const T first, Args... args) { @@ -462,13 +493,6 @@ namespace ristretto255 { } } - template < typename T> - decltype(ro::serialize(std::declval::type >()), hsh())& - operator <<(const T & j) { - return *this << ro::serialize(j); - } - - template::value, int >::type dummy_arg = 0 > void hashinto(const T first, Args... args) { @@ -477,27 +501,41 @@ namespace ristretto255 { (*this).hashinto(args...); } } - - hsh& operator <<(const std::span j) { + }; + /* + template + ristretto255::hsh& operator <<(ristretto255::hsh &u, const T& j) { + if constexpr (std::is_same_v, std::span >) { int i = crypto_generichash_blake2b_update( - &st, + &u.st, &j[0], j.size() ); if (i) throw HashReuseException(); - return *this; + return u; } - - hsh& operator <<(char* sz) { + else if constexpr (std::is_same_v, const char*>) { int i = crypto_generichash_blake2b_update( - &st, - static_cast(sz), - strlen(sz) + 1 + &u.st, + (const unsigned char *)(j), + strlen(j) + 1 ); if (i) throw HashReuseException(); - return *this; + return u; } - }; + else { + auto sj = ro::serialize(j); + int i = crypto_generichash_blake2b_update( + &u.st, + (const unsigned char*)&sj[0], + sj.size() + ); + if (i) throw HashReuseException(); + return u; + } + } + */ + // This constructs a finalized hash. // If it has one argument, and that argument is hsh (unfinalized hash) object, diff --git a/src/stdafx.h b/src/stdafx.h index c348c77..d32b46b 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -62,7 +62,7 @@ constexpr bool b_WINDOWS = false; static_assert(wxUSE_UNSAFE_WXSTRING_CONV == 1, R"(In fully utf environment, (wallet.manifest plus /utf-8 compile option) all string conversions are safe.)"); -static_assert(wxMAJOR_VERSION == 3 && wxMINOR_VERSION == 1 && wxRELEASE_NUMBER == 7 && wxSUBRELEASE_NUMBER == 0, "expecting wxWidgets 3.1.7"); +static_assert(wxMAJOR_VERSION == 3 && wxMINOR_VERSION == 2 && wxRELEASE_NUMBER == 0 && wxSUBRELEASE_NUMBER == 1, "expecting wxWidgets 3.1.7"); static_assert(wxUSE_IPV6 == 1, "IP6 unavailable in wxWidgets"); static_assert(WXWIN_COMPATIBILITY_3_0 == 0, "wxWidgets api out of date"); static_assert(wxUSE_COMPILER_TLS == (b_WINDOWS ? 2 : 1), "out of date workarounds in wxWidgets for windows bugs"); @@ -79,7 +79,7 @@ std::span& operator^=(std::span&, byte *); #ifdef __WXMSW__ #include // redefines the new() operator #endif -#define SODIUM_STATIC +#define SODIUM_STATIC 1 #include #include #pragma comment(lib, "libsodium.lib") @@ -98,6 +98,7 @@ enum MyIDs { myID_MAINFRAME_PANEL, myID_TESTWINDOW, myID_WELCOME_TO_ROCOIN, myID_WALLET_UI, mID_CLOSE_WALLET, myID_MYEXIT }; + #include "localization.h" #include "db_accessors.h" #include "app.h" diff --git a/src/unit_test.cpp b/src/unit_test.cpp index dd473d1..78b045b 100644 --- a/src/unit_test.cpp +++ b/src/unit_test.cpp @@ -612,6 +612,28 @@ static bool TestShareSecretGenerationSpeed(void) { return true; } + bool operator ==(const std::span& p, const std::span& q) { + bool breturn{ true }; + for (auto xq = q.begin(); auto xp:p) { + if (xp != *xq++) { + breturn = false; + break; + } + } + return breturn; + } + + bool operator !=(const std::span& p, const std::span& q) { + bool breturn{ false }; + for (auto xq = q.begin(); auto xp:p) { + if (xp != *xq++) { + breturn = true; + break; + } + } + return breturn; + } + static bool TestSignatures(void) { try { ILogMessage("\tTest Schnorr signatures."); @@ -863,11 +885,20 @@ static bool TestShareSecretGenerationSpeed(void) { } } ILogMessage("\tTesting hashing speed, hashes of hashes"); + auto first{ "first" }; + auto second{ "second" }; + if ( hash(first, second) + != + hash( + hsh() << first << second + ) + ) throw MyException("inconsistent hashes generated on strings"); const char* _ = "hello"; hash a(_); hash b(a); hash c(b); - if(hash(b, c) != hash(hsh() << b << c)) throw MyException("inconsistent hashes generated"); + if (hash(b, c) != hash(hsh() << b << c) + ) throw MyException("inconsistent hashes generated"); constexpr int hashes{ 3000 }; start_time = std::chrono::high_resolution_clock::now(); for (int i{ 0 }; i < hashes; i++) {