Title: [FEATURE REQUEST] Implement ChaCha20 stream cipher · Issue #7753 · TheAlgorithms/Java · GitHub
Open Graph Title: [FEATURE REQUEST] Implement ChaCha20 stream cipher · Issue #7753 · TheAlgorithms/Java
X Title: [FEATURE REQUEST] Implement ChaCha20 stream cipher · Issue #7753 · TheAlgorithms/Java
Description: What would you like to Propose? I would like to propose adding ChaCha20, a modern symmetric-key stream cipher, to the ciphers package. ChaCha20 is a stream cipher that generates a pseudorandom keystream using a 256-bit key, a 96-bit nonc...
Open Graph Description: What would you like to Propose? I would like to propose adding ChaCha20, a modern symmetric-key stream cipher, to the ciphers package. ChaCha20 is a stream cipher that generates a pseudorandom keys...
X Description: What would you like to Propose? I would like to propose adding ChaCha20, a modern symmetric-key stream cipher, to the ciphers package. ChaCha20 is a stream cipher that generates a pseudorandom keys...
Opengraph URL: https://github.com/TheAlgorithms/Java/issues/7753
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE REQUEST] Implement ChaCha20 stream cipher","articleBody":"### What would you like to Propose?\n\nI would like to propose adding **ChaCha20**, a modern symmetric-key stream cipher, to the `ciphers` package.\n\nChaCha20 is a stream cipher that generates a pseudorandom keystream using a 256-bit key, a 96-bit nonce, and a 32-bit block counter. It uses ARX (Addition, Rotation, and XOR) operations to generate 512-bit keystream blocks, which are XORed with plaintext to perform encryption and decryption.\n\nCurrently, the repository contains several classical and modern cryptographic algorithms, but does not appear to include a standalone ChaCha20 implementation.\n\n### Issue details\n\n### Algorithm Name\nChaCha20 Stream Cipher\n\n### Problem Statement\nImplement the ChaCha20 stream cipher in Java following the specification defined in [[RFC 8439](https://www.rfc-editor.org/rfc/rfc8439)](https://www.rfc-editor.org/rfc/rfc8439).\n\nThe implementation should generate a 512-bit keystream block from a 256-bit secret key, a 96-bit nonce, and a 32-bit block counter. The generated keystream should then be XORed with the input data to support encryption and decryption.\n\n### Proposed Implementation\n\nThe implementation should include the following components:\n\n1. **State Initialization:** Initialize the 4 × 4 state matrix using the predefined constants, secret key, counter, and nonce.\n2. **Quarter Round:** Implement the core ARX operations (addition, rotation, and XOR) with the specified rotation constants.\n3. **Round Operations:** Implement the 20-round transformation consisting of column rounds and diagonal rounds.\n4. **Block Generation:** Generate 64-byte keystream blocks by applying the ChaCha20 transformation and adding the original state.\n5. **Encryption:** XOR plaintext bytes with the generated keystream.\n6. **Decryption:** Reuse the same keystream generation process to recover the original plaintext.\n\n### Expected Behavior\n\n- Accept a 256-bit key and a 96-bit nonce.\n- Support arbitrary-length byte-array input.\n- Correctly process inputs spanning multiple 64-byte blocks.\n- Validate key and nonce lengths.\n- Handle empty input.\n- Ensure correct counter progression between blocks.\n- Prevent counter overflow and invalid counter usage.\n\n### Testing Requirements\n\nAdd JUnit tests covering:\n\n- RFC 8439 known test vectors.\n- Quarter-round correctness.\n- Block-function correctness.\n- Encryption and decryption round trips.\n- Empty input.\n- Inputs smaller than, equal to, and larger than 64 bytes.\n- Invalid key and nonce lengths.\n- Multiple-block encryption and decryption.\n- Counter boundary conditions.\n\n### References\n\n- [[RFC 8439 – ChaCha20 and Poly1305 for IETF Protocols](https://www.rfc-editor.org/rfc/rfc8439)](https://www.rfc-editor.org/rfc/rfc8439)\n- [[ChaCha20 Original Specification](https://cr.yp.to/chacha.html)](https://cr.yp.to/chacha.html)\n\n\n### Additional Information\n\n_No response_","author":{"url":"https://github.com/the404packet","@type":"Person","name":"the404packet"},"datePublished":"2026-11-12T13:21:04Z","url":"https://github.com/TheAlgorithms/Java/issues/7753"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6ea57e8e-0e8f-a026-d7dc-3e3c45b1baae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9DA6:3833D:201922:2D3E01:6AFA8A1C |
| html-safe-nonce | 1a7677c916ed63efa2cb7320cfa2b3c2e8eb6d1c394ec5e68e7e31d73968163e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5REE2OjM4MzNEOjIwMTkyMjoyRDNFMDE6NkFGQThBMUMiLCJ2aXNpdG9yX2lkIjoiODkxODU2NTA2NDQyMDI2NDQ3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 31e68fb1897d9c447638b8b86334236b944c1aeacb1e1d7d9d1333168f44b66a |
| hovercard-subject-tag | issue:6350704223 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TheAlgorithms/Java/7753/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5ec17bb596b9de7d8e36859a68c91b031d44717d160ac404d0c7bc1631d8c7a0/TheAlgorithms/Java/issues/7753 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5ec17bb596b9de7d8e36859a68c91b031d44717d160ac404d0c7bc1631d8c7a0/TheAlgorithms/Java/issues/7753 |
| og:image:alt | What would you like to Propose? I would like to propose adding ChaCha20, a modern symmetric-key stream cipher, to the ciphers package. ChaCha20 is a stream cipher that generates a pseudorandom keys... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | the404packet |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-preview |
| go-import | github.com/TheAlgorithms/Java git https://github.com/TheAlgorithms/Java.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 63477660 |
| octolytics-dimension-repository_nwo | TheAlgorithms/Java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63477660 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/Java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width