diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c index dad60907..7553a1cb 100644 --- a/src/crypto/crypto-ops.c +++ b/src/crypto/crypto-ops.c @@ -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] | diff --git a/src/crypto/crypto-ops.h b/src/crypto/crypto-ops.h index 07122772..e01735dd 100644 --- a/src/crypto/crypto-ops.h +++ b/src/crypto/crypto-ops.h @@ -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); diff --git a/tests/functional_tests/crypto_tests.cpp b/tests/functional_tests/crypto_tests.cpp index 4ba6717d..3b7aec3e 100644 --- a/tests/functional_tests/crypto_tests.cpp +++ b/tests/functional_tests/crypto_tests.cpp @@ -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(&pk)) == 0;