crypto

package module
v0.0.0-...-08bc4ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2018 License: MIT Imports: 20 Imported by: 0

README

go-libp2p-crypto

standard-readme compliant GoDoc Coverage Status Build Status

Various cryptographic utilities used by ipfs

Table of Contents

Install

go get github.com/libp2p/go-libp2p-crypto

Usage

Go to https://godoc.org/github.com/libp2p/go-libp2p-crypto.

Contribute

Feel free to join in. All welcome. Open an issue!

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to libp2p are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

Want to hack on IPFS?

License

MIT © 2016 Jeromy Johnson

Documentation

Overview

Package crypto implements various cryptographic utilities used by ipfs. This includes a Public and Private key interface and an RSA key implementation that satisfies it.

Index

Constants

View Source
const (
	RSA = iota
	Ed25519
	Secp256k1
)

Variables

View Source
var ErrBadKeyType = errors.New("invalid or unsupported key type")
View Source
var KeyTypes = []int{
	RSA,
	Ed25519,
	Secp256k1,
}

Functions

func ConfigDecodeKey

func ConfigDecodeKey(b string) ([]byte, error)

ConfigDecodeKey decodes from b64 (for config file), and unmarshals.

func ConfigEncodeKey

func ConfigEncodeKey(b []byte) string

ConfigEncodeKey encodes to b64 (for config file), and marshals.

func GenerateEd25519Key

func GenerateEd25519Key(src io.Reader) (PrivKey, PubKey, error)

func GenerateKeyPair

func GenerateKeyPair(typ, bits int) (PrivKey, PubKey, error)

func GenerateKeyPairWithReader

func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error)

Generates a keypair of the given type and bitsize

func GenerateSecp256k1Key

func GenerateSecp256k1Key(src io.Reader) (PrivKey, PubKey, error)

func KeyEqual

func KeyEqual(k1, k2 Key) bool

KeyEqual checks whether two

func KeyStretcher

func KeyStretcher(cipherType string, hashType string, secret []byte) (StretchedKeys, StretchedKeys)

Generates a set of keys for each party by stretching the shared key. (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey)

func MarshalPrivateKey

func MarshalPrivateKey(k PrivKey) ([]byte, error)

MarshalPrivateKey converts a key object into its protobuf serialized form.

func MarshalPublicKey

func MarshalPublicKey(k PubKey) ([]byte, error)

MarshalPublicKey converts a public key object into a protobuf serialized public key

func MarshalRsaPrivateKey

func MarshalRsaPrivateKey(k *RsaPrivateKey) []byte

func MarshalRsaPublicKey

func MarshalRsaPublicKey(k *RsaPublicKey) ([]byte, error)

Types

type Ed25519PrivateKey

type Ed25519PrivateKey struct {
	// contains filtered or unexported fields
}

func Ed25519PrivateKeyFromPrivKey

func Ed25519PrivateKeyFromPrivKey(sk [64]byte) *Ed25519PrivateKey

Ed25519PrivateKeyFromPrivKey creates an Ed25519PrivateKey from a 64 bytes private key

func (*Ed25519PrivateKey) Bytes

func (k *Ed25519PrivateKey) Bytes() ([]byte, error)

func (*Ed25519PrivateKey) BytesU

func (k *Ed25519PrivateKey) BytesU() [64]byte

BytesU returns the public key bytes without passing it through proto.Marshal

func (*Ed25519PrivateKey) Equals

func (k *Ed25519PrivateKey) Equals(o Key) bool

func (*Ed25519PrivateKey) GetPublic

func (k *Ed25519PrivateKey) GetPublic() PubKey

func (*Ed25519PrivateKey) Sign

func (k *Ed25519PrivateKey) Sign(msg []byte) ([]byte, error)

func (*Ed25519PrivateKey) ToCurve25519

func (k *Ed25519PrivateKey) ToCurve25519() *[32]byte

type Ed25519PublicKey

type Ed25519PublicKey struct {
	// contains filtered or unexported fields
}

func (*Ed25519PublicKey) Bytes

func (k *Ed25519PublicKey) Bytes() ([]byte, error)

func (*Ed25519PublicKey) BytesU

func (k *Ed25519PublicKey) BytesU() [32]byte

BytesU returns the public key bytes without passing it through proto.Marshal

func (*Ed25519PublicKey) Equals

func (k *Ed25519PublicKey) Equals(o Key) bool

func (*Ed25519PublicKey) ToCurve25519

func (k *Ed25519PublicKey) ToCurve25519() (*[32]byte, error)

func (*Ed25519PublicKey) Verify

func (k *Ed25519PublicKey) Verify(data []byte, sig []byte) (bool, error)

type GenSharedKey

type GenSharedKey func([]byte) ([]byte, error)

Given a public key, generates the shared key.

func GenerateEKeyPair

func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error)

Generates an ephemeral public key and returns a function that will compute the shared secret key. Used in the identify module.

Focuses only on ECDH now, but can be made more general in the future.

type Key

type Key interface {
	// Bytes returns a serialized, storeable representation of this key
	Bytes() ([]byte, error)

	// Equals checks whether two PubKeys are the same
	Equals(Key) bool
}

Key represents a crypto key that can be compared to another key

type PrivKey

type PrivKey interface {
	Key

	// Cryptographically sign the given bytes
	Sign([]byte) ([]byte, error)

	// Return a public key paired with this private key
	GetPublic() PubKey
}

PrivKey represents a private key that can be used to generate a public key, sign data, and decrypt data that was encrypted with a public key

func UnmarshalEd25519PrivateKey

func UnmarshalEd25519PrivateKey(data []byte) (PrivKey, error)

func UnmarshalPrivateKey

func UnmarshalPrivateKey(data []byte) (PrivKey, error)

UnmarshalPrivateKey converts a protobuf serialized private key into its representative object

func UnmarshalRsaPrivateKey

func UnmarshalRsaPrivateKey(b []byte) (PrivKey, error)

func UnmarshalSecp256k1PrivateKey

func UnmarshalSecp256k1PrivateKey(data []byte) (PrivKey, error)

type PrivKeyUnmarshaller

type PrivKeyUnmarshaller func(data []byte) (PrivKey, error)

PrivKeyUnmarshaller is a func that creates a PrivKey from a given slice of bytes

type PubKey

type PubKey interface {
	Key

	// Verify that 'sig' is the signed hash of 'data'
	Verify(data []byte, sig []byte) (bool, error)
}

func UnmarshalEd25519PublicKey

func UnmarshalEd25519PublicKey(data []byte) (PubKey, error)

func UnmarshalPublicKey

func UnmarshalPublicKey(data []byte) (PubKey, error)

UnmarshalPublicKey converts a protobuf serialized public key into its representative object

func UnmarshalRsaPublicKey

func UnmarshalRsaPublicKey(b []byte) (PubKey, error)

func UnmarshalSecp256k1PublicKey

func UnmarshalSecp256k1PublicKey(data []byte) (PubKey, error)

type PubKeyUnmarshaller

type PubKeyUnmarshaller func(data []byte) (PubKey, error)

PubKeyUnmarshaller is a func that creates a PubKey from a given slice of bytes

type RsaPrivateKey

type RsaPrivateKey struct {
	// contains filtered or unexported fields
}

func (*RsaPrivateKey) Bytes

func (sk *RsaPrivateKey) Bytes() ([]byte, error)

func (*RsaPrivateKey) Decrypt

func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error)

func (*RsaPrivateKey) Equals

func (sk *RsaPrivateKey) Equals(k Key) bool

Equals checks whether this key is equal to another

func (*RsaPrivateKey) GetPublic

func (sk *RsaPrivateKey) GetPublic() PubKey

func (*RsaPrivateKey) Sign

func (sk *RsaPrivateKey) Sign(message []byte) ([]byte, error)

type RsaPublicKey

type RsaPublicKey struct {
	// contains filtered or unexported fields
}

func (*RsaPublicKey) Bytes

func (pk *RsaPublicKey) Bytes() ([]byte, error)

func (*RsaPublicKey) Encrypt

func (pk *RsaPublicKey) Encrypt(b []byte) ([]byte, error)

func (*RsaPublicKey) Equals

func (pk *RsaPublicKey) Equals(k Key) bool

Equals checks whether this key is equal to another

func (*RsaPublicKey) Verify

func (pk *RsaPublicKey) Verify(data, sig []byte) (bool, error)

type Secp256k1PrivateKey

type Secp256k1PrivateKey btcec.PrivateKey

func (*Secp256k1PrivateKey) Bytes

func (k *Secp256k1PrivateKey) Bytes() ([]byte, error)

func (*Secp256k1PrivateKey) Equals

func (k *Secp256k1PrivateKey) Equals(o Key) bool

func (*Secp256k1PrivateKey) GetPublic

func (k *Secp256k1PrivateKey) GetPublic() PubKey

func (*Secp256k1PrivateKey) Sign

func (k *Secp256k1PrivateKey) Sign(data []byte) ([]byte, error)

type Secp256k1PublicKey

type Secp256k1PublicKey btcec.PublicKey

func (*Secp256k1PublicKey) Bytes

func (k *Secp256k1PublicKey) Bytes() ([]byte, error)

func (*Secp256k1PublicKey) Equals

func (k *Secp256k1PublicKey) Equals(o Key) bool

func (*Secp256k1PublicKey) Verify

func (k *Secp256k1PublicKey) Verify(data []byte, sigStr []byte) (bool, error)

type StretchedKeys

type StretchedKeys struct {
	IV        []byte
	MacKey    []byte
	CipherKey []byte
}

Directories

Path Synopsis
Package crypto_pb is a generated protocol buffer package.
Package crypto_pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL