{"id":19213711,"url":"https://github.com/carlosmakin/chacha20","last_synced_at":"2025-11-14T00:05:57.646Z","repository":{"id":218668741,"uuid":"747050870","full_name":"carlosmakin/chacha20","owner":"carlosmakin","description":"An implementation of the symmetric ChaCha20 cipher, Poly1305 (MAC), and ChaCha20-Poly1305 (AEAD) scheme as per RFC 8439.","archived":false,"fork":false,"pushed_at":"2024-07-29T15:26:39.000Z","size":96,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-04T17:47:34.755Z","etag":null,"topics":["chacha20","chacha20-poly1305","dart","poly1305","rfc8439"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/carlosmakin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-23T06:54:52.000Z","updated_at":"2024-07-29T15:26:43.000Z","dependencies_parsed_at":"2024-01-26T08:31:10.864Z","dependency_job_id":"1b3a83e9-a9b8-4ed1-b218-3d6d134ac2ca","html_url":"https://github.com/carlosmakin/chacha20","commit_stats":null,"previous_names":["carlosmakin/chacha","carlosmakin/chacha20"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosmakin%2Fchacha20","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosmakin%2Fchacha20/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosmakin%2Fchacha20/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosmakin%2Fchacha20/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carlosmakin","download_url":"https://codeload.github.com/carlosmakin/chacha20/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240286516,"owners_count":19777353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chacha20","chacha20-poly1305","dart","poly1305","rfc8439"],"created_at":"2024-11-09T14:07:16.696Z","updated_at":"2025-11-14T00:05:57.634Z","avatar_url":"https://github.com/carlosmakin.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ChaCha20 💃\n\n### Overview\n\nThis repository hosts an implementation of the ChaCha20 stream cipher, and Poly1305 message authentication code as per [RFC 8439](https://www.rfc-editor.org/rfc/rfc8439). These cryptographic algorithms offer robust solutions for ensuring data confidentiality, integrity, and authenticity.\n\n### ChaCha20\n\nChaCha20 is a modern stream cipher known for its speed and security. It is designed to provide strong encryption and has become a popular choice in various cryptographic protocols, such as TLS and secure messaging applications.\n\n#### Key Features:\n- **High Speed**: Excels in software implementations, especially on platforms without specialized hardware support for cryptography.\n- **Security**: Designed to be secure against a wide range of cryptographic attacks.\n- **Flexibility**: Easily adaptable for both large data encryption and real-time data streaming.\n\n#### Best Practices:\n- Ensure unique nonces for each encryption operation.\n- Securely manage and store encryption keys.\n\n### Poly1305\n\nPoly1305 is a fast and secure message authentication code (MAC) that works in conjunction with a cipher like ChaCha20. It provides a strong level of assurance against message tampering.\n\n#### Key Features:\n- **Efficiency**: Exceptionally fast, making it suitable for high-throughput applications.\n- **Security**: Offers strong guarantees of authenticity.\n- **One-Time Key Usage**: Each key must only be used once to maintain security.\n\n#### Best Practices:\n- Never reuse a key; always generate a new key for each message.\n- Combine with a secure cipher like ChaCha20 for complete data protection.\n\n### ChaCha20-Poly1305 AEAD\n\nChaCha20-Poly1305 AEAD combines the strengths of ChaCha20 and Poly1305, encrypting and authenticating data in a single step. It's recommended for scenarios where both confidentiality and integrity are crucial.\n\n#### Key Features:\n- **Authenticated Encryption**: Simultaneously encrypts and authenticates data.\n- **Nonce-Misuse Resistance**: Provides security even if nonces are reused (though nonce reuse is not recommended).\n- **Efficient**: Leverages the performance benefits of ChaCha20 and Poly1305.\n\n#### Best Practices:\n- Avoid nonce reuse to ensure the highest level of security.\n- Verify the authenticity of decrypted data before using it.\n\n## Background and History\n\n### ChaCha20\n\nDeveloped by Daniel J. Bernstein, ChaCha20 is an evolution of the earlier Salsa20 cipher. It was designed to provide strong cryptographic security while being highly efficient in software implementations.\n\n### Poly1305\n\nAlso developed by Daniel J. Bernstein, Poly1305 provides a way to authenticate messages securely and is often used in combination with ciphers like ChaCha20.\n\n### RFC 8439\n\nRFC 8439 standardizes the algorithms and provides comprehensive guidelines for their implementation and use, ensuring consistency and security across different applications.\n\n## Benchmarks\n\n### Performance\n\nBenchmarks were conducted on a MacBook Pro with the following specifications:\n- **Chip**: Apple M2 Max\n- **Memory**: 32GB\n\nThe benchmarks were performed by processing 1,000,000 bytes in each of 10 runs for each operation. The runtimes and throughput are as follows:\n\n| Operation           | Runtime (µs)        | Throughput (MB/s) |\n|---------------------|---------------------|-------------------|\n| chacha20-poly1305   | 5884.89             | 169.93            |\n| chacha20            | 4206.36             | 237.74            |\n| poly1305            | 1405.16             | 711.66            |\n\nThese results highlight the high efficiency of the algorithms, making them ideal for high-throughput applications.\n\n## Usage Examples\n\n### Real-World Use Case: Secure Data Encryption/Decryption\n\n**Scenario**: Encrypting and decrypting sensitive data using ChaCha20.\n\n```dart\nimport 'dart:typed_data';\nimport 'package:chacha/export.dart';\n\nUint8List encrypt({\n  required Uint8List plaintext,\n  required Uint8List key,\n  required Uint8List nonce,\n}) {\n  final ChaCha20 chacha20 = ChaCha20(key: key, nonce: nonce);\n  return chacha20.convert(plaintext);\n}\n\nUint8List decrypt({\n  required Uint8List ciphertext,\n  required Uint8List key,\n  required Uint8List nonce,\n}) {\n  final ChaCha20 chacha20 = ChaCha20(key: key, nonce: nonce);\n  return chacha20.convert(ciphertext);\n}\n```\n\n### Real-World Use Case: Secure Data Encryption/Decryption Stream\n\n**Scenario**: Encrypting and decrypting sensitive data using ChaCha20 streaming.\n\n```dart\nimport 'dart:typed_data';\nimport 'package:chacha/export.dart';\n\nStream\u003cList\u003cint\u003e\u003e encrypt({\n  required Stream\u003cUint8List\u003e plaintext,\n  required Uint8List key,\n  required Uint8List nonce,\n}) {\n  final ChaCha20 chacha20 = ChaCha20(key: key, nonce: nonce);\n  return plaintext.transform(chacha20);\n}\n\nStream\u003cList\u003cint\u003e\u003e decrypt({\n  required Stream\u003cUint8List\u003e ciphertext,\n  required Uint8List key,\n  required Uint8List nonce,\n}) {\n  final ChaCha20 chacha20 = ChaCha20(key: key, nonce: nonce);\n  return ciphertext.transform(chacha20);\n}\n```\n\n### Real-World Use Case: Secure File Encryption/Decryption Stream\n\n**Scenario**: Encrypting and decrypting sensitive files using ChaCha20 streaming.\n\n```dart\nimport 'dart:typed_data';\nimport 'package:chacha/export.dart';\n\nvoid process({\n  required File inputFile,\n  required File outputFile,\n  required Uint8List key,\n  required Uint8List nonce,\n}) {\n  final ChaCha20 chacha20 = ChaCha20(key: key, nonce: nonce);\n  inputFile.openRead().transform(chacha20).pipe(outputFile.openWrite());\n}\n```\n\n### Real-World Use Case: Data Authentication\n\n**Scenario**: Generating a MAC for a message using Poly1305.\n\n```dart\nimport 'dart:typed_data';\nimport 'package:chacha/poly1305.dart';\n\nUint8List generateMAC({\n  required Uint8List message,\n  required Uint8List key,\n}) {\n  final Poly1305 poly1305 = Poly1305(key: key)\n  return poly1305.convert(message);\n}\n```\n\n## Contribution\n\nContributions to improve the implementation, enhance security, and extend functionality are welcome. If you find any issues or have suggestions, please feel free to open an issue or submit a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosmakin%2Fchacha20","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarlosmakin%2Fchacha20","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosmakin%2Fchacha20/lists"}