diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index fa5aaafd..43e69c42 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -271,6 +271,11 @@ namespace crypto return sc_check(&m_s[0]) == 0; } + void reduce() + { + sc_reduce32(&m_s[0]); + } + scalar_t operator+(const scalar_t& v) const { scalar_t result; @@ -825,6 +830,16 @@ namespace crypto this->clear(); return scalar_t(hash); // this will reduce to L } + + void assign_calc_hash(scalar_t& result, bool clear = true) + { + static_assert(sizeof result == sizeof(crypto::hash), "size missmatch"); + size_t data_size_bytes = m_elements.size() * sizeof(item_t); + crypto::cn_fast_hash(m_elements.data(), data_size_bytes, (crypto::hash&)result); + result.reduce(); + if (clear) + this->clear(); + } union item_t {