ChaCha20

ChaCha20 and ChaCha20Poly1305 cipher implementation classes.

class pyflocker.ciphers.backends.cryptography_.ChaCha20.ChaCha20Poly1305(encrypting: bool, key: bytes, nonce: bytes)[source]

Bases: BaseAEADCipher

ChaCha20Poly1305 Cipher class.

is_encrypting() bool[source]

Whether the cipher is encrypting or not.

Returns:

True if encrypting, else False.

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().

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: memoryview | bytearray) None[source]

Encrypt or decrypt the data and store it in a preallocated buffer out.

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(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:
calculate_tag() bytes | None[source]

Calculates and returns the associated tag.

Returns:

Returns None if decrypting, otherwise the associated authentication tag.

class pyflocker.ciphers.backends.cryptography_.ChaCha20.ChaCha20(encrypting: bool, key: bytes, nonce: bytes)[source]

Bases: NonAEADCipherTemplate

ChaCha20 Cipher class.

This class alone does not provide any authentication. For AEAD purposes, wrap ChaCha20 object with a class that implements BaseAEADCipher or use ChaCha20Poly1305.

pyflocker.ciphers.backends.cryptography_.ChaCha20.new(encrypting: bool, key: bytes, nonce: bytes, *, use_poly1305: bool = True, file: io.BufferedIOBase | None = None) ChaCha20 | ChaCha20Poly1305 | FileCipherWrapper[source]

Instantiate a new ChaCha20(-Poly1305) cipher object.

Parameters:
  • encrypting – True is encryption and False is decryption.

  • key – The key for the cipher.

  • nonce – The Nonce for the cipher. It must not be repeated with the same key.

Keyword Arguments:
  • use_poly1305 – Whether to use Poly1305 MAC with ChaCha20 cipher.

  • file – The source file to read from.

Returns:

ChaCha20(-Poly1305) cipher wrapper object.

Note

Any other error that is raised is from the backend itself.