secp256k1

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 7 Imported by: 0

README

Secp256k1

secp256k1 Go Reference codecov

  import "github.com/bytemare/secp256k1"

This package implements the Secp256k1 prime-order elliptic curve group with hash-to-curve capabilities and complete addition formulas.

Documentation Go Reference

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

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.

Documentation

Overview

Package secp256k1 allows simple and abstracted operations in the Secp256k1 group.

Index

Constants

View Source
const (
	// H2CSECP256K1 represents the hash-to-curve string identifier for Secp256k1.
	H2CSECP256K1 = "secp256k1_XMD:SHA-256_SSWU_RO_"

	// E2CSECP256K1 represents the encode-to-curve string identifier for Secp256k1.
	E2CSECP256K1 = "secp256k1_XMD:SHA-256_SSWU_NU_"
)

Variables

This section is empty.

Functions

func Ciphersuite

func Ciphersuite() string

Ciphersuite returns the hash-to-curve ciphersuite identifier.

func ElementLength

func ElementLength() int

ElementLength returns the byte size of an encoded element.

func Order

func Order() string

Order returns the order of the canonical group of scalars.

func ScalarLength

func ScalarLength() int

ScalarLength returns the byte size of an encoded scalar.

Types

type Element

type Element struct {
	// contains filtered or unexported fields
}

Element implements the Element interface for the Secp256k1 group element.

func Base

func Base() *Element

Base returns the group's base point a.k.a. canonical generator.

func EncodeToGroup

func EncodeToGroup(input, dst []byte) *Element

EncodeToGroup returns a non-uniform mapping of the arbitrary input to an Element in the Group. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func HashToGroup

func HashToGroup(input, dst []byte) *Element

HashToGroup returns a safe mapping of the arbitrary input to an Element in the Group. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func NewElement

func NewElement() *Element

NewElement returns a new element set to the identity point.

func (*Element) Add

func (e *Element) Add(element *Element) *Element

Add sets the receiver to the sum of the input and the receiver, and returns the receiver.

func (*Element) Base

func (e *Element) Base() *Element

Base sets the element to the group's base point a.k.a. canonical generator.

func (*Element) Copy

func (e *Element) Copy() *Element

Copy returns a copy of the receiver.

func (*Element) Decode

func (e *Element) Decode(data []byte) error

Decode sets the receiver to a decoding of the input data, and returns an error on failure.

func (*Element) Double

func (e *Element) Double() *Element

Double sets the receiver to its double, and returns it.

func (*Element) Encode

func (e *Element) Encode() []byte

Encode returns the compressed byte encoding of the element.

func (*Element) Equal

func (e *Element) Equal(element *Element) int

Equal returns 1 if the elements are equivalent, and 0 otherwise.

func (*Element) Identity

func (e *Element) Identity() *Element

Identity sets the element to the point at infinity of the Group's underlying curve.

func (*Element) IsIdentity

func (e *Element) IsIdentity() bool

IsIdentity returns whether the Element is the point at infinity of the Group's underlying curve.

func (*Element) MarshalBinary

func (e *Element) MarshalBinary() ([]byte, error)

MarshalBinary returns the compressed byte encoding of the element.

func (*Element) Multiply

func (e *Element) Multiply(scalar *Scalar) *Element

Multiply sets the receiver to the scalar multiplication of the receiver with the given Scalar, and returns it.

func (*Element) Negate

func (e *Element) Negate() *Element

Negate sets the receiver to its negation, and returns it.

func (*Element) Set

func (e *Element) Set(element *Element) *Element

Set sets the receiver to the value of the argument, and returns the receiver.

func (*Element) Subtract

func (e *Element) Subtract(element *Element) *Element

Subtract subtracts the input from the receiver, and returns the receiver.

func (*Element) UnmarshalBinary

func (e *Element) UnmarshalBinary(data []byte) error

UnmarshalBinary sets e to the decoding of the byte encoded element.

func (*Element) XCoordinate

func (e *Element) XCoordinate() []byte

XCoordinate returns the encoded x coordinate of the element, which is the same as Encode().

type Scalar

type Scalar struct {
	// contains filtered or unexported fields
}

Scalar implements the Scalar interface for Edwards25519 group scalars.

func HashToScalar

func HashToScalar(input, dst []byte) *Scalar

HashToScalar returns a safe mapping of the arbitrary input to a Scalar. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func NewScalar

func NewScalar() *Scalar

NewScalar returns a new scalar set to 0.

func (*Scalar) Add

func (s *Scalar) Add(scalar *Scalar) *Scalar

Add sets the receiver to the sum of the input and the receiver, and returns the receiver.

func (*Scalar) Copy

func (s *Scalar) Copy() *Scalar

Copy returns a copy of the receiver.

func (*Scalar) Decode

func (s *Scalar) Decode(in []byte) error

Decode sets the receiver to a decoding of the input data, and returns an error on failure.

func (*Scalar) Encode

func (s *Scalar) Encode() []byte

Encode returns the compressed byte encoding of the scalar.

func (*Scalar) Equal

func (s *Scalar) Equal(scalar *Scalar) int

Equal returns 1 if the scalars are equal, and 0 otherwise.

func (*Scalar) Invert

func (s *Scalar) Invert() *Scalar

Invert sets the receiver to its modular inverse ( 1 / s ), and returns it.

func (*Scalar) IsZero

func (s *Scalar) IsZero() bool

IsZero returns whether the scalar is 0.

func (*Scalar) LessOrEqual

func (s *Scalar) LessOrEqual(scalar *Scalar) int

LessOrEqual returns 1 if s <= scalar and 0 otherwise.

func (*Scalar) MarshalBinary

func (s *Scalar) MarshalBinary() ([]byte, error)

MarshalBinary returns the compressed byte encoding of the scalar.

func (*Scalar) Multiply

func (s *Scalar) Multiply(scalar *Scalar) *Scalar

Multiply multiplies the receiver with the input, and returns the receiver.

func (*Scalar) One

func (s *Scalar) One() *Scalar

One sets the scalar to 1, and returns it.

func (*Scalar) Pow

func (s *Scalar) Pow(scalar *Scalar) *Scalar

Pow sets s to s**scalar modulo the group order, and returns s. If scalar is nil, it returns 1.

func (*Scalar) Random

func (s *Scalar) Random() *Scalar

Random sets the current scalar to a new random scalar and returns it. The random source is crypto/rand, and this functions is guaranteed to return a non-zero scalar.

func (*Scalar) Set

func (s *Scalar) Set(scalar *Scalar) *Scalar

Set sets the receiver to the value of the argument scalar, and returns the receiver.

func (*Scalar) SetInt

func (s *Scalar) SetInt(i *big.Int) error

SetInt sets s to i modulo the field order, and returns an error if one occurs.

func (*Scalar) Subtract

func (s *Scalar) Subtract(scalar *Scalar) *Scalar

Subtract subtracts the input from the receiver, and returns the receiver.

func (*Scalar) UnmarshalBinary

func (s *Scalar) UnmarshalBinary(data []byte) error

UnmarshalBinary sets e to the decoding of the byte encoded scalar.

func (*Scalar) Zero

func (s *Scalar) Zero() *Scalar

Zero sets the scalar to 0, and returns it.

Directories

Path Synopsis
internal
field
Package field provides modular operations over very high integers.
Package field provides modular operations over very high integers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL