Documentation ¶
Index ¶
- func Curve() elliptic.Curve
- func DecodeSignature(sig string) (r, s *big.Int, err error)
- func DumpPrivateKey(priv *ecdsa.PrivateKey) []byte
- func EncodeSignature(r, s *big.Int) string
- func FromPublicKey(pub *ecdsa.PublicKey) []byte
- func GenerateECDSAKey() (*ecdsa.PrivateKey, error)
- func Hash32(data []byte) uint32
- func ParsePrivateKey(d []byte) (*ecdsa.PrivateKey, error)
- func PrivateKeyHex(key *ecdsa.PrivateKey) string
- func PublicKeyHex(pub *ecdsa.PublicKey) string
- func PublicKeyID(pub *ecdsa.PublicKey) uint32
- func Sign(priv *ecdsa.PrivateKey, hash []byte) (r, s *big.Int, err error)
- func ToPublicKey(pub []byte) *ecdsa.PublicKey
- func Verify(pub *ecdsa.PublicKey, hash []byte, r, s *big.Int) bool
- type KeyReaderWriter
- type SimpleKeyfile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeSignature ¶
DecodeSignature parses a string representaion of a signature as produced by EncodeSignature.
func DumpPrivateKey ¶
func DumpPrivateKey(priv *ecdsa.PrivateKey) []byte
DumpPrivateKey exports a private key into a binary dump.
func EncodeSignature ¶
EncodeSignature returns a string representation of a signature.
func FromPublicKey ¶
FromPublicKey is a wrapper around elliptic.Marshal which calls Curve() to determine which elliptic.Curve to use. It outputs the point in uncompressed form.
func GenerateECDSAKey ¶
func GenerateECDSAKey() (*ecdsa.PrivateKey, error)
GenerateECDSAKey creates a new ecdsa.PrivateKey using the elliptic.Curve returned by Curve() function.
func ParsePrivateKey ¶
func ParsePrivateKey(d []byte) (*ecdsa.PrivateKey, error)
ParsePrivateKey creates a private key with the given D value.
func PrivateKeyHex ¶
func PrivateKeyHex(key *ecdsa.PrivateKey) string
PrivateKeyHex returns the hexadecimal representation of a raw private key as returned by DumpPrivateKey
func PublicKeyHex ¶
PublicKeyHex returns the hexadecimal reprentation of the uncompressed form of the public key
func PublicKeyID ¶
PublicKeyID tries to give a unique uint32 representation of the public key. There is obviously a risk of collision here. The uint32 is used to save space in the wire encoding of hashgraph Events, by replacing the uncompressed form of public-keys (65 bytes for secp256k1 curve) with uint32 (8 bytes).
XXX THIS SEEMS LIKE AN ATTACK VECTOR
func Sign ¶
Sign is a wrapper around ecdsa.Sign which uses the built-in pseudo-random generator rand.Reader.
func ToPublicKey ¶
ToPublicKey is a wrapper around elliptic.Unmarshal which calls Curve() to determine which elliptic.Curve to use. The argument pub is expected to be the uncompressed form of point on the curve, as returned by FromPublicKey.
Types ¶
type KeyReaderWriter ¶
type KeyReaderWriter interface { ReadKey() (ecdsa.PrivateKey, error) WriteKey(ecdsa.PrivateKey, error) }
KeyReaderWriter reads and writes ecdsa keys from/to any format or support.
type SimpleKeyfile ¶
type SimpleKeyfile struct {
// contains filtered or unexported fields
}
SimpleKeyfile implements KeyReaderWriter with unencrypted and unformated files.
func NewSimpleKeyfile ¶
func NewSimpleKeyfile(keyfile string) *SimpleKeyfile
NewSimpleKeyfile instantiates a new SimpleKeyfile with an underlying file
func (*SimpleKeyfile) ReadKey ¶
func (k *SimpleKeyfile) ReadKey() (*ecdsa.PrivateKey, error)
ReadKey implements KeyReaderWriter. It reads from the underlying file which is expected to contain a raw hex dump of the key's D value (big.Int), as produced by WriteKey.
func (*SimpleKeyfile) WriteKey ¶
func (k *SimpleKeyfile) WriteKey(key *ecdsa.PrivateKey) error
WriteKey implements KeyReaderWriter. It writes a raw hex dump of the key's D value (big.Int) to the underlying file.