secp256k1

package
v0.0.0-...-9f60edc Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const FieldBytes = 32

FieldBytes is the number of bytes in the field.

Variables

This section is empty.

Functions

This section is empty.

Types

type Curve

type Curve struct{}

Curve represents the secp256k1 curve, implementing the kyokusen.Curve interface.

func (Curve) Name

func (Curve) Name() string

func (Curve) NewBasePoint

func (Curve) NewBasePoint() kyokusen.Point

func (Curve) NewPoint

func (Curve) NewPoint() kyokusen.Point

func (Curve) NewScalar

func (Curve) NewScalar() kyokusen.Scalar

func (Curve) Order

func (Curve) Order() *saferith.Modulus

func (Curve) SafeScalarBytes

func (Curve) SafeScalarBytes() int

func (Curve) ScalarBits

func (Curve) ScalarBits() int

type Field

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

Field represents an element in the prime field used by secp256k1.

This field is used later to implement point operations on the curve.

func NewField

func NewField() *Field

NewField creates a new field element, with its value set to 0.

func (*Field) Add

func (z *Field) Add(a *Field) *Field

Add calculates z <- z + a, returning z.

func (*Field) AddU64

func (z *Field) AddU64(a uint64) *Field

Add calculates z <- z + a, returning z.

This may be faster than Add.

func (*Field) CondAssign

func (z *Field) CondAssign(yes saferith.Choice, x *Field) *Field

CondAssign sets z <- x, only if yes = 1, in constant-time.

func (*Field) CondNegate

func (z *Field) CondNegate(yes saferith.Choice) *Field

CondNegate sets z <- -z, only if yes = 1, in constant-time.

func (*Field) Eq

func (z *Field) Eq(x *Field) saferith.Choice

Eq checks if two field values are equal, in constant-time.

func (*Field) EqZero

func (z *Field) EqZero() saferith.Choice

Eq checks if a field value is equal to 0, in constant-time.

func (*Field) HasSqrt

func (z *Field) HasSqrt() saferith.Choice

HasSqrt checks if a field value has a valid square root.

func (*Field) Invert

func (z *Field) Invert() *Field

Invert calculates z <- z^-1, returning z.

func (*Field) IsEven

func (z *Field) IsEven() saferith.Choice

IsEven returns a choice indicating if a field element is even.

func (*Field) MarshalBinary

func (z *Field) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

This encodes the field element as big endian bytes. The result will always occupy 32 bytes of space.

func (*Field) Mul

func (z *Field) Mul(a *Field) *Field

Mul calculates z <- z * a, returning z.

func (*Field) MulU64

func (z *Field) MulU64(a uint64) *Field

MulU64 calculates z <- z * a, returning z.

This is more efficient than Mul.

func (*Field) Negate

func (z *Field) Negate() *Field

Sub calculates z <- -z, returning z.

func (*Field) Set

func (z *Field) Set(x *Field) *Field

Set calculates z <- x, returning z.

func (*Field) SetUint64

func (z *Field) SetUint64(x uint64) *Field

SetUint64 calculates z <- x, returning z.

func (*Field) Sqrt

func (z *Field) Sqrt() *Field

Sqrt calculates z <- sqrt(z), if such a value exists. Otherwise, the result is undefined.

func (*Field) Square

func (z *Field) Square() *Field

Square calculates z <- z * z, returning z.

func (*Field) String

func (z *Field) String() string

String returns a string representation of this field element.

func (*Field) Sub

func (z *Field) Sub(a *Field) *Field

Sub calculates z <- z - a, returning z.

func (*Field) UnmarshalBinary

func (z *Field) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

This expects exactly 32 Big Endian bytes, and will also return an error if the resulting value is >= the field modulus.

type Point

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

Point represents a point on the secp256k1 curve.

func NewPoint

func NewPoint() *Point

NewPoint returns the secp256k1 identity point.

func (*Point) Add

func (p1 *Point) Add(other kyokusen.Point) kyokusen.Point

func (*Point) CondAssign

func (p *Point) CondAssign(yes saferith.Choice, other *Point) *Point

CondAssign conditionally modifies the contents of a point.

func (*Point) Curve

func (*Point) Curve() kyokusen.Curve

func (*Point) Equal

func (p1 *Point) Equal(other kyokusen.Point) bool

func (*Point) IsIdentity

func (p *Point) IsIdentity() bool

func (*Point) MarshalBinary

func (p *Point) MarshalBinary() ([]byte, error)

MarshalBinary marshals a Secp256k1 point in the same way as Bitcoin does.

The point at infinity can't be marshalled.

func (*Point) Negate

func (p *Point) Negate() kyokusen.Point

func (*Point) String

func (p *Point) String() string

func (*Point) Sub

func (p *Point) Sub(other kyokusen.Point) kyokusen.Point

func (*Point) UnmarshalBinary

func (p *Point) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshals a Secp256k1 point from Bitcoin's encoding.

func (*Point) XScalar

func (*Point) XScalar() kyokusen.Scalar

type Scalar

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

func NewScalar

func NewScalar() *Scalar

func (*Scalar) Act

func (s *Scalar) Act(other kyokusen.Point) kyokusen.Point

func (*Scalar) ActOnBase

func (s *Scalar) ActOnBase() kyokusen.Point

func (*Scalar) Add

func (s1 *Scalar) Add(other kyokusen.Scalar) kyokusen.Scalar

func (*Scalar) Curve

func (s *Scalar) Curve() kyokusen.Curve

Curve returns the curve associated with this scalar field.

func (*Scalar) Equal

func (s1 *Scalar) Equal(other kyokusen.Scalar) bool

func (*Scalar) Invert

func (s1 *Scalar) Invert() kyokusen.Scalar

func (*Scalar) IsZero

func (s1 *Scalar) IsZero() bool

func (*Scalar) MarshalBinary

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

MarshalBinary returns the contents of this scalar as Big Endian bytes.

func (*Scalar) Mul

func (s1 *Scalar) Mul(other kyokusen.Scalar) kyokusen.Scalar

func (*Scalar) Negate

func (s1 *Scalar) Negate() kyokusen.Scalar

func (*Scalar) Set

func (s1 *Scalar) Set(other kyokusen.Scalar) kyokusen.Scalar

func (*Scalar) SetNat

func (s1 *Scalar) SetNat(other *saferith.Nat) kyokusen.Scalar

func (*Scalar) String

func (s *Scalar) String() string

func (*Scalar) Sub

func (s1 *Scalar) Sub(other kyokusen.Scalar) kyokusen.Scalar

func (*Scalar) UnmarshalBinary

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

UnmarshalBinary deserializes Big Endian bytes into this scalar.

Jump to

Keyboard shortcuts

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