i2pd/libi2pd/Elligator.h

46 lines
864 B
C
Raw Normal View History

/*
* Copyright (c) 2013-2020, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/
2019-12-04 20:37:24 +00:00
#ifndef ELLIGATOR_H__
#define ELLIGATOR_H__
2019-12-05 21:03:11 +00:00
#include <inttypes.h>
2019-12-04 20:37:24 +00:00
#include <memory>
2019-12-05 21:03:11 +00:00
#include <openssl/bn.h>
2019-12-04 20:37:24 +00:00
namespace i2p
{
namespace crypto
{
class Elligator2
{
public:
Elligator2 ();
~Elligator2 ();
2019-12-05 21:03:11 +00:00
2020-01-21 22:53:48 +00:00
bool Encode (const uint8_t * key, uint8_t * encoded, bool highY = false, bool random = true) const;
2019-12-10 15:45:08 +00:00
bool Decode (const uint8_t * encoded, uint8_t * key) const;
2019-12-05 21:03:11 +00:00
private:
2019-12-07 01:29:03 +00:00
void SquareRoot (const BIGNUM * x, BIGNUM * r, BN_CTX * ctx) const;
2019-12-10 15:45:08 +00:00
int Legendre (const BIGNUM * a, BN_CTX * ctx) const; // a/p
2019-12-05 21:03:11 +00:00
private:
2019-12-07 01:29:03 +00:00
BIGNUM * p, * p38, * p12, * p14, * sqrtn1, * A, * nA, * u, * iu;
2019-12-04 20:37:24 +00:00
};
std::unique_ptr<Elligator2>& GetElligator ();
}
}
#endif