1
0
mirror of https://github.com/GOSTSec/gostcoin synced 2025-01-17 10:10:12 +00:00
gostcoin/src/Gost.h

63 lines
1.6 KiB
C
Raw Normal View History

2017-04-15 19:03:42 -04:00
/*
2018-02-13 21:53:22 +03:00
* Copyright (c) 2013-2018, The PurpleI2P Project
2017-04-15 19:03:42 -04:00
*
* This file is part of Purple i2pd project and licensed under BSD3
*
*/
2017-04-10 15:31:15 -04:00
#ifndef GOST_H__
#define GOST_H__
#include <memory>
2017-04-29 16:56:19 -04:00
#include <inttypes.h>
2017-04-10 15:31:15 -04:00
#include <openssl/ec.h>
namespace i2p
{
namespace crypto
{
// ГОСТ Р 34.10
2018-02-13 21:53:22 +03:00
2017-04-10 15:31:15 -04:00
enum GOSTR3410ParamSet
{
2018-02-13 21:53:22 +03:00
eGOSTR3410CryptoProA = 0, // 1.2.643.2.2.35.1
2017-04-10 15:31:15 -04:00
// XchA = A, XchB = C
//eGOSTR3410CryptoProXchA, // 1.2.643.2.2.36.0
2018-02-13 21:53:22 +03:00
//eGOSTR3410CryptoProXchB, // 1.2.643.2.2.36.1
eGOSTR3410TC26A512, // 1.2.643.7.1.2.1.2.1
2017-04-10 15:31:15 -04:00
eGOSTR3410NumParamSets
2018-02-13 21:53:22 +03:00
};
2017-04-10 15:31:15 -04:00
class GOSTR3410Curve
{
public:
GOSTR3410Curve (BIGNUM * a, BIGNUM * b, BIGNUM * p, BIGNUM * q, BIGNUM * x, BIGNUM * y);
2018-02-13 21:53:22 +03:00
~GOSTR3410Curve ();
2017-04-10 15:31:15 -04:00
2018-02-13 21:53:22 +03:00
size_t GetKeyLen () const { return m_KeyLen; };
2017-04-10 15:31:15 -04:00
const EC_GROUP * GetGroup () const { return m_Group; };
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);
EC_POINT * RecoverPublicKey (const BIGNUM * digest, const BIGNUM * r, const BIGNUM * s, bool isNegativeY = false) const;
2018-02-13 21:53:22 +03:00
2017-04-10 15:31:15 -04:00
private:
EC_GROUP * m_Group;
size_t m_KeyLen; // in bytes
};
std::unique_ptr<GOSTR3410Curve>& GetGOSTR3410Curve (GOSTR3410ParamSet paramSet);
// Big Endian
void GOSTR3411_2012_256 (const uint8_t * buf, size_t len, uint8_t * digest);
2018-02-13 21:53:22 +03:00
void GOSTR3411_2012_512 (const uint8_t * buf, size_t len, uint8_t * digest);
2017-04-10 15:31:15 -04:00
}
}
#endif