Module: identity_key_pair

class omemo.identity_key_pair.IdentityKeyPair[source]

Bases: ABC

The identity key pair associated to this device, shared by all backends.

There are following requirements for the identity key pair:

  • It must be able to create and verify Ed25519-compatible signatures.

  • It must be able to perform X25519-compatible Diffie-Hellman key agreements.

There are at least two different kinds of key pairs that can fulfill these requirements: Ed25519 key pairs and Curve25519 key pairs. The birational equivalence of both curves can be used to “convert” one pair to the other.

Both types of key pairs share the same private key, however instead of a private key, a seed can be used which the private key is derived from using SHA-512. This is standard practice for Ed25519, where the other 32 bytes of the SHA-512 seed hash are used as a nonce during signing. If a new key pair has to be generated, this implementation generates a seed.

Note

This is the only actual cryptographic functionality offered by the core library. Everything else is backend-specific.

LOG_TAG = 'omemo.core.identity_key_pair'
async static get(storage)[source]

Get the identity key pair.

Parameters

storage (Storage) – The storage for all OMEMO-related data.

Return type

IdentityKeyPair

Returns

The identity key pair, which has either been loaded from storage or newly generated.

Note

There is only one identity key pair for storage instance. All instances of this class refer to the same storage locations, thus the same data.

abstract property is_seed: bool

Returns: Whether this is a IdentityKeyPairSeed.

Return type

bool

abstract property is_priv: bool

Returns: Whether this is a IdentityKeyPairPriv.

Return type

bool

abstract as_priv()[source]
Return type

IdentityKeyPairPriv

Returns

An IdentityKeyPairPriv derived from this instance (if necessary).

abstract property identity_key: Ed25519Pub

Returns: The public part of this identity key pair, in Ed25519 format.

Return type

bytes

class omemo.identity_key_pair.IdentityKeyPairPriv(priv)[source]

Bases: IdentityKeyPair

An IdentityKeyPair represented by a private key.

Parameters

priv (Priv) –

__init__(priv)[source]
Parameters

priv (bytes) – The Curve25519/Ed25519 private key.

Return type

None

property is_seed: bool

Returns: Whether this is a IdentityKeyPairSeed.

Return type

bool

property is_priv: bool

Returns: Whether this is a IdentityKeyPairPriv.

Return type

bool

as_priv()[source]
Return type

IdentityKeyPairPriv

Returns

An IdentityKeyPairPriv derived from this instance (if necessary).

property identity_key: Ed25519Pub

Returns: The public part of this identity key pair, in Ed25519 format.

Return type

bytes

property priv: Priv

Returns: The Curve25519/Ed25519 private key.

Return type

bytes

class omemo.identity_key_pair.IdentityKeyPairSeed(seed)[source]

Bases: IdentityKeyPair

An IdentityKeyPair represented by a seed.

Parameters

seed (Seed) –

__init__(seed)[source]
Parameters

seed (bytes) – The Curve25519/Ed25519 seed.

Return type

None

property is_seed: bool

Returns: Whether this is a IdentityKeyPairSeed.

Return type

bool

property is_priv: bool

Returns: Whether this is a IdentityKeyPairPriv.

Return type

bool

as_priv()[source]
Return type

IdentityKeyPairPriv

Returns

An IdentityKeyPairPriv derived from this instance (if necessary).

property identity_key: Ed25519Pub

Returns: The public part of this identity key pair, in Ed25519 format.

Return type

bytes

property seed: Seed

Returns: The Curve25519/Ed25519 seed.

Return type

bytes