namespace
cryptoCryptography related types.
Classes
- struct AccountObject
- Wrapper for the olm account object.
- class crypto_exception
- Exception thrown for various encryption related errors (not reported by olm), that generally should not be ignored.
- struct CURVE25519_AES_SHA2_Encrypted
- Base64 encoded CURVE25519_AES_SHA2 encrypted text, including the mac and ephemeral key.
- struct ExportedSession
- An exported megolm group session.
- struct ExportedSessionKeys
- A list of exported sessions.
- struct GroupPlaintext
- Return value from decrypting a group message.
- struct HkdfKeys
- HKDF key derivation with SHA256 digest.
- struct IdentityKeys
- A pair of keys connected to an olm account.
- struct InboundSessionObject
- Wrapper around the olm object for inbound group sessions used to decrypt messages in matrix rooms.
- class olm_exception
- Errors returned by the olm library.
- class OlmClient
- Client for all the cryptography related functionality like olm accounts, session keys encryption, signing and a few more things.
- struct OlmDeleter
- Deleter type to pass as a template argument to most smart pointers.
- struct OneTimeKeys
- A list of one time keys.
- struct OutboundSessionObject
- Wrapper around the outbound olm session object used to encrypt outbound group messages in matrix rooms.
- struct PkDecryptionObject
- Wrapper for the olm object to do Private Key Decryption.
- struct PkEncryptionObject
- Wrapper for the olm object to do Private Key Decryption.
- struct PkSigning
- Helper to sign arbitrary messages using an ed25519 key.
- struct PkSigningObject
- Wrapper for the olm object to do Private Key Signing.
- struct SAS
- Helper to generate Short Authentication Strings (SAS)
- struct SASObject
- Olm type for Short Authentication Strings.
- struct SessionObject
- Wrapper around olm sessions used for to device encryption.
- struct UtilityObject
- Wrapper for the Olm utility object.
Typedefs
- using BinaryBuf = std::vector<uint8_t>
- Data representation used to interact with libolm.
Functions
-
template<class T>auto pickle(typename T::olm_type* object, const std::string& key) -> std::string
- Serialize olm objects into strings encrypted using key to persist them on non volatile storage.
-
template<class T>auto unpickle(const std::string& pickled, const std::string& key) -> std::unique_ptr<typename T::olm_type, OlmDeleter>
- Deserialize olm objects from strings encrypted using key previously persisted on non volatile storage.
- auto session_id(OlmSession* s) -> std::string
- Retrieve the session id for an Olm session.
- auto session_id(OlmOutboundGroupSession* s) -> std::string
- Retrieve the session id.
- auto session_key(OlmOutboundGroupSession* s) -> std::string
- Retrieve the session key from an outbound megolm session.
- auto import_session(const std::string& session_key) -> InboundGroupSessionPtr
- Create an inbound megolm session from an exported session key.
- auto matches_inbound_session(OlmSession* session, const std::string& one_time_key_message) -> bool
- Checks if an inbound session matches a pre key message.
- auto matches_inbound_session_from(OlmSession* session, const std::string& id_key, const std::string& one_time_key_message) -> bool
- Checks if an inbound session matches a pre key message.
-
auto encrypt_exported_sessions(const mtx::
crypto:: ExportedSessionKeys& keys, const std::string& pass) -> std::string - Encrypt the exported sessions according to the export format from the spec.
-
auto decrypt_exported_sessions(const std::string& data,
const std::string& pass) -> mtx::
crypto:: ExportedSessionKeys - Decrypt the exported sessions according to the export format from the spec.
- auto verify_identity_signature(const DeviceKeys& device_keys, const DeviceId& device_id, const UserId& user_id) -> bool
- Verify a signature object as obtained from the response of /keys/query endpoint.
- auto ed25519_verify_signature(std::string signing_key, nlohmann::json obj, std::string signature) -> bool
- Verify an ed25519 signature.
-
template<class T>auto create_olm_object() -> std::unique_ptr<typename T::olm_type, OlmDeleter>
- Allocates an olm object using the mtxclient wrapper type.
- auto create_buffer(std::size_t nbytes) -> BinaryBuf
- Create a uint8_t buffer which is initialized with random bytes.
- auto to_binary_buf(std::string_view str) -> BinaryBuf
- Convert a string to a binary buffer.
- auto to_string(const BinaryBuf& buf) -> std::string
- Convert a binary buffer to a string.
- auto compatible_iv(BinaryBuf incompatible_iv) -> BinaryBuf
- Sets bit 63 to 0 to be compatible with other AES implementations.
- auto key_to_recoverykey(const BinaryBuf& key) -> std::string
- encodes a recovery key in base58 with parity and version tag,
- auto PBKDF2_HMAC_SHA_512(const std::string& pass, const BinaryBuf& salt, uint32_t iterations, uint32_t keylen = 64) -> BinaryBuf
- Simple wrapper around the OpenSSL PKCS5_PBKDF2_HMAC function.
-
auto key_from_passphrase(const std::string& password,
const mtx::
secret_storage:: AesHmacSha2KeyDescription& parameters) -> std::optional<BinaryBuf> - Derive the SSSS decryption key from a passphrase using the parameters stored in account_data.
-
auto key_from_recoverykey(const std::string& recoverkey,
const mtx::
secret_storage:: AesHmacSha2KeyDescription& parameters) -> std::optional<BinaryBuf> - Derive the SSSS decryption key from a base58 encoded recoverykey using the parameters stored in account_data.
-
auto decrypt(const mtx::
secret_storage:: AesHmacSha2EncryptedData& data, const BinaryBuf& decryptionKey, std::string_view key_name) -> std::string - Decrypt a secret from SSSS.
-
auto encrypt(const std::string& data,
const BinaryBuf& decryptionKey,
std::string_view key_name) -> mtx::
secret_storage:: AesHmacSha2EncryptedData - Encrypt a secret for SSSS.
-
auto CURVE25519_AES_SHA2_Encrypt(const std::string& plaintext,
const std::string& base64_publicKey) -> CURVE25519_
AES_ SHA2_ Encrypted - encypts a plaintext payload using CURVE25519_AES_SHA2
- auto CURVE25519_public_key_from_private(const BinaryBuf& privateKey) -> std::string
- returns base64 encoded pubkey
-
auto encrypt_session(const mtx::
responses:: backup:: SessionData& data, const std::string& publicKey) -> mtx:: responses:: backup:: EncryptedSessionData - encrypt a session for online key backup
-
auto decrypt_session(const mtx::
responses:: backup:: EncryptedSessionData& data, const BinaryBuf& privateKey) -> mtx:: responses:: backup:: SessionData - Decrypt a session retrieved from online key backup.
- auto sha256(const std::string& data) -> std::string
- Sha256 a string.
-
auto decrypt_file(const std::string& ciphertext,
const mtx::
crypto:: EncryptedFile& encryption_info) -> BinaryBuf - Decrypt matrix EncryptedFile.
-
auto encrypt_file(const std::string& plaintext) -> std::pair<BinaryBuf, mtx::
crypto:: EncryptedFile> - Encrypt matrix EncryptedFile.
- auto unpack_key_file(const std::string& data) -> std::string
- Translates the data back into the binary buffer, taking care to remove the header and footer elements.
- auto base642bin(const std::string& b64) -> std::string
- Convert base64 to binary.
- auto bin2base64(const std::string& bin) -> std::string
- Encode a binary string in base64.
- auto base642bin_unpadded(const std::string& b64) -> std::string
- Decode unpadded base64 to binary.
- auto bin2base64_unpadded(const std::string& bin) -> std::string
- Encode binary in unpadded base64.
- auto base642bin_urlsafe_unpadded(const std::string& b64) -> std::string
- Decode urlsafe, unpadded base64 to binary.
- auto bin2base64_urlsafe_unpadded(const std::string& bin) -> std::string
- Encode binary in urlsafe, unpadded base64.
- auto bin2base58(const std::string& bin) -> std::string
- Encode binary in base58.
- auto base582bin(const std::string& bin) -> std::string
- Decode base58 to binary.
Variables
- std::string_view ED25519
- Constant for ed25519 keys.
- std::string_view CURVE25519
- Constant for curve25519 keys.
- std::string_view SIGNED_CURVE25519
- Constant for signed curve25519 keys.
- std::string_view MEGOLM_ALGO
- The algorithm used for group messages.
Typedef documentation
typedef std::vector<uint8_t> mtx:: crypto:: BinaryBuf
Data representation used to interact with libolm.
Data representation used to interact with libolm. It's a contiguous buffer of bytes.
Function documentation
template<class T>
std::string mtx:: crypto:: pickle(typename T::olm_type* object,
const std::string& key)
Serialize olm objects into strings encrypted using key to persist them on non volatile storage.
template<class T>
std::unique_ptr<typename T::olm_type, OlmDeleter> mtx:: crypto:: unpickle(const std::string& pickled,
const std::string& key)
Deserialize olm objects from strings encrypted using key previously persisted on non volatile storage.
std::string mtx:: crypto:: session_id(OlmSession* s)
Retrieve the session id for an Olm session.
std::string mtx:: crypto:: session_id(OlmOutboundGroupSession* s)
Retrieve the session id.
std::string mtx:: crypto:: session_key(OlmOutboundGroupSession* s)
Retrieve the session key from an outbound megolm session.
InboundGroupSessionPtr mtx:: crypto:: import_session(const std::string& session_key)
Create an inbound megolm session from an exported session key.
bool mtx:: crypto:: matches_inbound_session(OlmSession* session,
const std::string& one_time_key_message)
Checks if an inbound session matches a pre key message.
Use matches_
bool mtx:: crypto:: matches_inbound_session_from(OlmSession* session,
const std::string& id_key,
const std::string& one_time_key_message)
Checks if an inbound session matches a pre key message.
std::string mtx:: crypto:: encrypt_exported_sessions(const mtx:: crypto:: ExportedSessionKeys& keys,
const std::string& pass)
Encrypt the exported sessions according to the export format from the spec.
mtx:: crypto:: ExportedSessionKeys mtx:: crypto:: decrypt_exported_sessions(const std::string& data,
const std::string& pass)
Decrypt the exported sessions according to the export format from the spec.
bool mtx:: crypto:: verify_identity_signature(const DeviceKeys& device_keys,
const DeviceId& device_id,
const UserId& user_id)
Verify a signature object as obtained from the response of /keys/query endpoint.
bool mtx:: crypto:: ed25519_verify_signature(std::string signing_key,
nlohmann::json obj,
std::string signature)
Verify an ed25519 signature.
template<class T>
std::unique_ptr<typename T::olm_type, OlmDeleter> mtx:: crypto:: create_olm_object()
Allocates an olm object using the mtxclient wrapper type.
BinaryBuf mtx:: crypto:: create_buffer(std::size_t nbytes)
#include <include/mtxclient/crypto/utils.hpp>
Create a uint8_t buffer which is initialized with random bytes.
BinaryBuf mtx:: crypto:: to_binary_buf(std::string_view str)
#include <include/mtxclient/crypto/utils.hpp>
Convert a string to a binary buffer.
std::string mtx:: crypto:: to_string(const BinaryBuf& buf)
#include <include/mtxclient/crypto/utils.hpp>
Convert a binary buffer to a string.
BinaryBuf mtx:: crypto:: compatible_iv(BinaryBuf incompatible_iv)
#include <include/mtxclient/crypto/utils.hpp>
Sets bit 63 to 0 to be compatible with other AES implementations.
std::string mtx:: crypto:: key_to_recoverykey(const BinaryBuf& key)
#include <include/mtxclient/crypto/utils.hpp>
encodes a recovery key in base58 with parity and version tag,
BinaryBuf mtx:: crypto:: PBKDF2_HMAC_SHA_512(const std::string& pass,
const BinaryBuf& salt,
uint32_t iterations,
uint32_t keylen = 64)
#include <include/mtxclient/crypto/utils.hpp>
Simple wrapper around the OpenSSL PKCS5_PBKDF2_HMAC function.
std::optional<BinaryBuf> mtx:: crypto:: key_from_passphrase(const std::string& password,
const mtx:: secret_storage:: AesHmacSha2KeyDescription& parameters)
#include <include/mtxclient/crypto/utils.hpp>
Derive the SSSS decryption key from a passphrase using the parameters stored in account_data.
std::optional<BinaryBuf> mtx:: crypto:: key_from_recoverykey(const std::string& recoverkey,
const mtx:: secret_storage:: AesHmacSha2KeyDescription& parameters)
#include <include/mtxclient/crypto/utils.hpp>
Derive the SSSS decryption key from a base58 encoded recoverykey using the parameters stored in account_data.
std::string mtx:: crypto:: decrypt(const mtx:: secret_storage:: AesHmacSha2EncryptedData& data,
const BinaryBuf& decryptionKey,
std::string_view key_name)
#include <include/mtxclient/crypto/utils.hpp>
Decrypt a secret from SSSS.
mtx:: secret_storage:: AesHmacSha2EncryptedData mtx:: crypto:: encrypt(const std::string& data,
const BinaryBuf& decryptionKey,
std::string_view key_name)
#include <include/mtxclient/crypto/utils.hpp>
Encrypt a secret for SSSS.
CURVE25519_ AES_ SHA2_ Encrypted mtx:: crypto:: CURVE25519_AES_SHA2_Encrypt(const std::string& plaintext,
const std::string& base64_publicKey)
#include <include/mtxclient/crypto/utils.hpp>
encypts a plaintext payload using CURVE25519_AES_SHA2
std::string mtx:: crypto:: CURVE25519_public_key_from_private(const BinaryBuf& privateKey)
#include <include/mtxclient/crypto/utils.hpp>
returns base64 encoded pubkey
mtx:: responses:: backup:: EncryptedSessionData mtx:: crypto:: encrypt_session(const mtx:: responses:: backup:: SessionData& data,
const std::string& publicKey)
#include <include/mtxclient/crypto/utils.hpp>
encrypt a session for online key backup
mtx:: responses:: backup:: SessionData mtx:: crypto:: decrypt_session(const mtx:: responses:: backup:: EncryptedSessionData& data,
const BinaryBuf& privateKey)
#include <include/mtxclient/crypto/utils.hpp>
Decrypt a session retrieved from online key backup.
std::string mtx:: crypto:: sha256(const std::string& data)
#include <include/mtxclient/crypto/utils.hpp>
Sha256 a string.
BinaryBuf mtx:: crypto:: decrypt_file(const std::string& ciphertext,
const mtx:: crypto:: EncryptedFile& encryption_info)
#include <include/mtxclient/crypto/utils.hpp>
Decrypt matrix EncryptedFile.
std::pair<BinaryBuf, mtx:: crypto:: EncryptedFile> mtx:: crypto:: encrypt_file(const std::string& plaintext)
#include <include/mtxclient/crypto/utils.hpp>
Encrypt matrix EncryptedFile.
std::string mtx:: crypto:: unpack_key_file(const std::string& data)
#include <include/mtxclient/crypto/utils.hpp>
Translates the data back into the binary buffer, taking care to remove the header and footer elements.
std::string mtx:: crypto:: base642bin(const std::string& b64)
#include <include/mtxclient/crypto/utils.hpp>
Convert base64 to binary.
std::string mtx:: crypto:: bin2base64(const std::string& bin)
#include <include/mtxclient/crypto/utils.hpp>
Encode a binary string in base64.
std::string mtx:: crypto:: base642bin_unpadded(const std::string& b64)
#include <include/mtxclient/crypto/utils.hpp>
Decode unpadded base64 to binary.
std::string mtx:: crypto:: bin2base64_unpadded(const std::string& bin)
#include <include/mtxclient/crypto/utils.hpp>
Encode binary in unpadded base64.
std::string mtx:: crypto:: base642bin_urlsafe_unpadded(const std::string& b64)
#include <include/mtxclient/crypto/utils.hpp>
Decode urlsafe, unpadded base64 to binary.
std::string mtx:: crypto:: bin2base64_urlsafe_unpadded(const std::string& bin)
#include <include/mtxclient/crypto/utils.hpp>
Encode binary in urlsafe, unpadded base64.
std::string mtx:: crypto:: bin2base58(const std::string& bin)
#include <include/mtxclient/crypto/utils.hpp>
Encode binary in base58.
std::string mtx:: crypto:: base582bin(const std::string& bin)
#include <include/mtxclient/crypto/utils.hpp>
Decode base58 to binary.
Variable documentation
std::string_view mtx:: crypto:: ED25519
#include <include/mtxclient/crypto/types.hpp>
Constant for ed25519 keys.
std::string_view mtx:: crypto:: CURVE25519
#include <include/mtxclient/crypto/types.hpp>
Constant for curve25519 keys.
std::string_view mtx:: crypto:: SIGNED_CURVE25519
#include <include/mtxclient/crypto/types.hpp>
Constant for signed curve25519 keys.
std::string_view mtx:: crypto:: MEGOLM_ALGO
#include <include/mtxclient/crypto/types.hpp>
The algorithm used for group messages.