Tools related to symmetric ciphers¶
Cryptodome backend specific templates and tools for symmetric ciphers.
- class pyflocker.ciphers.backends.cryptodome_.symmetric.NonAEADCipherTemplate[source]¶
Bases:
BaseNonAEADCipherTemplate class to provide the default behavior of BaseNonAEADCipher.
Subclasses need to provide:
_encrypting_update_func
- is_encrypting() bool[source]¶
Whether the cipher is encrypting or not.
- Returns:
Trueif encrypting, elseFalse.
- update(data: bytes) bytes[source]¶
Takes bytes-like object and returns encrypted/decrypted bytes object.
- Parameters:
data – The bytes-like object to pass to the cipher.
- Returns:
Encrypted/decrypted data as bytes.
- update_into(data: bytes, out: bytearray | memoryview) None[source]¶
Encrypt or decrypt the
dataand store it in a preallocated bufferout.- Parameters:
data – The bytes-like object to pass to the cipher.
out – The buffer interface where the encrypted/decrypted data must be written into.
- finalize() None[source]¶
Finalizes and closes the cipher.
- Raises:
AlreadyFinalized – If the cipher was already finalized.
- class pyflocker.ciphers.backends.cryptodome_.symmetric.AuthenticationMixin[source]¶
Bases:
objectMixin class to provide authentication behavior to ciphers.
Classes inheriting this must provide these attributes:
- _cipher¶
A cipher from Cryptodome package that has
update()andverify()methods.- Type:
Any
- _update_func¶
A method of
_cipherthat encrypts/decrypts data. It is generally_cipher.encrypt()or_cipher.decrypt().- Type:
Callable
- _tag¶
A byte sequence denoting the MAC tag generated by the cipher after encryption.
- Type:
bytes | None
- authenticate(data: bytes) None[source]¶
Authenticates part of the message that get delivered as is, without any encryption.
- Parameters:
data – The bytes-like object that must be authenticated.
- Raises:
TypeError – if this method is called after calling
update().
- finalize(tag: bytes | None = None) None[source]¶
Finalizes and ends the cipher state.
- Parameters:
tag – The associated tag that authenticates the decryption. Tag is required for decryption only.
- Raises:
ValueError – If cipher is decrypting and tag is not supplied.
DecryptionError – If the decryption was incorrect.
- class pyflocker.ciphers.backends.cryptodome_.symmetric.AEADCipherTemplate[source]¶
Bases:
AuthenticationMixin,BaseAEADCipherTemplate class to provide the default behavior of BaseAEADCipher.
Subclasses need to provide the following attributes:
_encrypting_update_func_cipher
- is_encrypting() bool[source]¶
Whether the cipher is encrypting or not.
- Returns:
Trueif encrypting, elseFalse.