nav-io / navio-core

Navio Core v8 [WIP]
https://nav.io
MIT License
3 stars 6 forks source link

crypto: create classes for arithmetic operations on the bls12-381 curve #14

Closed aguycalled closed 2 years ago

aguycalled commented 2 years ago

Depends on #11

Two serialisable classes need to be created in src/blsct/arith/:

implementing operator overload for the arithmetic operations provided by herumi/mcl.

Additional bitwise operations need to be implemented, which are not covered by herumi/mcl.

Scalar interface

    Scalar(const uint64_t& n = 0);
    Scalar(const std::vector<uint8_t> &v);
    Scalar(const Scalar& n);
    Scalar(const uint256& n);

    void operator=(const uint64_t& n);

    Scalar operator+(const Scalar &b) const;
    Scalar operator-(const Scalar &b) const;
    Scalar operator*(const Scalar &b) const;
    Scalar operator/(const Scalar &b) const;
    Scalar operator|(const Scalar &b) const;
    Scalar operator^(const Scalar &b) const;
    Scalar operator&(const Scalar &b) const;
    Scalar operator~() const;
    Scalar operator<<(const int &b) const;
    Scalar operator>>(const int &b) const;

    bool operator==(const Scalar& b) const;
    bool operator==(const int &b) const;

    Scalar Invert() const;
    Scalar Negate() const;

    static Scalar Rand();
    static Scalar hashAndMap(std::vector<unsigned char>);

    bool GetBit(size_t n) const;
    int64_t GetInt64() const;

    std::vector<uint8_t> GetVch() const;
    void SetVch(const std::vector<uint8_t>& b);

    void SetPow2(const int& n);

    uint256 Hash(const int& n) const;

    std::string GetString();

G1Point interface

    G1Point();
    G1Point(const std::vector<uint8_t>& v);
    G1Point(const G1Point& n);
    G1Point(const uint256 &b);

    G1Point operator+(const Point &b) const;
    G1Point operator-(const Point &b) const;
    G1Point operator*(const Scalar &b) const;

    G1Point Normalize() const;
    G1Point Double() const;

    static G1Point getBasePoint();
    static G1Point hashAndMap(std::vector<unsigned char>);
    static G1Point mulVec(std::vector<G1Point>, std::vector<Scalar>);

    bool operator==(const Point& b) const;

    static G1Point Rand();

    bool IsUnity() const;

    std::vector<uint8_t> GetVch() const;
    void SetVch(const std::vector<uint8_t>& b);

    std::string GetString();

Documentation reference

https://github.com/herumi/mcl/blob/master/api.md

aguycalled commented 2 years ago

Old code references

https://github.com/navcoin/navcoin-core/blob/master/src/blsct/scalar.cpp https://github.com/navcoin/navcoin-core/blob/master/src/blsct/scalar.h https://github.com/0x2830/navcoin-core/blob/blsct/src/blsct/types.cpp https://github.com/0x2830/navcoin-core/blob/blsct/src/blsct/types.h

aguycalled commented 2 years ago

closing issue as pr has already been merged