1
0
Fork 0
forked from lthn/blockchain

crypto: fe_isnonzero made public, point_t::is_zero() added

This commit is contained in:
sowle 2021-01-26 23:14:46 +03:00
parent 8063604b37
commit 5843f6964c
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 8 additions and 1 deletions

View file

@ -332,7 +332,7 @@ static int fe_isnegative(const fe f) {
/* From fe_isnonzero.c, modified */
static int fe_isnonzero(const fe f) {
int fe_isnonzero(const fe f) {
unsigned char s[32];
fe_tobytes(s, f);
return (((int) (s[0] | s[1] | s[2] | s[3] | s[4] | s[5] | s[6] | s[7] | s[8] |

View file

@ -128,6 +128,7 @@ int sc_isnonzero(const unsigned char *); /* Doesn't normalize */
void sc_invert(unsigned char*, const unsigned char*);
void fe_sq(fe h, const fe f);
int fe_isnonzero(const fe f);
void fe_mul(fe, const fe, const fe);
void fe_frombytes(fe h, const unsigned char *s);
void fe_invert(fe out, const fe z);

View file

@ -418,6 +418,12 @@ struct point_t
ge_p3_0(&m_p3);
}
bool is_zero() const
{
// (0, 1) ~ (0, z, z, 0)
return fe_isnonzero(m_p3.X) * fe_cmp(m_p3.Y, m_p3.Z) == 0;
}
bool from_public_key(const crypto::public_key& pk)
{
return ge_frombytes_vartime(&m_p3, reinterpret_cast<const unsigned char*>(&pk)) == 0;