1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-15 01:20:10 +00:00
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 15:37:24 -05:00
#ifndef ELLIGATOR_H__
#define ELLIGATOR_H__
2019-12-05 16:03:11 -05:00
#include <inttypes.h>
2019-12-04 15:37:24 -05:00
#include <memory>
2019-12-05 16:03:11 -05:00
#include <openssl/bn.h>
2019-12-04 15:37:24 -05:00
namespace i2p
{
namespace crypto
{
class Elligator2
{
public:
Elligator2 ();
~Elligator2 ();
2019-12-05 16:03:11 -05:00
2020-01-21 17:53:48 -05:00
bool Encode (const uint8_t * key, uint8_t * encoded, bool highY = false, bool random = true) const;
2019-12-10 10:45:08 -05:00
bool Decode (const uint8_t * encoded, uint8_t * key) const;
2019-12-05 16:03:11 -05:00
private:
2019-12-06 20:29:03 -05:00
void SquareRoot (const BIGNUM * x, BIGNUM * r, BN_CTX * ctx) const;
2019-12-10 10:45:08 -05:00
int Legendre (const BIGNUM * a, BN_CTX * ctx) const; // a/p
2019-12-05 16:03:11 -05:00
private:
2019-12-06 20:29:03 -05:00
BIGNUM * p, * p38, * p12, * p14, * sqrtn1, * A, * nA, * u, * iu;
2019-12-04 15:37:24 -05:00
};
std::unique_ptr<Elligator2>& GetElligator ();
}
}
#endif