ChaCha20 Python wrapper¶
ChaCha20 and ChaCha20-Poly1305 encryption and decryption can be tested with Python wrappers.
To get a template using the CLI, run:
crypto-condor-cli get-wrapper ChaCha20 --language Python
There is a practical example with PyCryptodome:
crypto-condor-cli get-wrapper ChaCha20 --language Python --example 1
Encrypt¶
To test an implementation of ChaCha20 encryption, the function must:
follow the naming convention;
implement the
Encrypt
protocol.
Naming convention¶
CC_ChaCha20_encrypt
Protocol¶
- protocol crypto_condor.primitives.ChaCha20.Encrypt
Represents a function that encrypts with ChaCha20.
Classes that implement this protocol must have the following methods / attributes:
- __call__(key, pt, nonce, init_counter=0)
Encrypts with ChaCha20.
- Parameters:
key (bytes) – The symmetric key.
pt (bytes) – The plaintext to encrypt.
nonce (bytes) – The nonce.
init_counter (int) – A position to seek in the keystream before encrypting, in bytes.
- Returns:
The ciphertext.
- Return type:
bytes
Decrypt¶
To test an implementation of ChaCha20 decryption, the function must:
follow the naming convention;
implement the
Decrypt
protocol.
Naming convention¶
CC_ChaCha20_encrypt
Protocol¶
- protocol crypto_condor.primitives.ChaCha20.Decrypt
Represents a function that decrypts with ChaCha20.
Classes that implement this protocol must have the following methods / attributes:
- __call__(key, ct, nonce, init_counter=0)
Decrypts with ChaCha20.
- Parameters:
key (bytes) – The symmetric key.
ct (bytes) – The ciphertext to decrypt.
nonce (bytes) – The nonce.
- Keyword Arguments:
init_counter – A position to seek in the keystream before encrypting, in bytes.
- Returns:
The plaintext.
- Return type:
bytes
Encrypt with Poly1305¶
To test an implementation of ChaCha20-Poly1305 authenticated encryption, the function must:
follow the naming convention;
implement the
EncryptPoly
protocol.
Naming convention¶
CC_ChaCha20_encrypt_poly
Protocol¶
- protocol crypto_condor.primitives.ChaCha20.EncryptPoly
Represents a function that encrypts with ChaCha20-Poly1305.
Classes that implement this protocol must have the following methods / attributes:
- __call__(key, pt, nonce, aad)
Encrypts with ChaCha20-Poly1305.
- Parameters:
key (bytes) – The symmetric key.
pt (bytes) – The plaintext to encrypt.
nonce (bytes) – The nonce.
aad (bytes) – The associated data.
- Returns:
A tuple containing the ciphertext and the MAC tag.
- Raises:
ValueError – If an input is incorrect (e.g. the nonce size is invalid).
- Return type:
tuple[bytes, bytes]
Decrypt¶
To test an implementation of ChaCha20-Poly1305 authenticated decryption, the function must:
follow the naming convention;
implement the
DecryptPoly
protocol.
Naming convention¶
CC_ChaCha20_decrypt_poly
Protocol¶
- protocol crypto_condor.primitives.ChaCha20.DecryptPoly
Represents a function that decrypts with ChaCha20-Poly1305.
Classes that implement this protocol must have the following methods / attributes:
- __call__(key, ct, nonce, tag, aad)
Decrypts with ChaCha20-Poly1305.
- Parameters:
key (bytes) – The symmetric key.
ct (bytes) – The ciphertext to decrypt.
nonce (bytes) – The 12-byte nonce.
tag (bytes) – The MAC tag.
aad (bytes) – The associated data.
- Returns:
The decrypted plaintext.
- Raises:
ValueError – If an input is incorrect (e.g. the nonce size is not 12 bytes) or if the MAC verification failed.
- Return type:
bytes | None