2013-03-10 17:25:19 -03:00
|
|
|
#ifndef _SECP256K1_NUM_OPENSSL_
|
|
|
|
#define _SECP256K1_NUM_OPENSSL_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <openssl/bn.h>
|
2013-03-13 21:20:10 -03:00
|
|
|
|
2013-03-10 17:25:19 -03:00
|
|
|
namespace secp256k1 {
|
|
|
|
|
|
|
|
class Number {
|
|
|
|
private:
|
2013-03-13 21:20:10 -03:00
|
|
|
BIGNUM b;
|
2013-03-16 11:51:55 -03:00
|
|
|
Number(const Number &x);
|
2013-03-13 21:20:10 -03:00
|
|
|
|
2013-03-16 11:51:55 -03:00
|
|
|
operator const BIGNUM*() const;
|
|
|
|
operator BIGNUM*();
|
2013-03-10 17:25:19 -03:00
|
|
|
public:
|
2013-03-16 11:51:55 -03:00
|
|
|
Number();
|
|
|
|
~Number();
|
|
|
|
Number(const unsigned char *bin, int len);
|
|
|
|
void SetNumber(const Number &x);
|
|
|
|
Number &operator=(const Number &x);
|
|
|
|
void SetBytes(const unsigned char *bin, int len);
|
|
|
|
void GetBytes(unsigned char *bin, int len);
|
|
|
|
void SetInt(int x);
|
|
|
|
void SetModInverse(const Number &x, const Number &m);
|
|
|
|
void SetModMul(const Number &a, const Number &b, const Number &m);
|
|
|
|
void SetAdd(const Number &a1, const Number &a2);
|
|
|
|
void SetSub(const Number &a1, const Number &a2);
|
|
|
|
void SetMult(const Number &a1, const Number &a2);
|
|
|
|
void SetDiv(const Number &a1, const Number &a2);
|
|
|
|
void SetMod(const Number &a, const Number &m);
|
|
|
|
int Compare(const Number &a) const;
|
|
|
|
int GetBits() const;
|
|
|
|
int ShiftLowBits(int bits);
|
|
|
|
bool IsZero() const;
|
|
|
|
bool IsOdd() const;
|
|
|
|
bool IsNeg() const;
|
2013-03-17 22:41:01 -03:00
|
|
|
bool CheckBit(int pos) const;
|
2013-03-16 11:51:55 -03:00
|
|
|
void Negate();
|
|
|
|
void Shift1();
|
|
|
|
void Inc();
|
|
|
|
void SetHex(const std::string &str);
|
|
|
|
void SetPseudoRand(const Number &max);
|
|
|
|
void SplitInto(int bits, Number &low, Number &high) const;
|
|
|
|
std::string ToString() const;
|
2013-03-10 17:25:19 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|