secp256k1

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package secp256k1 implements secp256k1-related functions and types.

  • the elliptic curve secp256k1 itself (Compressed, Point and functions with prefix GE)
  • scalar values (Scalar and functions with prefix SC)
  • utility functions

Index

Constants

This section is empty.

Variables

View Source
var ErrorInvalidPoint = errors.New("invalid point on secp256k1")

ErrorInvalidPoint is returned when an invalid point was found. The reasons why a point is invalid include:

  • invalid header (neither 02 nor 03)
  • could not find the y coordinate
View Source
var Order = [32]byte(nBytes) // The order of secp256k1, namely 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141.
View Source
var P = [32]byte(pBytes) // P is the order of the defining field F_p, namely 2^256 - 2^32 - 977.

Functions

func CompareBytes

func CompareBytes(a [32]byte, b [32]byte) int

CompareBytes compares two 32-byte arrays in constant-time.

The return value is one of {-1, 0, 1}.

  • -1: a < b
  • 0: a = b
  • 1: a > b

func SCIsValid

func SCIsValid(a Scalar) int

SCIsValid returns a < Order. It runs in constant-time.

Types

type Compressed

type Compressed [33]byte

Compressed is a compressed (33-byte, x-coordinate + y mod 2) representation of a point on secp256k1. Its zero value is invalid. It cannot represent the infinity (zero element).

func (Compressed) Uncompress

func (a Compressed) Uncompress() (*Point, error)

type Point

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

Point retains a point in Jacobian coordinates.

Two distinct representations can represent the same point, so you cannot simply compare two Points with == to check if they are equal. You need to first compress them into Compressed and then compare.

Its zero value is invalid.

func GEAdd

func GEAdd(a *Point, b *Point) *Point

GEAdd computes a + b. It runs in constant-time.

func GEDouble

func GEDouble(p *Point) *Point

GEDouble computes 2p. It runs in constant-time.

func GEPoint

func GEPoint(n Scalar) *Point

GEPoint computes n G where G is the base point. It runs in constant-time.

func GEVartimePoint

func GEVartimePoint(n Scalar) *Point

GEVartimePoint computes n G where G is the base point. It does not have a constant-time guarantee, but it is faster than GEPoint.

func (*Point) Compress

func (p *Point) Compress() Compressed

Compress returns the value in the compressed format. It runs in constant-time.

type Scalar

type Scalar [32]byte

Scalar represents an integer mod Order. Its zero value represents 0 mod Order.

func SCAdd

func SCAdd(a Scalar, b Scalar) Scalar

SCAdd returns (a + b) mod Order. It runs in constant-time.

Jump to

Keyboard shortcuts

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