2020-05-22 16:18:41 +03:00
|
|
|
/*
|
|
|
|
* 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 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
|
|
|
|
2020-01-22 01:53:48 +03:00
|
|
|
bool Encode (const uint8_t * key, uint8_t * encoded, bool highY = false, bool random = true) 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
|
|
|
|
2020-03-01 13:25:50 +03:00
|
|
|
private:
|
2019-12-07 04:29:03 +03:00
|
|
|
|
|
|
|
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
|
2020-03-01 13:25:50 +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
|