Documentation
¶
Index ¶
- Constants
- func ContextDestroy(ctx *Context)
- func ContextRandomize(ctx *Context, seed32 [32]byte) int
- func EcPrivkeyNegate(ctx *Context, seckey []byte) (int, error)
- func EcPrivkeyTweakAdd(ctx *Context, seckey []byte, tweak []byte) (int, error)
- func EcPrivkeyTweakMul(ctx *Context, seckey []byte, tweak []byte) (int, error)
- func EcPubkeyNegate(ctx *Context, pubkey *PublicKey) (int, error)
- func EcPubkeySerialize(ctx *Context, publicKey *PublicKey, flags uint) (int, []byte, error)
- func EcPubkeyTweakAdd(ctx *Context, pk *PublicKey, tweak []byte) (int, error)
- func EcPubkeyTweakMul(ctx *Context, pk *PublicKey, tweak []byte) (int, error)
- func EcSeckeyVerify(ctx *Context, seckey []byte) (int, error)
- func Ecdh(ctx *Context, pubKey *PublicKey, privKey []byte) (int, []byte, error)
- func EcdsaRecoverableSignatureSerializeCompact(ctx *Context, sig *EcdsaRecoverableSignature) (int, []byte, int, error)
- func EcdsaSignatureNormalize(ctx *Context, sigout *EcdsaSignature, sigin *EcdsaSignature) (int, error)
- func EcdsaSignatureSerializeCompact(ctx *Context, sig *EcdsaSignature) (int, []byte, error)
- func EcdsaSignatureSerializeDer(ctx *Context, sig *EcdsaSignature) (int, []byte, error)
- func EcdsaVerify(ctx *Context, sig *EcdsaSignature, msg32 []byte, pubkey *PublicKey) (int, error)
- type Context
- type EcdsaRecoverableSignature
- type EcdsaSignature
- func EcdsaRecoverableSignatureConvert(ctx *Context, sig *EcdsaRecoverableSignature) (int, *EcdsaSignature, error)
- func EcdsaSign(ctx *Context, msg32 []byte, seckey []byte) (int, *EcdsaSignature, error)
- func EcdsaSignatureParseCompact(ctx *Context, signature []byte) (int, *EcdsaSignature, error)
- func EcdsaSignatureParseDer(ctx *Context, signature []byte) (int, *EcdsaSignature, error)
- func EcdsaSignatureParseDerLax(ctx *Context, signature []byte) (int, *EcdsaSignature, error)
- type PublicKey
- func EcPubkeyCombine(ctx *Context, vPk []*PublicKey) (int, *PublicKey, error)
- func EcPubkeyCreate(ctx *Context, seckey []byte) (int, *PublicKey, error)
- func EcPubkeyParse(ctx *Context, publicKey []byte) (int, *PublicKey, error)
- func EcdsaRecover(ctx *Context, sig *EcdsaRecoverableSignature, msg32 []byte) (int, *PublicKey, error)
Constants ¶
const ( /** Flags to pass to secp256k1_context_create. */ ContextVerify = uint(C.SECP256K1_CONTEXT_VERIFY) ContextSign = uint(C.SECP256K1_CONTEXT_SIGN) // Flags for EcPubkeySerialize EcCompressed = uint(C.SECP256K1_EC_COMPRESSED) EcUncompressed = uint(C.SECP256K1_EC_UNCOMPRESSED) // Length of elements byte representations LenCompressed int = 33 LenUncompressed int = 65 LenMsgHash int = 32 LenPrivateKey int = 32 LenCompactSig int = 64 LenMaxDerSig int = 72 // Errors returned by functions ErrorPrivateKeyNull string = "Private key cannot be null" ErrorPrivateKeyInvalid string = "Invalid private key" ErrorPublicKeyNull string = "Public key cannot be null" ErrorEcdsaSignatureNull string = "Signature cannot be null" ErrorEcdsaRecoverableSignatureNull string = "Recoverable signature" + " cannot be null" ErrorEcdh string = "Unable to do ECDH" ErrorPublicKeyCreate string = "Unable to produce public key" ErrorPublicKeyCombine string = "Unable to combine public keys" ErrorTweakSize string = "Tweak must be exactly 32 bytes" ErrorMsg32Size string = "Message hash must be exactly 32 bytes" ErrorPrivateKeySize string = "Private key must be exactly 32 bytes" ErrorPublicKeySize string = "Public key must be 33 or 65 bytes" ErrorTweakingPublicKey string = "Unable to tweak this public key" ErrorTweakingPrivateKey string = "Unable to tweak this private key" ErrorProducingSignature string = "Unable to produce signature" ErrorProducingRecoverableSignature string = "Unable to produce recoverable signature" ErrorCompactSigSize string = "Compact signature must be exactly 64 bytes" ErrorCompactSigParse string = "Unable to parse this compact signature" ErrorDerSigParse string = "Unable to parse this DER signature" ErrorRecoverableSigParse string = "Unable to parse this recoverable signature" ErrorRecoveryFailed string = "Failed to recover public key" ErrorPublicKeyParse string = "Unable to parse this public key" )
Variables ¶
This section is empty.
Functions ¶
func ContextDestroy ¶
func ContextDestroy(ctx *Context)
ContextDestroy destroys the context. The provided context must not be NULL.
func ContextRandomize ¶
ContextRandomize accepts a [32]byte seed in order to update the context randomization. NULL may be passed to reset to initial state. The context pointer must not be null.
func EcPrivkeyNegate ¶
EcPrivkeyNegate will negate a public key in place. The return code is 1 if the operation was successful, or 0 if the length was invalid.
func EcPrivkeyTweakAdd ¶
EcPrivkeyTweakAdd modifies the provided `seckey` by adding tweak to it. The return code is 0 if `tweak` was out of range (chance of around 1 in 2^128 for uniformly random 32-byte arrays), or if the resulting private key would be invalid (only when the tweak is the complement of the private key). The return code is 1 otherwise.
func EcPrivkeyTweakMul ¶
Tweak a private key by multiplying it by a tweak. The return code is 0 if the tweak was out of range (chance of around 1 in 2^128 for uniformly random 32-byte arrays) or zero. The code is 1 otherwise.
func EcPubkeyNegate ¶
EcPubkeyNegate will negate a public key object in place. The return code is always 1.
func EcPubkeySerialize ¶
EcPubkeySerialize serializes a pubkey object into a []byte. The output is an array of 65-bytes (if compressed==0), or 33-bytes (if compressed==1). Use EcCompressed or EcUncompressed to request a certain format. The function will always return 1, because the only public key objects are valid ones.
func EcPubkeyTweakAdd ¶
Tweak a public key by adding tweak times the generator to it. The return code is 0 if the tweak was out of range (chance of around 1 in 2^128 for uniformly random 32-byte arrays) or if the resulting public key would be invalid. The return code is 1 otherwise.
func EcPubkeyTweakMul ¶
Tweak a public key by multiplying it by a tweak. The return code is 0 if the tweak was out of range (chance of around 1 in 2^128 for uniformly random 32-byte arrays) or zero. The code is 1 otherwise.
func EcSeckeyVerify ¶
Verify a secret key. Returns 1 if the secret key is valid, or 0 if an error occured or the key was empty.
func Ecdh ¶
Compute an EC Diffie-Hellman secret in constant time. Return code is 1 if exponentiation was successful, or 0 if the scalar was invalid.
func EcdsaRecoverableSignatureSerializeCompact ¶
func EcdsaRecoverableSignatureSerializeCompact(ctx *Context, sig *EcdsaRecoverableSignature) (int, []byte, int, error)
Serialize an ECDSA signature in compact format, returning the []byte and the recovery id. Return code is always 1.
func EcdsaSignatureNormalize ¶
func EcdsaSignatureNormalize(ctx *Context, sigout *EcdsaSignature, sigin *EcdsaSignature) (int, error)
func EcdsaSignatureSerializeCompact ¶
func EcdsaSignatureSerializeCompact(ctx *Context, sig *EcdsaSignature) (int, []byte, error)
Serialize an ECDSA signature in compact (64 byte) format. Return code is always 1. See EcdsaSignatureParseCompact for details about the encoding.
func EcdsaSignatureSerializeDer ¶
func EcdsaSignatureSerializeDer(ctx *Context, sig *EcdsaSignature) (int, []byte, error)
Serialize an ECDSA signature in DER format. The return code for this function _should_ always return 1, since the serializedSig is initialized to LenMaxDerSig. If some day it doesn't, it's serious.
func EcdsaVerify ¶
Verify an ECDSA signature. Return code is 1 for a correct signature, or 0 if incorrect. To avoid accepting malleable signature, only ECDSA signatures in lower-S form are accepted. If you need to accept ECDSA sigantures from sources that do not obey this rule, apply EcdsaSignatureNormalize() prior to validation (however, this results in malleable signatures)
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context wraps a *secp256k1_context, required to use all functions. It can be initialized for signing, verification, or both.
func ContextClone ¶
ContextClone makes a copy of the provided *Context. The provided context must not be NULL.
func ContextCreate ¶
ContextCreate produces a new *Context, initialized with a bitmask of flags depending on it's intended usage. The supported flags are currently ContextSign and ContextVerify. Although expressed in the return type signature, the function does not currently return an error.
type EcdsaRecoverableSignature ¶
type EcdsaRecoverableSignature struct {
// contains filtered or unexported fields
}
EcdsaRecoverableSignature wraps a *secp256k1_ecdsa_recoverable_signature which contains the signature, and information about public key recovery.
func EcdsaRecoverableSignatureParseCompact ¶
func EcdsaRecoverableSignatureParseCompact(ctx *Context, signature []byte, recid int) (int, *EcdsaRecoverableSignature, error)
Parse a compact ECDSA signature from the 64-byte signature and recovery id (0, 1, 2, or 3). The return code is 1 if successful, 0 otherwise.
func EcdsaSignRecoverable ¶
func EcdsaSignRecoverable(ctx *Context, msg32 []byte, seckey []byte) (int, *EcdsaRecoverableSignature, error)
Create a recoverable ECDSA signature. The return code is 1 when the sig was created, or 0 if nonce generation failed or the private key was invalid.
type EcdsaSignature ¶
type EcdsaSignature struct {
// contains filtered or unexported fields
}
EcdsaSignature wraps a *secp256k1_ecdsa_signature, containing the R and S values.
func EcdsaRecoverableSignatureConvert ¶
func EcdsaRecoverableSignatureConvert(ctx *Context, sig *EcdsaRecoverableSignature) (int, *EcdsaSignature, error)
Convert a recoverable signature into a normal signature. The return code is always 1.
func EcdsaSign ¶
Create an ECDSA signature. Return code is 1 if the signature was created, or is zero and the error is set if the nonce generation function failed, or the private key was invalid. The created signature is always in lower-S form. See EcdsaSignatureNormalize for details.
func EcdsaSignatureParseCompact ¶
func EcdsaSignatureParseCompact(ctx *Context, signature []byte) (int, *EcdsaSignature, error)
EcdsaSignatureParseCompact parses an ECDSA signature in compact (64 bytes) format. The return code is 1 when the signature could be parsed, 0 otherwise. The signature must consist of a 32-byte big endian R value, followed by a 32-byte big endian S value. If R or S fall outside of [0..order-1], the encoding is invalid. R and S with value 0 are allowed in the encoding. After the call, sig will always be initialized. If parsing failed or R or S are zero, the resulting sig value is guaranteed to fail validation for any message and public key.
func EcdsaSignatureParseDer ¶
func EcdsaSignatureParseDer(ctx *Context, signature []byte) (int, *EcdsaSignature, error)
Parse a DER ECDSA signature. Returns 1 when the signature could be parsed, 0 otherwise. This function will accept any valid DER encoded signature, even if the encoded numbers are out of range. After the call, sig will always be initialized. If parsing failed or the encoded numbers are out of range, signature validation with it is guaranteed to fail for every message and public key.
func EcdsaSignatureParseDerLax ¶
func EcdsaSignatureParseDerLax(ctx *Context, signature []byte) (int, *EcdsaSignature, error)
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey wraps a *secp256k1_pubkey, which contains the prefix plus the X+Y coordidnates
func EcPubkeyCombine ¶
EcPubkeyCombine will compute sum of all the provided public keys, returning a new point. The error code is 1 if the sum is valid, 0 otherwise. There must be at least one public key.
func EcPubkeyCreate ¶
EcPubkeyCreate will compute the public key for a secret key. The return code is 1 and the key returned if the secret was valid. Otherwise, the return code is 0, and an error is returned. The key length must be 32-bytes.
func EcPubkeyParse ¶
EcPubkeyParse deserializes a variable-length public key into a *Pubkey object. The function will reject any input of zero bytes in length. This function supports parsing compressed (33 bytes, header byte 0x02 or 0x03), uncompressed (65 bytes, header byte 0x04), or hybrid (65 bytes, header byte 0x06 or 0x07) format public keys. The return code is 1 if the public key was fully valid, or 0 if the public key was invalid or could not be parsed.
func EcdsaRecover ¶
func EcdsaRecover(ctx *Context, sig *EcdsaRecoverableSignature, msg32 []byte) (int, *PublicKey, error)
Recover an ECDSA public key from a signature. The return code is 1 if the key was successfully recovered (which guarantees a correct signature), and is 0 otherwise.