encode with highY

This commit is contained in:
orignal 2019-12-10 14:10:12 -05:00
parent 36eaaa748c
commit 9ed58e5186
3 changed files with 22 additions and 6 deletions

View file

@ -39,7 +39,7 @@ namespace crypto
BN_free (u); BN_free (iu);
}
bool Elligator2::Encode (const uint8_t * key, uint8_t * encoded) const
bool Elligator2::Encode (const uint8_t * key, uint8_t * encoded, bool highY) const
{
bool ret = true;
BN_CTX * ctx = BN_CTX_new ();
@ -63,8 +63,16 @@ namespace crypto
if (Legendre (uxxA, ctx) != -1)
{
BIGNUM * r = BN_CTX_get (ctx);
BN_mod_inverse (r, xA, p, ctx);
BN_mod_mul (r, r, x, p, ctx);
if (highY)
{
BN_mod_inverse (r, x, p, ctx);
BN_mod_mul (r, r, xA, p, ctx);
}
else
{
BN_mod_inverse (r, xA, p, ctx);
BN_mod_mul (r, r, x, p, ctx);
}
BN_mod_mul (r, r, iu, p, ctx);
SquareRoot (r, r, ctx);

View file

@ -17,7 +17,7 @@ namespace crypto
Elligator2 ();
~Elligator2 ();
bool Encode (const uint8_t * key, uint8_t * encoded) const;
bool Encode (const uint8_t * key, uint8_t * encoded, bool highY = false) const;
bool Decode (const uint8_t * encoded, uint8_t * key) const;
private: