From 9a12dbbd7e53da61a0b5d1b71008d093388eef0c Mon Sep 17 00:00:00 2001 From: Cheng Date: Fri, 22 Sep 2023 19:49:30 +1000 Subject: [PATCH] minimally broken branch to isolate what is broken --- src/ristretto255.h | 55 ++++++++++------------------------------------ 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/src/ristretto255.h b/src/ristretto255.h index 1a8c31a..054b511 100644 --- a/src/ristretto255.h +++ b/src/ristretto255.h @@ -449,35 +449,36 @@ namespace ristretto255 { template ristretto255::hsh& operator << (const T& j) { + int i{ 1 }; if constexpr (std::is_same_v, std::span >) { - int i = crypto_generichash_blake2b_update( + 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( + i = crypto_generichash_blake2b_update( &(this->st), (const unsigned char*)(j), strlen(j) + 1 ); - if (i) throw HashReuseException(); - return *this; } - else { + else if constexpr (is_serializable::value) { auto sj = ro::serialize(j); - int i = crypto_generichash_blake2b_update( + i = crypto_generichash_blake2b_update( &(this->st), (const unsigned char*)&sj[0], sj.size() ); - if (i) throw HashReuseException(); - return *this; } + else { + static_assert(false, "don't know a machine and compiler independent representation of this type"); + } + if (i) throw HashReuseException(); + return *this; } + template::value, int >::type dummy_arg = 0 >explicit hsh(const T first, Args... args) { @@ -502,40 +503,6 @@ namespace ristretto255 { } } }; - /* - template - 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, - &j[0], - j.size() - ); - if (i) throw HashReuseException(); - return u; - } - else if constexpr (std::is_same_v, const char*>) { - int i = crypto_generichash_blake2b_update( - &u.st, - (const unsigned char *)(j), - strlen(j) + 1 - ); - if (i) throw HashReuseException(); - 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,