crash worked around

But the way I fixed it proves it is
a visual studio bug, not my bug
This commit is contained in:
Cheng 2023-02-17 12:43:22 +08:00
parent 5a9296e529
commit 003d671c25
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
2 changed files with 45 additions and 15 deletions

View File

@ -446,6 +446,38 @@ namespace ristretto255 {
}; };
assert(i == 0); assert(i == 0);
} }
template<typename T>
ristretto255::hsh<hashsize>& operator << (const T& j) {
if constexpr (std::is_same_v<std::remove_cvref_t<T>, std::span<const byte> >) {
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<std::remove_cvref_t<T>, 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<typename T, typename... Args, template<typename T, typename... Args,
typename std::enable_if< is_serializable<const T, Args...>::value, int >::type dummy_arg = 0 typename std::enable_if< is_serializable<const T, Args...>::value, int >::type dummy_arg = 0
>explicit hsh(const T first, Args... args) { >explicit hsh(const T first, Args... args) {
@ -470,9 +502,9 @@ namespace ristretto255 {
} }
} }
}; };
/*
template<unsigned int hashsize, typename T> template<unsigned int hashsize, typename T>
ristretto255::hsh<hashsize>& operator <<(ristretto255::hsh<hashsize> u, const T& j) { ristretto255::hsh<hashsize>& operator <<(ristretto255::hsh<hashsize> &u, const T& j) {
if constexpr (std::is_same_v<std::remove_cvref_t<T>, std::span<const byte> >) { if constexpr (std::is_same_v<std::remove_cvref_t<T>, std::span<const byte> >) {
int i = crypto_generichash_blake2b_update( int i = crypto_generichash_blake2b_update(
&u.st, &u.st,
@ -502,18 +534,7 @@ namespace ristretto255 {
return u; return u;
} }
} }
*/
template<unsigned int hashsize, const char *>
ristretto255::hsh<hashsize>& operator <<(ristretto255::hsh<hashsize> u, const char* sz) {
int i = crypto_generichash_blake2b_update(
&u.st,
static_cast<std::nullptr_t>(sz),
// (unsigned char*)(sz),
strlen(sz) + 1
);
if (i) throw HashReuseException();
return u;
}
// This constructs a finalized hash. // This constructs a finalized hash.

View File

@ -885,11 +885,20 @@ static bool TestShareSecretGenerationSpeed(void) {
} }
} }
ILogMessage("\tTesting hashing speed, hashes of hashes"); 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"; const char* _ = "hello";
hash a(_); hash a(_);
hash b(a); hash b(a);
hash c(b); 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 }; constexpr int hashes{ 3000 };
start_time = std::chrono::high_resolution_clock::now(); start_time = std::chrono::high_resolution_clock::now();
for (int i{ 0 }; i < hashes; i++) { for (int i{ 0 }; i < hashes; i++) {