Categorygithub.com/btcsuite/btcd/btcec/v2
modulepackage
2.3.4
Repository: https://github.com/btcsuite/btcd.git
Documentation: pkg.go.dev

# README

btcec

Build Status ISC License GoDoc

Package btcec implements elliptic curve cryptography needed for working with Bitcoin (secp256k1 only for now). It is designed so that it may be used with the standard crypto/ecdsa packages provided with go. A comprehensive suite of test is provided to ensure proper functionality. Package btcec was originally based on work from ThePiachu which is licensed under the same terms as Go, but it has significantly diverged since then. The btcsuite developers original is licensed under the liberal ISC license.

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

Installation and Updating

$ go install -u -v github.com/btcsuite/btcd/btcec/v2

Examples

  • Sign Message
    Demonstrates signing a message with a secp256k1 private key that is first parsed form raw bytes and serializing the generated signature.

  • Verify Signature
    Demonstrates verifying a secp256k1 signature against a public key that is first parsed from raw bytes. The signature is also parsed from raw bytes.

License

Package btcec is licensed under the copyfree ISC License except for btcec.go and btcec_test.go which is under the same license as Go.

# Packages

# 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.
GenerateSharedSecret generates a shared secret based on a private key and a public key using Diffie-Hellman key exchange (ECDH) (RFC 4753).
Generator returns the public key at the Generator Point.
GeneratorJacobian sets the passed JacobianPoint to the Generator Point.
IsCompressedPubKey returns true the passed serialized public key has been encoded in compressed format, and false otherwise.
JacobianToByteSlice converts the passed JacobianPoint to a Pubkey and serializes that to a byte slice.
MakeJacobianPoint returns a Jacobian point with the provided X, Y, and Z coordinates.
NewPrivateKey is a wrapper for ecdsa.GenerateKey that returns a PrivateKey instead of the normal ecdsa.PrivateKey.
NewPublicKey instantiates a new public key with the given x and y coordinates.
NonceRFC6979 generates a nonce deterministically according to RFC 6979 using HMAC-SHA256 for the hashing function.
Params returns the secp256k1 curve parameters for convenience.
ParseJacobian parses a byte slice point as a secp.Publickey and returns the pubkey as a JacobianPoint.
ParsePubKey parses a public key for a koblitz curve from a bytestring into a ecdsa.Publickey, verifying that it is valid.
PrivKeyFromBytes returns a private and public key for `curve' based on the private key passed as an argument as a byte slice.
PrivKeyFromScalar instantiates a new private key from a scalar encoded as a big integer.
S256 returns a Curve which implements secp256k1.
ScalarBaseMultNonConst multiplies k*G where G is the base point of the group and k is a big endian integer.
ScalarMultNonConst multiplies k*P where k is a big endian integer modulo the curve order and P is a point in Jacobian projective coordinates and stores the result in the provided Jacobian point.
ToSerialized serializes a public key into its compressed form.

# Constants

PrivKeyBytesLen defines the length in bytes of a serialized private key.
PubKeyBytesLenCompressed is the bytes length of a serialized compressed public key.

# Type aliases

CurveParams contains the parameters for the secp256k1 curve.
Error identifies an error related to public key cryptography using a sec256k1 curve.
ErrorKind identifies a kind of error.
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.
PrivateKey wraps an ecdsa.PrivateKey as a convenience mainly for signing things with the private key without having to directly import the ecdsa package.
PublicKey is an ecdsa.PublicKey with additional functions to serialize in uncompressed, compressed, and hybrid formats.
SerializedKey is a type for representing a public key in its compressed serialized form.