1
0
Fork 0
forked from lthn/blockchain

crypto sugar: scalar_t::reduce(), hs_t::assign_calc_hash()

This commit is contained in:
sowle 2021-05-11 04:32:03 +03:00
parent 1957ea5c75
commit 182a0c59bb
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC

View file

@ -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
{