From 9c6fd362b7ad9b5aa3cebd182a8bea5fe1f8485d Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 21 Jul 2022 13:55:38 -0700 Subject: [PATCH 1/7] fixed wxConfig --- libsodium | 2 +- src/app.cpp | 6 ++---- src/app.h | 2 +- src/stdafx.h | 2 +- wxWidgets | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libsodium b/libsodium index 012e892..8cbcc3c 160000 --- a/libsodium +++ b/libsodium @@ -1 +1 @@ -Subproject commit 012e892841ed6edc521f88a23b55863c7afe4622 +Subproject commit 8cbcc3ccccb035b1a976c053ab4de47b7f0b9352 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/stdafx.h b/src/stdafx.h index c348c77..633c3f9 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"); diff --git a/wxWidgets b/wxWidgets index a8e46b7..2648eb4 160000 --- a/wxWidgets +++ b/wxWidgets @@ -1 +1 @@ -Subproject commit a8e46b7fdd0c3554bb4a55d729415c91c59d4cba +Subproject commit 2648eb4da156a751a377cfe96b91faa03e535c10 From 63e36acab4c8e1590e291494053edb3cb9bff43b Mon Sep 17 00:00:00 2001 From: Cheng Date: Sun, 18 Sep 2022 17:57:42 +1000 Subject: [PATCH 2/7] minor cleanup of git attributes and set_upstream --- .gitattributes | 17 ++++++++-------- docs/set_upstream.sh | 46 ++++++++++++++++++++++---------------------- msvc/winConfig.bat | 2 +- 3 files changed, 33 insertions(+), 32 deletions(-) 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 From 2ae3a850db9d6e082b1f449818b2c2227a051124 Mon Sep 17 00:00:00 2001 From: Cheng Date: Sun, 18 Sep 2022 03:08:36 -0700 Subject: [PATCH 3/7] modified: .gitattributes --- .gitattributes | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 From fab225e872cb8736df963f46ffb0c4e2eee6602d Mon Sep 17 00:00:00 2001 From: Cheng Date: Wed, 5 Oct 2022 15:34:55 +1100 Subject: [PATCH 4/7] struggling because with the new update, stuff just stopped working --- src/ristretto255.h | 72 +++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/src/ristretto255.h b/src/ristretto255.h index 0460991..377f129 100644 --- a/src/ristretto255.h +++ b/src/ristretto255.h @@ -146,10 +146,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 +183,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 +201,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 +219,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));; } }; @@ -462,13 +463,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 +471,45 @@ 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 { + return u << ro::serialize(j); + } + } + + template + ristretto255::hsh& operator <<(ristretto255::hsh u, const char* sz) { + int i = crypto_generichash_blake2b_update( + &u.st, + static_cast(sz), + // (unsigned char*)(sz), + strlen(sz) + 1 + ); + if (i) throw HashReuseException(); + return u; + } + // This constructs a finalized hash. // If it has one argument, and that argument is hsh (unfinalized hash) object, From 0967d18cc4bc1220cf2887b44ef83d22a608f028 Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 16 Feb 2023 13:28:10 +0800 Subject: [PATCH 5/7] minor changes to fix the original failure to compile correctly Which might have worked, but now visual studio compiler crashes on ristretto.h modified: src/frame.cpp modified: src/ristretto255.h modified: src/stdafx.h --- src/frame.cpp | 2 +- src/ristretto255.h | 9 ++++++++- src/stdafx.h | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) 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.h b/src/ristretto255.h index 377f129..6ee40a4 100644 --- a/src/ristretto255.h +++ b/src/ristretto255.h @@ -494,7 +494,14 @@ namespace ristretto255 { return u; } else { - return u << ro::serialize(j); + auto sj = ro::serialize(j); + int i = crypto_generichash_blake2b_update( + &u.st, + &sj[0], + sj.size() + ); + if (i) throw HashReuseException(); + return u; } } diff --git a/src/stdafx.h b/src/stdafx.h index 633c3f9..d32b46b 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -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" From 5a9296e529dc29be7d0d7892537f35d866c06724 Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 16 Feb 2023 15:24:43 +0800 Subject: [PATCH 6/7] Now it compiles, but still fails unit test So, though it compiles, the hashing code is compiling to the wrong thing. I conclude that my investment in template coding has been excessive. It is time to switch to rust. Template coding contains too much logically incoherent and internally inconsistent backward compatibility making it fragile to subtle changes in the compiler. --- src/ristretto255.cpp | 22 ---------------------- src/ristretto255.h | 4 +--- src/unit_test.cpp | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 25 deletions(-) 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 6ee40a4..1d98037 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, @@ -497,7 +495,7 @@ namespace ristretto255 { auto sj = ro::serialize(j); int i = crypto_generichash_blake2b_update( &u.st, - &sj[0], + (const unsigned char*)&sj[0], sj.size() ); if (i) throw HashReuseException(); diff --git a/src/unit_test.cpp b/src/unit_test.cpp index dd473d1..ae8fb26 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."); From 003d671c258f40f252762122d987222e30060410 Mon Sep 17 00:00:00 2001 From: Cheng Date: Fri, 17 Feb 2023 12:43:22 +0800 Subject: [PATCH 7/7] crash worked around But the way I fixed it proves it is a visual studio bug, not my bug --- src/ristretto255.h | 49 +++++++++++++++++++++++++++++++++------------- src/unit_test.cpp | 11 ++++++++++- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/ristretto255.h b/src/ristretto255.h index 1d98037..1a8c31a 100644 --- a/src/ristretto255.h +++ b/src/ristretto255.h @@ -446,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) { @@ -470,9 +502,9 @@ namespace ristretto255 { } } }; - + /* template - ristretto255::hsh& operator <<(ristretto255::hsh u, const T& j) { + ristretto255::hsh& operator <<(ristretto255::hsh &u, const T& j) { if constexpr (std::is_same_v, std::span >) { int i = crypto_generichash_blake2b_update( &u.st, @@ -502,18 +534,7 @@ namespace ristretto255 { return u; } } - - template - ristretto255::hsh& operator <<(ristretto255::hsh u, const char* sz) { - int i = crypto_generichash_blake2b_update( - &u.st, - static_cast(sz), - // (unsigned char*)(sz), - strlen(sz) + 1 - ); - if (i) throw HashReuseException(); - return u; - } + */ // This constructs a finalized hash. diff --git a/src/unit_test.cpp b/src/unit_test.cpp index ae8fb26..78b045b 100644 --- a/src/unit_test.cpp +++ b/src/unit_test.cpp @@ -885,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++) {