i2pd/libi2pd/Elligator.h

40 lines
660 B
C
Raw Normal View History

2019-12-04 23:37:24 +03:00
#ifndef ELLIGATOR_H__
#define ELLIGATOR_H__
2019-12-06 00:03:11 +03:00
#include <inttypes.h>
2019-12-04 23:37:24 +03:00
#include <memory>
2019-12-06 00:03:11 +03:00
#include <openssl/bn.h>
2019-12-04 23:37:24 +03:00
namespace i2p
{
namespace crypto
{
class Elligator2
{
public:
Elligator2 ();
~Elligator2 ();
2019-12-06 00:03:11 +03:00
2019-12-10 22:10:12 +03:00
bool Encode (const uint8_t * key, uint8_t * encoded, bool highY = false) const;
2019-12-10 18:45:08 +03:00
bool Decode (const uint8_t * encoded, uint8_t * key) const;
2019-12-06 00:03:11 +03:00
2019-12-07 04:29:03 +03:00
private:
void SquareRoot (const BIGNUM * x, BIGNUM * r, BN_CTX * ctx) const;
2019-12-10 18:45:08 +03:00
int Legendre (const BIGNUM * a, BN_CTX * ctx) const; // a/p
2019-12-07 04:29:03 +03:00
2019-12-06 00:03:11 +03:00
private:
2019-12-07 04:29:03 +03:00
BIGNUM * p, * p38, * p12, * p14, * sqrtn1, * A, * nA, * u, * iu;
2019-12-04 23:37:24 +03:00
};
std::unique_ptr<Elligator2>& GetElligator ();
}
}
#endif