2017-03-14 00:28:36 +00:00
|
|
|
|
#ifndef GOST_H__
|
|
|
|
|
#define GOST_H__
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <openssl/ec.h>
|
|
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
|
{
|
|
|
|
|
namespace crypto
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// ГОСТ Р 34.10
|
|
|
|
|
|
|
|
|
|
enum GOSTR3410ParamSet
|
|
|
|
|
{
|
2017-03-14 20:02:16 +00:00
|
|
|
|
// GOST R 34.10-2001
|
2017-03-14 00:28:36 +00:00
|
|
|
|
eGOSTR3410CryptoProA = 0, // 1.2.643.2.2.35.1
|
|
|
|
|
eGOSTR3410CryptoProB, // 1.2.643.2.2.35.2
|
|
|
|
|
eGOSTR3410CryptoProC, // 1.2.643.2.2.35.3
|
2017-03-14 20:02:16 +00:00
|
|
|
|
// XchA = A, XchB = C
|
2017-03-14 00:28:36 +00:00
|
|
|
|
//eGOSTR3410CryptoProXchA, // 1.2.643.2.2.36.0
|
|
|
|
|
//eGOSTR3410CryptoProXchB, // 1.2.643.2.2.36.1
|
2017-03-14 20:02:16 +00:00
|
|
|
|
// GOST R 34.10-2012
|
2017-03-15 00:03:44 +00:00
|
|
|
|
eGOSTR3410TC26A256, // 1.2.643.7.1.2.1.1.1
|
|
|
|
|
eGOSTR3410TC26C512, // 1.2.643.7.1.2.1.2.3
|
2017-03-14 00:28:36 +00:00
|
|
|
|
eGOSTR3410NumParamSets
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GOSTR3410Curve
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
GOSTR3410Curve (BIGNUM * a, BIGNUM * b, BIGNUM * p, BIGNUM * q, BIGNUM * x, BIGNUM * y);
|
|
|
|
|
~GOSTR3410Curve ();
|
|
|
|
|
|
2017-03-14 20:41:06 +00:00
|
|
|
|
size_t GetKeyLen () const { return m_KeyLen; };
|
2017-03-14 00:28:36 +00:00
|
|
|
|
EC_POINT * MulP (const BIGNUM * n) const;
|
|
|
|
|
bool GetXY (const EC_POINT * p, BIGNUM * x, BIGNUM * y) const;
|
|
|
|
|
EC_POINT * CreatePoint (const BIGNUM * x, const BIGNUM * y) const;
|
|
|
|
|
void Sign (const BIGNUM * priv, const BIGNUM * digest, BIGNUM * r, BIGNUM * s);
|
|
|
|
|
bool Verify (const EC_POINT * pub, const BIGNUM * digest, const BIGNUM * r, const BIGNUM * s);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
EC_GROUP * m_Group;
|
2017-03-14 20:41:06 +00:00
|
|
|
|
size_t m_KeyLen; // in bytes
|
2017-03-14 00:28:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<GOSTR3410Curve>& GetGOSTR3410Curve (GOSTR3410ParamSet paramSet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 20:02:16 +00:00
|
|
|
|
#endif
|