Module: crypto_provider
- class doubleratchet.recommended.crypto_provider.CryptoProvider[source]
Bases:
ABCAbstraction of the cryptographic operations needed by this package to allow for different backend implementations.
- abstractmethod async static hkdf_derive(hash_function, length, salt, info, key_material)[source]
- Parameters:
hash_function (
HashFunction) – The hash function to parameterize the HKDF with.length (
int) – The number of bytes to derive.salt (
bytes) – The salt input for the HKDF.info (
bytes) – The info input for the HKDF.key_material (
bytes) – The input key material to derive from.
- Return type:
- Returns:
The derived key material.
- abstractmethod async static hmac_calculate(key, hash_function, data)[source]
- Parameters:
key (
bytes) – The authentication key.hash_function (
HashFunction) – The hash function to parameterize the HMAC with.data (
bytes) – The data to authenticate.
- Return type:
- Returns:
The authentication tag.
- abstractmethod async static aes_cbc_encrypt(key, initialization_vector, plaintext)[source]
Encrypt plaintext with AES-CBC. The plaintext is padded with PKCS#7 before encryption.
- Parameters:
- Return type:
- Returns:
The ciphertext obtained by padding the plaintext with PKCS#7 and then encrypting it with AES-CBC.
- abstractmethod async static aes_cbc_decrypt(key, initialization_vector, ciphertext)[source]
Decrypt plaintext with AES-CBC. The plaintext is unpadded with PKCS#7 after decryption.
- Parameters:
- Return type:
- Returns:
The plaintext obtained by decrypting it with AES-CBC and unpadding the result with PKCS#7.
- Raises:
DecryptionFailedException – on decryption or unpadding failure.
- class doubleratchet.recommended.crypto_provider.HashFunction(*values)[source]
Bases:
EnumEnumeration of the three hash functions that can be used with
doubleratchet.recommended.aead_aes_hmac.AEAD,doubleratchet.recommended.kdf_hkdf.KDFanddoubleratchet.recommended.kdf_separate_hmacs.KDF. The three hash functions are SHA-256, SHA-512, and truncated SHA-512 to 256 bits.- SHA_256 = 'SHA_256'
- SHA_512 = 'SHA_512'
- SHA_512_256 = 'SHA_512_256'