package
1.2.17
Repository: https://github.com/hubmakerlabs/replicatr.git
Documentation: pkg.go.dev

# README

secp256k1

Due to the terrible state of the btcec library, and the ethical character of dcred, the two main secp256k1 EC libraries in the Go language, it has become necessary to refactor and clean up the mess of btcec's module versioning.

In addition, the code has been updated to use several new features of Go that were added to the language since these libraries were first created, notably the precomps are here directly generated as binary data instead of nasty base64 source code.

Package secp256k1 implements optimized secp256k1 elliptic curve operations.

This package provides an optimized pure Go implementation of elliptic curve cryptography operations over the secp256k1 curve as well as data structures and functions for working with public and secret secp256k1 keys. See https://www.secg.org/sec2-v2.pdf for details on the standard.

In addition, sub packages are provided to produce, verify, parse, and serialize ECDSA signatures and EC-Schnorr-DCRv0 (a custom Schnorr-based signature scheme specific to Decred) signatures. See the README.md files in the relevant sub packages for more details about those aspects.

An overview of the features provided by this package are as follows:

  • Secret key generation, serialization, and parsing
  • Public key generation, serialization and parsing per ANSI X9.62-1998
    • Parses uncompressed, compressed, and hybrid public keys
    • Serializes uncompressed and compressed public keys
  • Specialized types for performing optimized and constant time field operations
    • FieldVal type for working modulo the secp256k1 field prime
    • ModNScalar type for working modulo the secp256k1 group order
  • Elliptic curve operations in Jacobian projective coordinates
    • Point addition
    • Point doubling
    • Scalar multiplication with an arbitrary point
    • Scalar multiplication with the base point (group generator)
  • Point decompression from a given x coordinate
  • Nonce generation via RFC6979 with support for extra data and version information that can be used to prevent nonce reuse between signing algorithms

It also provides an implementation of the Go standard library crypto/elliptic Curve interface via the S256 function so that it may be used with other packages in the standard library such as crypto/tls, crypto/x509, and crypto/ecdsa. However, in the case of ECDSA, it is highly recommended to use the ecdsa sub package of this package instead since it is optimized specifically for secp256k1 and is significantly faster as a result.

Although this package was primarily written for dcrd, it has intentionally been designed so it can be used as a standalone package for any projects needing to use optimized secp256k1 elliptic curve cryptography.

Finally, a comprehensive suite of tests is provided to provide a high level of quality assurance.

# Packages

No description provided by the author

# Functions

AddNonConst adds the passed Jacobian points together and stores the result in the provided result param in *non-constant* time.
DecompressY attempts to calculate the Y coordinate for the given X coordinate such that the result pair is a point on the secp256k1 curve.
DoubleNonConst doubles the passed Jacobian point and stores the result in the provided result parameter in *non-constant* time.
GenerateSecretKey generates and returns a new cryptographically secure secret key that is suitable for use with secp256k1.
GenerateSecretKeyFromRand generates a secret key that is suitable for use with secp256k1 using the provided reader as a source of entropy.
GenerateSharedSecret generates a shared secret based on a secret key and a public key using Diffie-Hellman key exchange (ECDH) (RFC 5903).
MakeJacobianPoint returns a Jacobian point with the provided X, Y, and Z coordinates.
NewPublicKey instantiates a new public key with the given x and y coordinates.
NewSecretKey instantiates a new secret key from a scalar encoded as a big integer.
NonceRFC6979 generates a nonce deterministically according to RFC 6979 using HMAC-SHA256 for the hashing function.
Params returns the secp256k1 curve parameters for convenience.
ParsePubKey parses a secp256k1 public key encoded according to the format specified by ANSI X9.62-1998, which means it is also compatible with the SEC (Standards for Efficient Cryptography) specification which is a subset of the former.
S256 returns an elliptic.Curve which implements secp256k1.
ScalarBaseMultNonConst multiplies k*G where k is a scalar modulo the curve order and G is the base point of the group and stores the result in the provided Jacobian point.
ScalarMultNonConst multiplies k*P where k is a scalar modulo the curve order and P is a point in Jacobian projective coordinates and stores the result in the provided Jacobian point.
SecKeyFromBytes returns a secret based on the provided byte slice which is interpreted as an unsigned 256-bit big-endian integer in the range [0, N-1], where N is the order of the curve.

# Constants

ErrPubKeyInvalidFormat indicates an attempt was made to parse a public key that does not specify one of the supported formats.
ErrPubKeyInvalidLen indicates that the length of a serialized public key is not one of the allowed lengths.
ErrPubKeyMismatchedOddness indicates that a hybrid public key specified an oddness of the y coordinate that does not match the actual oddness of the provided y coordinate.
ErrPubKeyNotOnCurve indicates that a public key is not a point on the secp256k1 curve.
ErrPubKeyXTooBig indicates that the x coordinate for a public key is greater than or equal to the prime of the field underlying the group.
ErrPubKeyYTooBig indicates that the y coordinate for a public key is greater than or equal to the prime of the field underlying the group.
PubKeyBytesLenCompressed is the number of bytes of a serialized compressed public key.
PubKeyBytesLenUncompressed is the number of bytes of a serialized uncompressed public key.
PubKeyFormatCompressedEven is the identifier prefix byte for a public key whose Y coordinate is even when serialized in the compressed format per section 2.3.4 of [SEC1](https://secg.org/sec1-v2.pdf#subsubsection.2.3.4).
PubKeyFormatCompressedOdd is the identifier prefix byte for a public key whose Y coordinate is odd when serialized in the compressed format per section 2.3.4 of [SEC1](https://secg.org/sec1-v2.pdf#subsubsection.2.3.4).
PubKeyFormatHybridEven is the identifier prefix byte for a public key whose Y coordinate is even when serialized according to the hybrid format per section 4.3.6 of [ANSI X9.62-1998].
PubKeyFormatHybridOdd is the identifier prefix byte for a public key whose Y coordingate is odd when serialized according to the hybrid format per section 4.3.6 of [ANSI X9.62-1998].
PubKeyFormatUncompressed is the identifier prefix byte for a public key when serialized according in the uncompressed format per section 2.3.3 of [SEC1](https://secg.org/sec1-v2.pdf#subsubsection.2.3.3).
SecKeyBytesLen defines the length in bytes of a serialized secret key.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

CurveParams contains the parameters for the secp256k1 curve.
Error identifies an error related to public key cryptography using a sec256k1 curve.
FieldVal implements optimized fixed-precision arithmetic over the secp256k1 finite field.
JacobianPoint is an element of the group formed by the secp256k1 curve in Jacobian projective coordinates and thus represents a point on the curve.
KoblitzCurve provides an implementation for secp256k1 that fits the ECC Curve interface from crypto/elliptic.
ModNScalar implements optimized 256-bit constant-time fixed-precision arithmetic over the secp256k1 group order.
PublicKey provides facilities for efficiently working with secp256k1 public keys within this package and includes functions to serialize in both uncompressed and compressed SEC (Standards for Efficient Cryptography) formats.
SecretKey provides facilities for working with secp256k1 secret keys within this package and includes functionality such as serializing and parsing them as well as computing their associated public key.

# Type aliases

ErrorKind identifies a kind of error.
No description provided by the author