Skip to content

bytemare/crypto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prime-order Elliptic Curve Groups

CI Go Reference codecov

  import "github.com/bytemare/crypto"

This package exposes abstract operations over opaque prime-order elliptic curve groups and their scalars and elements, and support hash-to-curve as per RFC 9380.

It is made so you can swap between primitives with no code change and only the Group identifier. The package serves as an interface to optimized and secure implementations that serve as backends, and to which you don't need to adapt.

The following table indexes supported groups with hash-to-curve capability and links each one to the underlying implementations:

ID Name Backend
1 Ristretto255 github.com/gtank/ristretto255
2 Decaf448 not supported
3 P-256 filippo.io/nistec
4 P-384 filippo.io/nistec
5 P-521 filippo.io/nistec
6 Edwards25519 filippo.io/edwards25519
7 Secp256k1 github.com/bytemare/secp256k1
8 Double-Odd not yet supported

Prime-order group interface

This package exposes types that can handle different implementations under the hood, internally using an interface to the group and its scalars and elements, but you don't need to instantiate or implement anything. Just use the type in the top package.

Group interface

// Group abstracts operations in a prime-order group.
type Group interface {
    NewScalar() Scalar
    NewElement() Element
    Base() Element
    HashToScalar(input, dst []byte) Scalar
    HashToGroup(input, dst []byte) Element
    EncodeToGroup(input, dst []byte) Element
    Ciphersuite() string
    ScalarLength() int
    ElementLength() int
    Order() string
}

Scalar interface

// Scalar interface abstracts common operations on scalars in a prime-order Group.
type Scalar interface {
    Zero() Scalar
    One() Scalar
    Random() Scalar
    Add(Scalar) Scalar
    Subtract(Scalar) Scalar
    Multiply(Scalar) Scalar
    Pow(Scalar) Scalar
    Invert() Scalar
    Equal(Scalar) int
    LessOrEqual(Scalar) int
    IsZero() bool
    Set(Scalar) Scalar
    SetInt(big.Int) error
    Copy() Scalar
    Encode() []byte
    Decode(in []byte) error
    encoding.BinaryMarshaler
    encoding.BinaryUnmarshaler
}

Element interface

// Element interface abstracts common operations on an Element in a prime-order Group.
type Element interface {
    Base() Element
    Identity() Element
    Add(Element) Element
    Double() Element
    Negate() Element
    Subtract(Element) Element
    Multiply(Scalar) Element
    Equal(element Element) int
    IsIdentity() bool
    Set(Element) Element
    Copy() Element
    Encode() []byte
    XCoordinate() []byte
    Decode(data []byte) error
    encoding.BinaryMarshaler
    encoding.BinaryUnmarshaler
}

Documentation Go Reference

You can find the documentation and usage examples in the package doc and the project wiki .

Versioning

SemVer is used for versioning. For the versions available, see the tags on the repository.

Contributing

Please read CONTRIBUTING.md for details on the code of conduct, and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.