Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ChaCha20 with LibreSSL #9194

Closed
wants to merge 1 commit into from

Conversation

facutuesca
Copy link
Contributor

This PR adds support for ChaCha20 with LibreSSL. Since cryptography's ChaCha20 uses OpenSSL's implementation (which uses a 64 bit counter + 64 bit nonce), and LibreSSL does the same, it is straightforward to use LibreSSL's API.

The only complication is that the current _CipherContext implementation assumes that the underlying cipher can be accessed through the EVP_CIPHER API. This is not the case for LibreSSL's ChaCha20, which has a separate CRYPTO_chacha_20() API for it.

In order to solve that, this PR makes _CipherContext an abstract class with two implementations, _CipherContextEVP (which is the previous _CipherContext) and _CipherContextChaCha, which is a simple context that is used only for the LibreSSL+ChaCha20 combination.

This means all of the code that uses _CipherContext remains the same, and we only have a single branching point isolated in the create_cipher_context() function, which selects the correct context depending on the cipher+backend.

It also leaves the option open in the future if we want to add BoringSSL's ChaCha20, since we can reuse the same _CipherContextChaCha for it (the API is almost the same, and we can deal with the differences in a C wrapper)

@facutuesca
Copy link
Contributor Author

Needs further work

@facutuesca facutuesca closed this Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant