libp2p.crypto package

Submodules

libp2p.crypto.authenticated_encryption module

class libp2p.crypto.authenticated_encryption.EncryptionParameters(cipher_type: str, hash_type: str, iv: bytes, mac_key: bytes, cipher_key: bytes)

Bases: object

cipher_key: bytes = None
cipher_type: str = None
hash_type: str = None
iv: bytes = None
mac_key: bytes = None
exception libp2p.crypto.authenticated_encryption.InvalidMACException

Bases: Exception

class libp2p.crypto.authenticated_encryption.MacAndCipher(parameters: libp2p.crypto.authenticated_encryption.EncryptionParameters)

Bases: object

authenticate(data: bytes) → bytes
decrypt_if_valid(data_with_tag: bytes) → bytes
encrypt(data: bytes) → bytes
libp2p.crypto.authenticated_encryption.initialize_pair(cipher_type: str, hash_type: str, secret: bytes) → Tuple[libp2p.crypto.authenticated_encryption.EncryptionParameters, libp2p.crypto.authenticated_encryption.EncryptionParameters]

Return a pair of Keys for use in securing a communications channel with authenticated encryption derived from the secret and using the requested cipher_type and hash_type.

libp2p.crypto.ecc module

class libp2p.crypto.ecc.ECCPrivateKey(impl: int, curve: <MagicMock name='mock.curve.Curve' id='140201811228264'>)

Bases: libp2p.crypto.keys.PrivateKey

get_public_key() → libp2p.crypto.keys.PublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

classmethod new(curve: str) → libp2p.crypto.ecc.ECCPrivateKey
sign(data: bytes) → bytes
to_bytes() → bytes

Returns the byte representation of this key.

class libp2p.crypto.ecc.ECCPublicKey(impl: <MagicMock name='mock.point.Point' id='140201691400176'>, curve: <MagicMock name='mock.curve.Curve' id='140201811228264'>)

Bases: libp2p.crypto.keys.PublicKey

classmethod from_bytes(data: bytes, curve: str) → libp2p.crypto.ecc.ECCPublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

to_bytes() → bytes

Returns the byte representation of this key.

verify(data: bytes, signature: bytes) → bool

Verify that signature is the cryptographic signature of the hash of data.

libp2p.crypto.ecc.create_new_key_pair(curve: str) → libp2p.crypto.keys.KeyPair

Return a new ECC keypair with the requested curve type, e.g. “P-256”.

libp2p.crypto.ecc.infer_local_type(curve: str) → <MagicMock name='mock.curve.Curve' id='140201811228264'>

converts a str representation of some elliptic curve to a representation understood by the backend of this module.

libp2p.crypto.ed25519 module

class libp2p.crypto.ed25519.Ed25519PrivateKey(impl: nacl.public.PrivateKey)

Bases: libp2p.crypto.keys.PrivateKey

classmethod from_bytes(data: bytes) → libp2p.crypto.ed25519.Ed25519PrivateKey
get_public_key() → libp2p.crypto.keys.PublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

classmethod new(seed: bytes = None) → libp2p.crypto.ed25519.Ed25519PrivateKey
sign(data: bytes) → bytes
to_bytes() → bytes

Returns the byte representation of this key.

class libp2p.crypto.ed25519.Ed25519PublicKey(impl: nacl.public.PublicKey)

Bases: libp2p.crypto.keys.PublicKey

classmethod from_bytes(key_bytes: bytes) → libp2p.crypto.ed25519.Ed25519PublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

to_bytes() → bytes

Returns the byte representation of this key.

verify(data: bytes, signature: bytes) → bool

Verify that signature is the cryptographic signature of the hash of data.

libp2p.crypto.ed25519.create_new_key_pair(seed: bytes = None) → libp2p.crypto.keys.KeyPair

libp2p.crypto.exceptions module

exception libp2p.crypto.exceptions.CryptographyError

Bases: libp2p.exceptions.BaseLibp2pError

exception libp2p.crypto.exceptions.MissingDeserializerError

Bases: libp2p.crypto.exceptions.CryptographyError

Raise if the requested deserialization routine is missing for some type of cryptographic key.

libp2p.crypto.key_exchange module

libp2p.crypto.key_exchange.create_ephemeral_key_pair(curve_type: str) → Tuple[libp2p.crypto.keys.PublicKey, Callable[[bytes], bytes]]

Facilitates ECDH key exchange.

libp2p.crypto.keys module

class libp2p.crypto.keys.Key

Bases: abc.ABC

A Key represents a cryptographic key.

abstract get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

abstract to_bytes() → bytes

Returns the byte representation of this key.

class libp2p.crypto.keys.KeyPair(private_key: libp2p.crypto.keys.PrivateKey, public_key: libp2p.crypto.keys.PublicKey)

Bases: object

private_key: PrivateKey = None
public_key: PublicKey = None
class libp2p.crypto.keys.KeyType

Bases: enum.Enum

An enumeration.

ECC_P256 = 4
ECDSA = 3
Ed25519 = 1
RSA = 0
Secp256k1 = 2
class libp2p.crypto.keys.PrivateKey

Bases: libp2p.crypto.keys.Key

A PrivateKey represents a cryptographic private key.

classmethod deserialize_from_protobuf(protobuf_data: bytes) → libp2p.crypto.pb.crypto_pb2.PrivateKey
abstract get_public_key() → libp2p.crypto.keys.PublicKey
serialize() → bytes

Return the canonical serialization of this Key.

abstract sign(data: bytes) → bytes
class libp2p.crypto.keys.PublicKey

Bases: libp2p.crypto.keys.Key

A PublicKey represents a cryptographic public key.

classmethod deserialize_from_protobuf(protobuf_data: bytes) → libp2p.crypto.pb.crypto_pb2.PublicKey
serialize() → bytes

Return the canonical serialization of this Key.

abstract verify(data: bytes, signature: bytes) → bool

Verify that signature is the cryptographic signature of the hash of data.

libp2p.crypto.rsa module

class libp2p.crypto.rsa.RSAPrivateKey(impl: Crypto.PublicKey.RSA.RsaKey)

Bases: libp2p.crypto.keys.PrivateKey

get_public_key() → libp2p.crypto.keys.PublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

classmethod new(bits: int = 2048, e: int = 65537) → libp2p.crypto.rsa.RSAPrivateKey
sign(data: bytes) → bytes
to_bytes() → bytes

Returns the byte representation of this key.

class libp2p.crypto.rsa.RSAPublicKey(impl: Crypto.PublicKey.RSA.RsaKey)

Bases: libp2p.crypto.keys.PublicKey

classmethod from_bytes(key_bytes: bytes) → libp2p.crypto.rsa.RSAPublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

to_bytes() → bytes

Returns the byte representation of this key.

verify(data: bytes, signature: bytes) → bool

Verify that signature is the cryptographic signature of the hash of data.

libp2p.crypto.rsa.create_new_key_pair(bits: int = 2048, e: int = 65537) → libp2p.crypto.keys.KeyPair

Returns a new RSA keypair with the requested key size (bits) and the given public exponent e.

Sane defaults are provided for both values.

libp2p.crypto.secp256k1 module

class libp2p.crypto.secp256k1.Secp256k1PrivateKey(impl: coincurve.keys.PrivateKey)

Bases: libp2p.crypto.keys.PrivateKey

classmethod deserialize(data: bytes) → libp2p.crypto.secp256k1.Secp256k1PrivateKey
classmethod from_bytes(data: bytes) → libp2p.crypto.secp256k1.Secp256k1PrivateKey
get_public_key() → libp2p.crypto.keys.PublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

classmethod new(secret: bytes = None) → libp2p.crypto.secp256k1.Secp256k1PrivateKey
sign(data: bytes) → bytes
to_bytes() → bytes

Returns the byte representation of this key.

class libp2p.crypto.secp256k1.Secp256k1PublicKey(impl: coincurve.keys.PublicKey)

Bases: libp2p.crypto.keys.PublicKey

classmethod deserialize(data: bytes) → libp2p.crypto.secp256k1.Secp256k1PublicKey
classmethod from_bytes(data: bytes) → libp2p.crypto.secp256k1.Secp256k1PublicKey
get_type() → libp2p.crypto.keys.KeyType

Returns the KeyType for self.

to_bytes() → bytes

Returns the byte representation of this key.

verify(data: bytes, signature: bytes) → bool

Verify that signature is the cryptographic signature of the hash of data.

libp2p.crypto.secp256k1.create_new_key_pair(secret: bytes = None) → libp2p.crypto.keys.KeyPair

Returns a new Secp256k1 keypair derived from the provided secret, a sequence of bytes corresponding to some integer between 0 and the group order.

A valid secret is created if None is passed.

libp2p.crypto.serialization module

libp2p.crypto.serialization.deserialize_private_key(data: bytes) → libp2p.crypto.keys.PrivateKey
libp2p.crypto.serialization.deserialize_public_key(data: bytes) → libp2p.crypto.keys.PublicKey

Module contents