secp256k1

package
v2.10.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 18 Imported by: 3

Documentation

Overview

Package secp256k1 is an implementation of the kyber.{Group,Point,Scalar} //////////////////////////////////////////////////////////////////////////////

XXX: Do not use in production until this code has been audited.

////////////////////////////////////////////////////////////////////////////// interfaces, based on btcd/btcec and kyber/group/mod

XXX: NOT CONSTANT TIME!

Package secp256k1 is an implementation of the kyber.{Group,Point,Scalar} //////////////////////////////////////////////////////////////////////////////

XXX: Do not use in production until this code has been audited.

////////////////////////////////////////////////////////////////////////////// interfaces, based on btcd/btcec and kyber/group/mod

XXX: NOT CONSTANT TIME!

Package secp256k1 is an implementation of the kyber.{Group,Point,Scalar} //////////////////////////////////////////////////////////////////////////////

XXX: Do not use in production until this code has been audited.

////////////////////////////////////////////////////////////////////////////// interfaces, based on btcd/btcec and kyber/group/mod

XXX: NOT CONSTANT TIME!

Package secp256k1 is an implementation of the kyber.{Group,Point,Scalcar} //////////////////////////////////////////////////////////////////////////////

XXX: Do not use in production until this code has been audited.

////////////////////////////////////////////////////////////////////////////// interfaces, based on btcd/btcec and kyber/group/mod

XXX: NOT CONSTANT TIME!

Package secp256k1 is an implementation of the kyber.{Group,Point,Scalar} //////////////////////////////////////////////////////////////////////////////

XXX: Do not use in production until this code has been audited.

////////////////////////////////////////////////////////////////////////////// interfaces, based on btcd/btcec and kyber/group/mod

XXX: NOT CONSTANT TIME!

Index

Constants

View Source
const CompressedPublicKeyLength = 33

CompressedPublicKeyLength is the length of a secp256k1 public key's x coordinate as a uint256, concatenated with 00 if y is even, 01 if odd.

Variables

View Source
var FieldSize = secp256k1BTCD.S256().P
View Source
var GroupOrder = secp256k1BTCD.S256().N

Functions

func Coordinates

func Coordinates(p kyber.Point) (*big.Int, *big.Int)

Coordinates returns the coordinates of p

func EthereumAddress

func EthereumAddress(p kyber.Point) (rv [20]byte)

EthereumAddress returns the 160-bit address corresponding to p as public key.

func Generate

func Generate(random cipher.Stream) *key.Pair

Generate generates a public/private key pair, which can be verified cheaply on-chain

func IntToScalar

func IntToScalar(i *big.Int) kyber.Scalar

IntToScalar returns i wrapped as a big.Int.

May modify i to reduce mod GroupOrder

func IsSecp256k1Point

func IsSecp256k1Point(p kyber.Point) bool

IsSecp256k1Point returns true if p is a secp256k1Point

func IsSecp256k1Scalar

func IsSecp256k1Scalar(s kyber.Scalar) bool

IsSecp256k1Scalar returns true if p is a secp256k1Scalar

func LongMarshal

func LongMarshal(p kyber.Point) []byte

LongMarshal returns the concatenated coordinates serialized as uint256's

func LongUnmarshal

func LongUnmarshal(m []byte) (kyber.Point, error)

LongUnmarshal returns the secp256k1 point represented by m, as a concatenated pair of uint256's

func RepresentsScalar

func RepresentsScalar(i *big.Int) bool

RepresentsScalar returns true iff i is in the right range to be a scalar

func ScalarToHash

func ScalarToHash(s kyber.Scalar) common.Hash

func ScalarToPublicPoint

func ScalarToPublicPoint(s kyber.Scalar) kyber.Point

ScalarToPublicPoint returns the public secp256k1 point associated to s

func SetCoordinates

func SetCoordinates(x, y *big.Int) kyber.Point

SetCoordinates returns the point (x,y), or panics if an invalid secp256k1Point

func ToInt

func ToInt(s kyber.Scalar) *big.Int

func ValidPublicKey

func ValidPublicKey(p kyber.Point) bool

ValidPublicKey returns true iff p can be used in the optimized on-chain Schnorr-signature verification. See SchnorrSECP256K1.sol for details.

Types

type PublicKey

PublicKey is a secp256k1 point in compressed format

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(rawKey []byte) (PublicKey, error)

NewPublicKeyFromBytes returns the PublicKey built from the given bytes, or errors

func NewPublicKeyFromHex

func NewPublicKeyFromHex(hex string) (PublicKey, error)

NewPublicKeyFromHex returns the PublicKey encoded by 0x-hex string hex, or errors

func (*PublicKey) Address

func (k *PublicKey) Address() common.Address

Address returns the Ethereum address of k or 0 if the key is invalid

func (*PublicKey) Hash

func (k *PublicKey) Hash() (common.Hash, error)

Hash returns the solidity Keccak256 hash of k. Corresponds to hashOfKey on VRFCoordinator.

func (*PublicKey) IsZero

func (k *PublicKey) IsZero() bool

IsZero returns true iff k is the zero value for PublicKey

func (PublicKey) MarshalText

func (k PublicKey) MarshalText() ([]byte, error)

MarshalText renders k as a text string

func (*PublicKey) MustHash

func (k *PublicKey) MustHash() common.Hash

MustHash is like Hash, but panics on error. Useful for testing.

func (*PublicKey) Point

func (k *PublicKey) Point() (kyber.Point, error)

Point returns the secp256k1 point corresponding to k

func (*PublicKey) Scan

func (k *PublicKey) Scan(value interface{}) error

Scan reconstructs a PublicKey from a DB record of it.

func (*PublicKey) Set

func (k *PublicKey) Set(l PublicKey)

Set sets k to the public key represented by l

func (*PublicKey) SetFromHex

func (k *PublicKey) SetFromHex(hex string) error

SetFromHex sets k to the public key represented by hex, which must represent the compressed binary format

func (PublicKey) String

func (k PublicKey) String() string

String returns k's binary compressed representation, as 0x-hex

func (*PublicKey) StringUncompressed

func (k *PublicKey) StringUncompressed() (string, error)

StringUncompressed returns k's binary uncompressed representation, as 0x-hex

func (*PublicKey) UnmarshalText

func (k *PublicKey) UnmarshalText(text []byte) error

UnmarshalText reads a PublicKey into k from text, or errors

func (PublicKey) Value

func (k PublicKey) Value() (driver.Value, error)

Value marshals PublicKey to be saved in the DB

type Secp256k1

type Secp256k1 struct{}

Secp256k1 represents the secp256k1 group. There are no parameters and no initialization is required because it supports only this one specific curve.

func (*Secp256k1) Point

func (*Secp256k1) Point() kyber.Point

Point returns a new secp256k1 point

func (*Secp256k1) PointLen

func (*Secp256k1) PointLen() int

PointLen returns the length of a marshalled Point

func (*Secp256k1) Scalar

func (*Secp256k1) Scalar() kyber.Scalar

Scalar creates a new Scalar for the prime-order group on the secp256k1 curve

func (*Secp256k1) ScalarLen

func (*Secp256k1) ScalarLen() int

ScalarLen returns the length of a marshalled Scalar

func (*Secp256k1) String

func (*Secp256k1) String() string

String returns the name of the curve

type SuiteSecp256k1

type SuiteSecp256k1 struct {
	Secp256k1
	// contains filtered or unexported fields
}

SuiteSecp256k1 implements some basic functionalities such as Group, HashFactory, and XOFFactory.

func NewBlakeKeccackSecp256k1

func NewBlakeKeccackSecp256k1() *SuiteSecp256k1

NewBlakeKeccackSecp256k1 returns a cipher suite based on package go.dedis.ch/kyber/xof/blake2xb, SHA-256, and the secp256k1 curve. It produces cryptographically secure random numbers via package crypto/rand.

func (*SuiteSecp256k1) Hash

func (s *SuiteSecp256k1) Hash() hash.Hash

Hash returns a newly instantiated keccak hash function.

func (*SuiteSecp256k1) New

func (s *SuiteSecp256k1) New(t reflect.Type) interface{}

New implements the kyber.Encoding interface, and returns a new element of type t, which can be a Point or a Scalar

func (*SuiteSecp256k1) RandomStream

func (s *SuiteSecp256k1) RandomStream() cipher.Stream

RandomStream returns a cipher.Stream that returns a key stream from crypto/rand.

func (*SuiteSecp256k1) Read

func (s *SuiteSecp256k1) Read(r io.Reader, objs ...interface{}) error

Read implements the Encoding interface function, and reads a series of objs from r The objs must all be pointers

func (*SuiteSecp256k1) Write

func (s *SuiteSecp256k1) Write(w io.Writer, objs ...interface{}) error

Write implements the Encoding interface, and writes the objs to r using their built-in binary serializations. Supports Points, Scalars, fixed-length data types supported by encoding/binary/Write(), and structs, arrays, and slices containing these types.

func (*SuiteSecp256k1) XOF

func (s *SuiteSecp256k1) XOF(key []byte) kyber.XOF

XOF returns an XOR function, implemented via the Blake2b hash.

This should only be used for generating secrets, so there is no need to make it cheap to compute on-chain.

Jump to

Keyboard shortcuts

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