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 XChaCha20 and XChaCha20-Poly1305 (IETF draft-irtf-cfrg-xchacha) #1011

Merged

Conversation

zssz
Copy link
Contributor

@zssz zssz commented Apr 19, 2023

Checklist:

  • Correct file headers (see CONTRIBUTING.md).
  • Formatted with SwiftFormat.
  • Tests added.

Changes proposed in this pull request:

This PR introduces support for the XChaCha20 and XChaCha20-Poly1305 encryption algorithms, as specified in the IETF draft-irtf-cfrg-xchacha. The implementation leverages the existing ChaCha20 implementation by extending its functionality to support XChaCha20 and AEADXChaCha20Poly1305. New classes, XChaCha20 and AEADXChaCha20Poly1305, along with their respective test classes, XChaCha20Tests and XChaCha20Poly1305Tests, have been added. The test cases cover the HChaCha20 block function and encryption-decryption operations with the specified test vectors from the IETF draft documentation.

To accommodate the XChaCha20 variant, the ChaCha20 initializer has been updated with an optional blockCounter parameter and a new convenience initializer. The convenience initializer accepts key and nonce parameters and internally calls the main initializer with a default blockCounter value of 0. This allows for proper handling of the block counter, which is necessary for XChaCha20's extended nonce size, ensuring correct encryption and decryption behavior.

These changes provide users with access to the XChaCha20 and XChaCha20-Poly1305 encryption algorithms for enhanced security and performance, broadening the library's cryptographic capabilities.

Note
Parts of the code in this PR were contributed with the assistance of ChatGPT [2023] Mar 23 Version.

@zssz zssz changed the title Feat/draft irtf cfrg xchacha 03 Add XChaCha20 and XChaCha20-Poly1305 (IETF draft-irtf-cfrg-xchacha) Apr 19, 2023
Copy link
Owner

@krzyzanowskim krzyzanowskim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! It's well-rounded PR 👏

@krzyzanowskim krzyzanowskim merged commit 6dd9cfe into krzyzanowskim:main Sep 4, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants