package crypto

Import Path
	github.com/libp2p/go-libp2p/core/crypto (on go.dev)

Dependency Relation
	imports 22 packages, and imported by 20 packages

Involved Source Files ecdsa.go ed25519.go Package crypto implements various cryptographic utilities used by libp2p. This includes a Public and Private key interface and key implementations for supported key algorithms. key_to_stdlib.go rsa_common.go rsa_go.go secp256k1.go
Package-Level Type Names (total 15)
/* sort by: | */
ECDSAPrivateKey is an implementation of an ECDSA private key Equals compares two private keys GetPublic returns a public key Raw returns x509 bytes from a private key Sign returns the signature of the input data Type returns the key type *ECDSAPrivateKey : Key *ECDSAPrivateKey : PrivKey func MarshalECDSAPrivateKey(ePriv ECDSAPrivateKey) (res []byte, err error)
ECDSAPublicKey is an implementation of an ECDSA public key Equals compares to public keys Raw returns x509 bytes from a public key Type returns the key type Verify compares data to a signature *ECDSAPublicKey : Key *ECDSAPublicKey : PubKey func MarshalECDSAPublicKey(ePub ECDSAPublicKey) (res []byte, err error)
ECDSASig holds the r and s values of an ECDSA signature R *big.Int S *big.Int
Ed25519PrivateKey is an ed25519 private key. Equals compares two ed25519 private keys. GetPublic returns an ed25519 public key from a private key. Raw private key bytes. Sign returns a signature from an input message. Type of the private key (Ed25519). *Ed25519PrivateKey : Key *Ed25519PrivateKey : PrivKey
Ed25519PublicKey is an ed25519 public key. Equals compares two ed25519 public keys. Raw public key bytes. Type of the public key (Ed25519). Verify checks a signature against the input data. *Ed25519PublicKey : Key *Ed25519PublicKey : PubKey
GenSharedKey generates the shared key from a given private key
Key represents a crypto key that can be compared to another key Equals checks whether two PubKeys are the same Raw returns the raw bytes of the key (not wrapped in the libp2p-crypto protobuf). This function is the inverse of {Priv,Pub}KeyUnmarshaler. Type returns the protobuf key type. *ECDSAPrivateKey *ECDSAPublicKey *Ed25519PrivateKey *Ed25519PublicKey PrivKey (interface) PubKey (interface) *RsaPrivateKey *RsaPublicKey *Secp256k1PrivateKey *Secp256k1PublicKey func KeyEqual(k1, k2 Key) bool func (*ECDSAPrivateKey).Equals(o Key) bool func (*ECDSAPublicKey).Equals(o Key) bool func (*Ed25519PrivateKey).Equals(o Key) bool func (*Ed25519PublicKey).Equals(o Key) bool func Key.Equals(Key) bool func PrivKey.Equals(Key) bool func PubKey.Equals(Key) bool func (*RsaPrivateKey).Equals(k Key) bool func (*RsaPublicKey).Equals(k Key) bool func (*Secp256k1PrivateKey).Equals(o Key) bool func (*Secp256k1PublicKey).Equals(o Key) bool
PrivKey represents a private key that can be used to generate a public key and sign data Equals checks whether two PubKeys are the same Return a public key paired with this private key Raw returns the raw bytes of the key (not wrapped in the libp2p-crypto protobuf). This function is the inverse of {Priv,Pub}KeyUnmarshaler. Cryptographically sign the given bytes Type returns the protobuf key type. *ECDSAPrivateKey *Ed25519PrivateKey *RsaPrivateKey *Secp256k1PrivateKey PrivKey : Key func ECDSAKeyPairFromKey(priv *ecdsa.PrivateKey) (PrivKey, PubKey, error) func GenerateECDSAKeyPair(src io.Reader) (PrivKey, PubKey, error) func GenerateECDSAKeyPairWithCurve(curve elliptic.Curve, src io.Reader) (PrivKey, PubKey, error) func GenerateEd25519Key(src io.Reader) (PrivKey, PubKey, error) func GenerateKeyPair(typ, bits int) (PrivKey, PubKey, error) func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error) func GenerateRSAKeyPair(bits int, src io.Reader) (PrivKey, PubKey, error) func GenerateSecp256k1Key(_ io.Reader) (PrivKey, PubKey, error) func KeyPairFromStdKey(priv crypto.PrivateKey) (PrivKey, PubKey, error) func UnmarshalECDSAPrivateKey(data []byte) (res PrivKey, err error) func UnmarshalEd25519PrivateKey(data []byte) (PrivKey, error) func UnmarshalPrivateKey(data []byte) (PrivKey, error) func UnmarshalRsaPrivateKey(b []byte) (key PrivKey, err error) func UnmarshalSecp256k1PrivateKey(data []byte) (k PrivKey, err error) func github.com/libp2p/go-libp2p/core/peerstore.KeyBook.PrivKey(peer.ID) PrivKey func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.PrivKey(peer.ID) PrivKey func MarshalPrivateKey(k PrivKey) ([]byte, error) func PrivKeyToStdKey(priv PrivKey) (crypto.PrivateKey, error) func github.com/libp2p/go-libp2p/core/peer.IDFromPrivateKey(sk PrivKey) (peer.ID, error) func github.com/libp2p/go-libp2p/core/peer.ID.MatchesPrivateKey(sk PrivKey) bool func github.com/libp2p/go-libp2p/core/peerstore.KeyBook.AddPrivKey(peer.ID, PrivKey) error func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.AddPrivKey(peer.ID, PrivKey) error func github.com/libp2p/go-libp2p/core/record.Seal(rec record.Record, privateKey PrivKey) (*record.Envelope, error) func github.com/libp2p/go-libp2p/core/sec/insecure.NewWithIdentity(protocolID protocol.ID, id peer.ID, key PrivKey) *insecure.Transport func github.com/libp2p/go-libp2p.Identity(sk PrivKey) libp2p.Option func github.com/libp2p/go-libp2p/config.PrivKeyToStatelessResetKey(key PrivKey) (quic.StatelessResetKey, error) func github.com/libp2p/go-libp2p/config.PrivKeyToTokenGeneratorKey(key PrivKey) (quic.TokenGeneratorKey, error) func github.com/libp2p/go-libp2p/p2p/security/noise.New(id protocol.ID, privkey PrivKey, muxers []tptu.StreamMuxer) (*noise.Transport, error) func github.com/libp2p/go-libp2p/p2p/security/tls.GenerateSignedExtension(sk PrivKey, pubKey crypto.PublicKey) (pkix.Extension, error) func github.com/libp2p/go-libp2p/p2p/security/tls.New(id protocol.ID, key PrivKey, muxers []tptu.StreamMuxer) (*libp2ptls.Transport, error) func github.com/libp2p/go-libp2p/p2p/security/tls.NewIdentity(privKey PrivKey, opts ...libp2ptls.IdentityOption) (*libp2ptls.Identity, error) func github.com/libp2p/go-libp2p/p2p/transport/quic.NewTransport(key PrivKey, connManager *quicreuse.ConnManager, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager) (tpt.Transport, error) func github.com/libp2p/go-libp2p/p2p/transport/webrtc.New(privKey PrivKey, psk pnet.PSK, gater connmgr.ConnectionGater, rcmgr network.ResourceManager, listenUDP libp2pwebrtc.ListenUDPFn, opts ...libp2pwebrtc.Option) (*libp2pwebrtc.WebRTCTransport, error) func github.com/libp2p/go-libp2p/p2p/transport/webtransport.New(key PrivKey, psk pnet.PSK, connManager *quicreuse.ConnManager, gater connmgr.ConnectionGater, rcmgr network.ResourceManager, opts ...libp2pwebtransport.Option) (tpt.Transport, error) func github.com/libp2p/go-libp2p-pubsub.WithSecretKeyAndPeerId(key PrivKey, pid peer.ID) pubsub.PubOpt
PrivKeyUnmarshaller is a func that creates a PrivKey from a given slice of bytes
PubKey is a public key that can be used to verify data signed with the corresponding private key Equals checks whether two PubKeys are the same Raw returns the raw bytes of the key (not wrapped in the libp2p-crypto protobuf). This function is the inverse of {Priv,Pub}KeyUnmarshaler. Type returns the protobuf key type. Verify that 'sig' is the signed hash of 'data' *ECDSAPublicKey *Ed25519PublicKey *RsaPublicKey *Secp256k1PublicKey PubKey : Key func ECDSAKeyPairFromKey(priv *ecdsa.PrivateKey) (PrivKey, PubKey, error) func ECDSAPublicKeyFromPubKey(pub ecdsa.PublicKey) (PubKey, error) func GenerateECDSAKeyPair(src io.Reader) (PrivKey, PubKey, error) func GenerateECDSAKeyPairWithCurve(curve elliptic.Curve, src io.Reader) (PrivKey, PubKey, error) func GenerateEd25519Key(src io.Reader) (PrivKey, PubKey, error) func GenerateKeyPair(typ, bits int) (PrivKey, PubKey, error) func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error) func GenerateRSAKeyPair(bits int, src io.Reader) (PrivKey, PubKey, error) func GenerateSecp256k1Key(_ io.Reader) (PrivKey, PubKey, error) func KeyPairFromStdKey(priv crypto.PrivateKey) (PrivKey, PubKey, error) func PublicKeyFromProto(pmes *pb.PublicKey) (PubKey, error) func UnmarshalECDSAPublicKey(data []byte) (key PubKey, err error) func UnmarshalEd25519PublicKey(data []byte) (PubKey, error) func UnmarshalPublicKey(data []byte) (PubKey, error) func UnmarshalRsaPublicKey(b []byte) (key PubKey, err error) func UnmarshalSecp256k1PublicKey(data []byte) (_k PubKey, err error) func (*ECDSAPrivateKey).GetPublic() PubKey func (*Ed25519PrivateKey).GetPublic() PubKey func PrivKey.GetPublic() PubKey func (*RsaPrivateKey).GetPublic() PubKey func (*Secp256k1PrivateKey).GetPublic() PubKey func github.com/libp2p/go-libp2p/core/network.Conn.RemotePublicKey() PubKey func github.com/libp2p/go-libp2p/core/network.ConnSecurity.RemotePublicKey() PubKey func github.com/libp2p/go-libp2p/core/peer.ID.ExtractPublicKey() (PubKey, error) func github.com/libp2p/go-libp2p/core/peerstore.KeyBook.PubKey(peer.ID) PubKey func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.PubKey(peer.ID) PubKey func github.com/libp2p/go-libp2p/core/routing.GetPublicKey(r routing.ValueStore, ctx context.Context, p peer.ID) (PubKey, error) func github.com/libp2p/go-libp2p/core/routing.PubKeyFetcher.GetPublicKey(context.Context, peer.ID) (PubKey, error) func github.com/libp2p/go-libp2p/core/sec.SecureConn.RemotePublicKey() PubKey func github.com/libp2p/go-libp2p/core/sec/insecure.(*Conn).RemotePublicKey() PubKey func github.com/libp2p/go-libp2p/core/transport.CapableConn.RemotePublicKey() PubKey func github.com/libp2p/go-libp2p/p2p/net/swarm.(*Conn).RemotePublicKey() PubKey func github.com/libp2p/go-libp2p/p2p/security/tls.PubKeyFromCertChain(chain []*x509.Certificate) (PubKey, error) func github.com/libp2p/go-libp2p/p2p/security/tls.(*Identity).ConfigForPeer(remote peer.ID) (*tls.Config, <-chan PubKey) func MarshalPublicKey(k PubKey) ([]byte, error) func PubKeyToStdKey(pub PubKey) (crypto.PublicKey, error) func PublicKeyToProto(k PubKey) (*pb.PublicKey, error) func github.com/libp2p/go-libp2p/core/peer.IDFromPublicKey(pk PubKey) (peer.ID, error) func github.com/libp2p/go-libp2p/core/peer.ID.MatchesPublicKey(pk PubKey) bool func github.com/libp2p/go-libp2p/core/peerstore.KeyBook.AddPubKey(peer.ID, PubKey) error func github.com/libp2p/go-libp2p/core/peerstore.Peerstore.AddPubKey(peer.ID, PubKey) error func github.com/libp2p/go-libp2p/p2p/net/swarm.MetricsTracer.OpenedConnection(network.Direction, PubKey, network.ConnectionState, ma.Multiaddr)
PubKeyUnmarshaller is a func that creates a PubKey from a given slice of bytes
RsaPrivateKey is a rsa private key Equals checks whether this key is equal to another GetPublic returns a public key (*RsaPrivateKey) Raw() (res []byte, err error) Sign returns a signature of the input data (*RsaPrivateKey) Type() pb.KeyType *RsaPrivateKey : Key *RsaPrivateKey : PrivKey
RsaPublicKey is a rsa public key Equals checks whether this key is equal to another (*RsaPublicKey) Raw() (res []byte, err error) (*RsaPublicKey) Type() pb.KeyType Verify compares a signature against input data *RsaPublicKey : Key *RsaPublicKey : PubKey
Secp256k1PrivateKey is a Secp256k1 private key Key secp256k1.ModNScalar Equals compares two private keys GetPublic returns a public key Raw returns the bytes of the key Sign returns a signature from input data Type returns the private key type *Secp256k1PrivateKey : Key *Secp256k1PrivateKey : PrivKey
Secp256k1PublicKey is a Secp256k1 public key Equals compares two public keys Raw returns the bytes of the key Type returns the public key type Verify compares a signature against the input data *Secp256k1PublicKey : Key *Secp256k1PublicKey : PubKey
Package-Level Functions (total 31)
ConfigDecodeKey decodes from b64 (for config file) to a byte array that can be unmarshalled.
ConfigEncodeKey encodes a marshalled key to b64 (for config file).
ECDSAKeyPairFromKey generates a new ecdsa private and public key from an input private key
ECDSAPublicKeyFromPubKey generates a new ecdsa public key from an input public key
GenerateECDSAKeyPair generates a new ecdsa private and public key
GenerateECDSAKeyPairWithCurve generates a new ecdsa private and public key with a specified curve
GenerateEd25519Key generates a new ed25519 private and public key pair.
GenerateKeyPair generates a private and public key
GenerateKeyPairWithReader returns a keypair of the given type and bit-size
GenerateRSAKeyPair generates a new rsa private and public key
GenerateSecp256k1Key generates a new Secp256k1 private and public key pair
KeyEqual checks whether two Keys are equivalent (have identical byte representations).
KeyPairFromStdKey wraps standard library (and secp256k1) private keys in libp2p/go-libp2p/core/crypto keys
MarshalECDSAPrivateKey returns x509 bytes from a private key
MarshalECDSAPublicKey returns x509 bytes from a public key
MarshalPrivateKey converts a key object into its protobuf serialized form.
MarshalPublicKey converts a public key object into a protobuf serialized public key
PrivKeyToStdKey converts libp2p/go-libp2p/core/crypto private keys to standard library (and secp256k1) private keys
PubKeyToStdKey converts libp2p/go-libp2p/core/crypto private keys to standard library (and secp256k1) public keys
PublicKeyFromProto converts an unserialized protobuf PublicKey message into its representative object.
PublicKeyToProto converts a public key object into an unserialized protobuf PublicKey message.
UnmarshalECDSAPrivateKey returns a private key from x509 bytes
UnmarshalECDSAPublicKey returns the public key from x509 bytes
UnmarshalEd25519PrivateKey returns a private key from input bytes.
UnmarshalEd25519PublicKey returns a public key from input bytes.
UnmarshalPrivateKey converts a protobuf serialized private key into its representative object
UnmarshalPublicKey converts a protobuf serialized public key into its representative object
UnmarshalRsaPrivateKey returns a private key from the input x509 bytes
UnmarshalRsaPublicKey returns a public key from the input x509 bytes
UnmarshalSecp256k1PrivateKey returns a private key from bytes
UnmarshalSecp256k1PublicKey returns a public key from bytes
Package-Level Variables (total 12)
ECDSACurve is the default ecdsa curve used
ErrBadKeyType is returned when a key is not supported
ErrNilPrivateKey is returned when a nil private key is provided
ErrNilPublicKey is returned when a nil public key is provided
ErrNilSig is returned when the signature is nil
ErrNotECDSAPubKey is returned when the public key passed is not an ecdsa public key
ErrRsaKeyTooSmall is returned when trying to generate or parse an RSA key that's smaller than MinRsaKeyBits bits. In test
KeyTypes is a list of supported keys
PrivKeyUnmarshallers is a map of unmarshallers by key type
PubKeyUnmarshallers is a map of unmarshallers by key type
Package-Level Constants (total 5)
ECDSA is an enum for the supported ECDSA key type
Ed25519 is an enum for the supported Ed25519 key type
RSA is an enum for the supported RSA key type
Secp256k1 is an enum for the supported Secp256k1 key type
WeakRsaKeyEnv is an environment variable which, when set, lowers the minimum required bits of RSA keys to 512. This should be used exclusively in test situations.