From 5a9296e529dc29be7d0d7892537f35d866c06724 Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 16 Feb 2023 15:24:43 +0800 Subject: [PATCH] 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.");