Documentation
¶
Overview ¶
Package keys implements the public key cryptography used throughout Babble.
An instance of a Babble node, also referred to as peer, participant or validator, owns a cryptographic key-pair that it uses to encrypt, sign and verify messages. The private key is secret but the public key is used by other nodes to verify messages signed with the private key.
Babble uses elliptic curve cryptography (ECDSA) with the sec256k1 curve. We chose the secp256k1 curve because it is also used by Bitcoin and Ethereum which means that Bitcoin and Ethereum keys can be used to operate a Babble node.r
Index ¶
- 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 ParsePrivateKey(d []byte) (*ecdsa.PrivateKey, error)
- func PrivateKeyHex(key *ecdsa.PrivateKey) string
- func PublicKeyHex(pub *ecdsa.PublicKey) string
- func PublicKeyID(pubBytes []byte) uint32
- func Sign(priv *ecdsa.PrivateKey, data []byte) (r, s *big.Int, err error)
- func ToPublicKey(pub []byte) *ecdsa.PublicKey
- func Verify(pub *ecdsa.PublicKey, data []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 representation 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).
func Sign ¶
Sign signs the data with the private key and 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 a 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 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.