You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bitcoin/group.h

113 lines
2.5 KiB

12 years ago
#ifndef _SECP256K1_GROUP_
#define _SECP256K1_GROUP_
#include <string>
#include "num.h"
12 years ago
#include "field.h"
namespace secp256k1 {
12 years ago
class GroupElemJac;
12 years ago
/** Defines a point on the secp256k1 curve (y^2 = x^3 + 7) */
class GroupElem {
protected:
bool fInfinity;
FieldElem x;
FieldElem y;
public:
/** Creates the point at infinity */
GroupElem();
12 years ago
/** Creates the point with given affine coordinates */
GroupElem(const FieldElem &xin, const FieldElem &yin);
12 years ago
/** Checks whether this is the point at infinity */
bool IsInfinity() const;
12 years ago
void SetNeg(const GroupElem &p);
12 years ago
void GetX(FieldElem &xout);
12 years ago
void GetY(FieldElem &yout);
12 years ago
std::string ToString() const;
12 years ago
void SetJac(GroupElemJac &jac);
12 years ago
12 years ago
friend class GroupElemJac;
};
/** Represents a point on the secp256k1 curve, with jacobian coordinates */
12 years ago
class GroupElemJac : private GroupElem {
12 years ago
protected:
FieldElem z;
public:
/** Creates the point at infinity */
GroupElemJac();
12 years ago
/** Creates the point with given affine coordinates */
GroupElemJac(const FieldElem &xin, const FieldElem &yin);
12 years ago
GroupElemJac(const GroupElem &in);
12 years ago
12 years ago
void SetJac(const GroupElemJac &jac);
void SetAffine(const GroupElem &aff);
12 years ago
12 years ago
/** Checks whether this is a non-infinite point on the curve */
bool IsValid() const;
12 years ago
/** Returns the affine coordinates of this point */
void GetAffine(GroupElem &aff);
void GetX(FieldElem &xout);
void GetY(FieldElem &yout);
bool IsInfinity() const;
void SetNeg(const GroupElemJac &p);
12 years ago
12 years ago
/** Sets this point to have a given X coordinate & given Y oddness */
void SetCompressed(const FieldElem &xin, bool fOdd);
12 years ago
/** Sets this point to be the EC double of another */
void SetDouble(const GroupElemJac &p);
12 years ago
/** Sets this point to be the EC addition of two others */
void SetAdd(const GroupElemJac &p, const GroupElemJac &q);
12 years ago
/** Sets this point to be the EC addition of two others (one of which is in affine coordinates) */
void SetAdd(const GroupElemJac &p, const GroupElem &q);
std::string ToString() const;
12 years ago
void SetMulLambda(const GroupElemJac &p);
12 years ago
};
12 years ago
class GroupConstants {
private:
const FieldElem g_x;
const FieldElem g_y;
public:
const Number order;
const GroupElem g;
12 years ago
const FieldElem beta;
const Number lambda, a1b2, b1, a2;
12 years ago
GroupConstants();
12 years ago
};
const GroupConstants &GetGroupConst();
12 years ago
void SplitExp(const Number &exp, Number &exp1, Number &exp2);
12 years ago
12 years ago
}
#endif