{"id":16370175,"url":"https://github.com/mrdcvlsc/chacha20-poly1305","last_synced_at":"2025-03-21T01:31:25.292Z","repository":{"id":42019907,"uuid":"467161544","full_name":"mrdcvlsc/ChaCha20-Poly1305","owner":"mrdcvlsc","description":"A C++ implementation of ChaCha20 \u0026 Poly1305 stream cipher described in RFC - 8439.","archived":false,"fork":false,"pushed_at":"2024-06-09T11:54:13.000Z","size":347,"stargazers_count":15,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-18T06:01:21.046Z","etag":null,"topics":["aead","aead-authenticated-cryptography-mac","arm","authenticated-encryption","chacha20","chacha20-poly1305","cplusplus","cpp","cryptography","decryption","encryption","key","library","poly1305","rfc-8439","scratch-implementation","security","stream-cipher","uint512","x86-64"],"latest_commit_sha":null,"homepage":"","language":"C++","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/mrdcvlsc.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2022-03-07T15:57:13.000Z","updated_at":"2024-10-05T06:37:30.000Z","dependencies_parsed_at":"2024-05-28T17:59:38.473Z","dependency_job_id":"06c693c2-5610-4bb8-a468-c33de93fc405","html_url":"https://github.com/mrdcvlsc/ChaCha20-Poly1305","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdcvlsc%2FChaCha20-Poly1305","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdcvlsc%2FChaCha20-Poly1305/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdcvlsc%2FChaCha20-Poly1305/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdcvlsc%2FChaCha20-Poly1305/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrdcvlsc","download_url":"https://codeload.github.com/mrdcvlsc/ChaCha20-Poly1305/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221810763,"owners_count":16884188,"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":["aead","aead-authenticated-cryptography-mac","arm","authenticated-encryption","chacha20","chacha20-poly1305","cplusplus","cpp","cryptography","decryption","encryption","key","library","poly1305","rfc-8439","scratch-implementation","security","stream-cipher","uint512","x86-64"],"created_at":"2024-10-11T03:04:08.534Z","updated_at":"2024-10-28T08:59:52.624Z","avatar_url":"https://github.com/mrdcvlsc.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChaCha20 \u0026 Poly1305\n\n![build](https://github.com/mrdcvlsc/ChaCha20-Poly1305/actions/workflows/build.yml/badge.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\nA from scratch C++ implementation of ```ChaCha20 \u0026 Poly1305``` stream cipher described in [RFC - 8439](https://www.rfc-editor.org/info/rfc8439).\n\n**tests:**\n\n![gcc-gnu](https://github.com/mrdcvlsc/ChaCha20-Poly1305/actions/workflows/gcc-gnu.yml/badge.svg)\n![clang](https://github.com/mrdcvlsc/ChaCha20-Poly1305/actions/workflows/clang.yml/badge.svg)\n![mingw64](https://github.com/mrdcvlsc/ChaCha20-Poly1305/actions/workflows/mingw64.yml/badge.svg)\n![msvc](https://github.com/mrdcvlsc/ChaCha20-Poly1305/actions/workflows/msvc.yml/badge.svg)\n\nAll test from RFC-8439 is implemented here and is inside the ```tests``` folder.\n\n-----\n\n# Clone the repository and download the submodule\n\n```bash\ngit clone https://github.com/mrdcvlsc/ChaCha20-Poly1305.git\ncd ChaCha20-Poly1305\ngit submodule update --init --recursive\n```\n\n-----\n\n# Environment Requirements\n- std=c++20\n- x86_64 or aarch64 architecture\n- little endian system\n\nIf your system does not have these requirements, it might produce wrong results or might not even compile.\n\n-----\n\n# Main Functions\n\n**Note:** one **byte** is equivalent to one ```unsigned char```, If we have an array with a size of **5 bytes**, that is an array of type ```unsigned char``` with **5 elements**.\n\nThe sizes of the parameter arrays are mentioned in the documentation comments in the example code below:\n\n```c++\n/**Encryption.\n * \n * @param outputCipher resulting cipher text output, \n * The size of outputCipher in bytes is equivalent to textLen.\n * \n * @param outputTag resulting 128bit / 16 byte array,\n * GENERATED after ENCRYPTION.\n * \n * @param inputText plain text to be ENCRYPTED.\n * \n * @param textLen size of the inputText in bytes.\n * \n * @param AAD Arbitrary length additional authenticated data.\n * \n * @param AAD_len size of the AAD in bytes.\n * \n * @param key a 256-bit key or 32 byte unsigned char array.\n * \n * @param nonce number only/use once, a 12 byte array with random values\n*/\nChaCha20_Poly1305::aead_encrypt(\n    unsigned char       *outputCipher,\n    unsigned char       *outputTag,\n    const unsigned char *inputText,\n    size_t               textLen,\n    const unsigned char *AAD,\n    size_t               AAD_len,\n    const unsigned char *key,\n    const unsigned char *nonce\n);\n\n/**Decryption.\n * \n * @param outputText recovered plain text output, \n * The size of outputText in bytes is equivalent to cipherLen.\n * \n * @param outputTag resulting 128bit / 16 byte array,\n * GENERATED after DECRYPTION.\n * \n * @param inputCipher cipher text to be DECRYPTED.\n * \n * @param cipherLen size of the input inputCipher in bytes.\n * \n * @param AAD Arbitrary length additional authenticated data.\n * \n * @param AAD_len size of the AAD in bytes.\n * \n * @param key a 256-bit key or 32 byte unsigned char array.\n * \n * @param nonce number only/use once, a 12 byte array with random values\n*/\nChaCha20_Poly1305::aead_decrypt(\n    unsigned char       *outputText,\n    unsigned char       *outputTag,\n    const unsigned char *inputCipher,\n    size_t               cipherLen,\n    const unsigned char *AAD,\n    size_t               AAD_len,\n    const unsigned char *key,\n    const unsigned char *nonce\n);\n```\n\n**To know if the message is authentic:**\n\nThe **outputTag** of generated by encryption should match the **outputTag** generated by decryption.\n\n1. The sender will **send** the encrypted **cipher text** along with the **encrypted tag**.\n\n2. Then the receiver will decrypt the cipher text, the decryption function will generate the output **recovered plain text** and the output **decryption tag**.\n\n3. The receiver then compares the **sender's encryption tag** to the generated output **decryption tag**; if both tag matched / is-equal then the message was authentic / not altered.\n\n-----\n\n\n# Compilation\n\nThere are **TWO WAYS** to use the library, either using the **header only mode**, or building the **static library**.\n\n- ## **Using header only**\n\n    Directly include the **Header-Mode-Chaha20-Poly1305.hpp** in your source code, and you can directly compile it without building the static library.\n\n    ```c++\n    #include \"Header-Mode-Chaha20-Poly1305.hpp\"\n    ```\n\n    But you always need to enable the optimization flags for this method to work.\n\n    ```shell\n    g++ main.cpp main.out -O2\n    ```\n\n    ```shell\n    clang++ main.cpp main.out -O2\n    ```\n\n\u003cbr\u003e\n\n- ## **Static Build with GNU-GCC Linux makefiles**\n\n    Build \u0026 install static library\n    ```shell\n    make -f staticlib\n    sudo make -f staticlib install\n    ```\n\n    Run tests (optional)\n    ```\n    make -f staticlib build_test\n    ```\n\n    Include ```#include \u003cChaCha20-Poly1305.hpp\u003e``` in your program then compile with **-lchacha20**\n\n    ```\n    g++ main.cpp -o main.out -lchacha20\n    ```\n\n    To uninstall library\n    ```\n    sudo make -f staticlib uninstall\n    ```\n\n    Clean Up compiled objects\n    ```\n    make -f staticlib cleanup\n    ```\n\n\u003cbr\u003e\n\n- ## **Static Build with Clang Linux makefiles**\n\n    Build static library with clang\n    ```shell\n    make -f staticlib CC=clang++\n    sudo make -f staticlib install\n    ```\n\n    Run tests with clang (optional)\n    ```\n    make -f staticlib build_test CC=clang++\n    ```\n\n    Include ```#include \u003cChaCha20-Poly1305.hpp\u003e``` in your program then compile with **-lchacha20**\n\n    ```\n    clang++ main.cpp -o main.out -lchacha20\n    ```\n\n    To uninstall library\n    ```\n    sudo make -f staticlib uninstall\n    ```\n\n    Clean Up compiled objects\n    ```\n    make -f staticlib cleanup\n    ```\n\n\u003cbr\u003e\n\n- ## **Static Build with Mingw64 Windows makefiles**\n    \n    Build \u0026 install static library\n    ```shell\n    mingw32-make -f staticlib\n    mingw32-make -f staticlib install INSTALL_PREFIX=(path/to/mingw64)\n    ```\n\n    Run tests (optional)\n    ```\n    mingw32-make -f staticlib build_test\n    ```\n\n    Include ```#include \u003cChaCha20-Poly1305.hpp\u003e``` in your program then compile with **-lchacha20**\n\n    ```\n    g++ main.cpp -o main.out -lchacha20\n    ```\n\n    To uninstall library\n    ```\n    mingw32-make -f staticlib uninstall INSTALL_PREFIX=(path/to/mingw64)\n    ```\n\n    Clean Up compiled objects\n    ```\n    mingw32-make -f staticlib cleanup\n    ```\n\nYou can also modify the installation path in linux by setting up a new value for the ```INSTALL_PREFIX=``` when executing the make build commands similar to what is shown in the windows build.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdcvlsc%2Fchacha20-poly1305","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdcvlsc%2Fchacha20-poly1305","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdcvlsc%2Fchacha20-poly1305/lists"}