forked from lthn/blockchain
crypto: attempt to fix a warning about dereferencing type-punned pointer
This commit is contained in:
parent
1c940653d4
commit
2ae226e594
2 changed files with 9 additions and 12 deletions
|
|
@ -24,4 +24,6 @@ namespace crypto
|
|||
const point_t c_point_H2 = { 0x70c8d1ab9dbf1cc0, 0xc561bb12639a8516, 0x3cfff1def9e5b268, 0xe0936386f3bcce1a }; // == Hp("h2_generator"), cheched in bpp_basics
|
||||
const point_t c_point_0 = point_t(point_t::tag_zero());
|
||||
|
||||
static_assert(sizeof(scalar_t::m_sk) == sizeof(scalar_t::m_u64) && sizeof(scalar_t::m_u64) == sizeof(scalar_t::m_s), "size missmatch");
|
||||
|
||||
} // namespace crypto
|
||||
|
|
|
|||
|
|
@ -136,8 +136,9 @@ namespace crypto
|
|||
{
|
||||
union
|
||||
{
|
||||
uint64_t m_u64[4];
|
||||
unsigned char m_s[32];
|
||||
uint64_t m_u64[4];
|
||||
unsigned char m_s[32];
|
||||
crypto::secret_key m_sk;
|
||||
};
|
||||
|
||||
scalar_t()
|
||||
|
|
@ -205,28 +206,22 @@ namespace crypto
|
|||
|
||||
crypto::secret_key &as_secret_key()
|
||||
{
|
||||
return *reinterpret_cast<crypto::secret_key*>(&m_s[0]);
|
||||
return m_sk;
|
||||
}
|
||||
|
||||
const crypto::secret_key& as_secret_key() const
|
||||
{
|
||||
return *reinterpret_cast<const crypto::secret_key*>(&m_s[0]);
|
||||
return m_sk;
|
||||
}
|
||||
|
||||
operator crypto::secret_key() const
|
||||
{
|
||||
crypto::secret_key result;
|
||||
memcpy(result.data, &m_s, sizeof result.data);
|
||||
return result;
|
||||
return m_sk;
|
||||
}
|
||||
|
||||
void from_secret_key(const crypto::secret_key& sk)
|
||||
{
|
||||
uint64_t *p_sk64 = (uint64_t*)&sk;
|
||||
m_u64[0] = p_sk64[0];
|
||||
m_u64[1] = p_sk64[1];
|
||||
m_u64[2] = p_sk64[2];
|
||||
m_u64[3] = p_sk64[3];
|
||||
m_sk = sk;
|
||||
// assuming secret key is correct (< L), so we don't need to call reduce here
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue