Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKeyPair() (*PrivateKey, *PublicKey, error)
- func GetRFC6979Nonce(prv *PrivateKey, hash []byte) []byte
- func NewKeyFromSeed(seed []byte) (*PrivateKey, *PublicKey, error)
- func NonceRFC6979(privkey *big.Int, hash []byte, extra []byte, version []byte) *big.Int
- func PartialSign(hash []byte, prv *PrivateKey, groupPubkey *PublicKey, prvNonce *PrivateKey, ...) (*big.Int, *big.Int, error)
- func PrivKeyFromBytes(pkBytes []byte) (*PrivateKey, *PublicKey)
- func PrivKeyFromScalar(p []byte) (*PrivateKey, *PublicKey, error)
- func PrivKeyFromSecret(s []byte) (*PrivateKey, *PublicKey)
- func Sign(priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
- func SignFromScalar(priv *PrivateKey, nonce []byte, hash []byte) (r, s *big.Int, err error)
- func SignFromSecretNoReader(priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
- func SignThreshold(priv *PrivateKey, groupPub *PublicKey, hash []byte, privNonce *PrivateKey, ...) (r, s *big.Int, err error)
- func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
- type PrivateKey
- func (p PrivateKey) GetD() *big.Int
- func (p *PrivateKey) PubKey() *PublicKey
- func (p PrivateKey) Public() (*big.Int, *big.Int)
- func (p PrivateKey) Serialize() []byte
- func (p PrivateKey) SerializeSecret() []byte
- func (p PrivateKey) Sign(hash []byte) (*Signature, error)
- func (p PrivateKey) ToECDSA() *ecdsa.PrivateKey
- type PublicKey
- type Signature
- type TwistedEdwardsCurve
- func (curve *TwistedEdwardsCurve) Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int)
- func (curve *TwistedEdwardsCurve) Double(x1, y1 *big.Int) (x, y *big.Int)
- func (curve *TwistedEdwardsCurve) IsOnCurve(x *big.Int, y *big.Int) bool
- func (curve TwistedEdwardsCurve) Params() *elliptic.CurveParams
- func (curve *TwistedEdwardsCurve) ScalarBaseMult(k []byte) (x, y *big.Int)
- func (curve *TwistedEdwardsCurve) ScalarMult(x1, y1 *big.Int, k []byte) (x, y *big.Int)
Constants ¶
const ( PrivScalarSize = 32 PrivKeyBytesLen = 64 )
These constants define the lengths of serialized private keys.
const (
PubKeyBytesLen = 32
)
These constants define the lengths of serialized public keys.
const SignatureSize = 64
SignatureSize is the size of an encoded ECDSA signature.
Variables ¶
var Sha512VersionStringRFC6979 = []byte("Edwards+SHA512 ")
Sha512VersionStringRFC6979 is the RFC6979 nonce version for a Schnorr signature over the Curve25519 curve using BLAKE256 as the hash function.
Functions ¶
func GenerateKeyPair ¶
func GenerateKeyPair() (*PrivateKey, *PublicKey, error)
GenerateKeyPair is a wrapper for ecdsa.GenerateKey that returns a PrivateKey instead of the normal ecdsa.PrivateKey.
func GetRFC6979Nonce ¶
func GetRFC6979Nonce(prv *PrivateKey, hash []byte) []byte
GetRFC6979Nonce -- returns the deterministic nonce.
func NewKeyFromSeed ¶
func NewKeyFromSeed(seed []byte) (*PrivateKey, *PublicKey, error)
NewKeyFromSeed calculates a private key from a seed.
func NonceRFC6979 ¶
NonceRFC6979 generates an ECDSA nonce (`k`) deterministically according to RFC 6979. It takes a 32-byte hash as an input and returns 32-byte nonce to be used in ECDSA algorithm.
func PartialSign ¶
func PartialSign(hash []byte, prv *PrivateKey, groupPubkey *PublicKey, prvNonce *PrivateKey, pubNonce *PublicKey) (*big.Int, *big.Int, error)
PartialSign -- returns the partial signature of this private key.
func PrivKeyFromBytes ¶
func PrivKeyFromBytes(pkBytes []byte) (*PrivateKey, *PublicKey)
PrivKeyFromBytes returns a private and public key for `curve' based on the private key passed as an argument as a byte slice.
func PrivKeyFromScalar ¶
func PrivKeyFromScalar(p []byte) (*PrivateKey, *PublicKey, error)
PrivKeyFromScalar returns a private and public key for `curve' based on the 32-byte private scalar passed as an argument as a byte slice (encoded big endian int).
func PrivKeyFromSecret ¶
func PrivKeyFromSecret(s []byte) (*PrivateKey, *PublicKey)
PrivKeyFromSecret returns a private and public key for `curve' based on the 32-byte private key secret passed as an argument as a byte slice.
func Sign ¶
func Sign(priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
Sign is the generalized and exported version of Ed25519 signing, that handles both standard private secrets and non-standard scalars.
func SignFromScalar ¶
SignFromScalar signs a message 'hash' using the given private scalar priv. It uses RFC6979 to generate a deterministic nonce. Considered experimental. r = kG, where k is the RFC6979 nonce s = r + hash512(k || A || M) * a
func SignFromSecretNoReader ¶
func SignFromSecretNoReader(priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
SignFromSecretNoReader signs a message 'hash' using the given private key priv. It doesn't actually user the random reader.
func SignThreshold ¶
func SignThreshold(priv *PrivateKey, groupPub *PublicKey, hash []byte, privNonce *PrivateKey, pubNonceSum *PublicKey) (r, s *big.Int, err error)
SignThreshold signs a message 'hash' using the given private scalar priv in a threshold group signature. It uses RFC6979 to generate a deterministic nonce. Considered experimental. As opposed to the threshold signing function for secp256k1, this function takes the entirety of the public nonce point (all points added) instead of the public nonce point with n-1 keys added. r = K_Sum s = r + hash512(k || A || M) * a
Types ¶
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey wraps an ecdsa.PrivateKey as a convenience mainly for signing things with the private key without having to directly import the ecdsa package.
func (PrivateKey) GetD ¶
func (p PrivateKey) GetD() *big.Int
GetD satisfies the chainec PrivateKey interface.
func (*PrivateKey) PubKey ¶
func (p *PrivateKey) PubKey() *PublicKey
PubKey returns the PublicKey corresponding to this private key.
func (PrivateKey) Public ¶
func (p PrivateKey) Public() (*big.Int, *big.Int)
Public returns the PublicKey corresponding to this private key.
func (PrivateKey) Serialize ¶
func (p PrivateKey) Serialize() []byte
Serialize returns the private key as a 32 byte big endian number.
func (PrivateKey) SerializeSecret ¶
func (p PrivateKey) SerializeSecret() []byte
SerializeSecret returns the 32 byte secret along with its public key as 64 bytes.
func (PrivateKey) Sign ¶
func (p PrivateKey) Sign(hash []byte) (*Signature, error)
Sign is the generalized and exported version of Ed25519 signing, that handles both standard private secrets and non-standard scalars.
func (PrivateKey) ToECDSA ¶
func (p PrivateKey) ToECDSA() *ecdsa.PrivateKey
ToECDSA returns the private key as a *ecdsa.PrivateKey.
type PublicKey ¶
PublicKey is an ecdsa.PublicKey with an additional function to serialize.
func NewPublicKey ¶
NewPublicKey instantiates a new public key.
func ParsePubKey ¶
ParsePubKey parses a public key for an edwards curve from a bytestring into a ecdsa.Publickey, verifying that it is valid.
type Signature ¶
Signature is a type representing an ecdsa signature.
func CombinePartialSigs ¶
CombinePartialSigs -- returns the signature of aggragation.
func NewSignature ¶
NewSignature instantiates a new signature given some R,S values.
func ParseSignature ¶
ParseSignature parses a signature in BER format for the curve type `curve' into a Signature type, performing some basic sanity checks.
func (*Signature) IsEqual ¶
IsEqual compares this Signature instance to the one passed, returning true if both Signatures are equivalent. A signature is equivalent to another, if they both have the same scalar value for R and S.
type TwistedEdwardsCurve ¶
type TwistedEdwardsCurve struct { *elliptic.CurveParams H int // Cofactor of the curve A, D, I *big.Int // Edwards curve equation parameter constants // contains filtered or unexported fields }
TwistedEdwardsCurve extended an elliptical curve set of parameters to satisfy the interface of the elliptic package.
func Edwards ¶
func Edwards() *TwistedEdwardsCurve
Edwards returns a Curve which implements Ed25519.
func (*TwistedEdwardsCurve) Add ¶
func (curve *TwistedEdwardsCurve) Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int)
Add adds two points represented by pairs of big integers on the elliptical curve.
func (*TwistedEdwardsCurve) Double ¶
func (curve *TwistedEdwardsCurve) Double(x1, y1 *big.Int) (x, y *big.Int)
Double adds the same pair of big integer coordinates to itself on the elliptical curve.
func (*TwistedEdwardsCurve) IsOnCurve ¶
IsOnCurve returns bool to say if the point (x,y) is on the curve by checking (y^2 - x^2 - 1 - dx^2y^2) % P == 0.
func (TwistedEdwardsCurve) Params ¶
func (curve TwistedEdwardsCurve) Params() *elliptic.CurveParams
Params returns the parameters for the curve.
func (*TwistedEdwardsCurve) ScalarBaseMult ¶
func (curve *TwistedEdwardsCurve) ScalarBaseMult(k []byte) (x, y *big.Int)
ScalarBaseMult returns k*G, where G is the base point of the group and k is an integer in big-endian form. TODO Optimize this with field elements
func (*TwistedEdwardsCurve) ScalarMult ¶
ScalarMult returns k*(Bx,By) where k is a number in big-endian form. This uses the repeated doubling method, which is variable time. TODO use a constant time method to prevent side channel attacks.