{"id":17761060,"url":"https://github.com/brainfoolong/js-ascon","last_synced_at":"2025-05-12T18:55:29.870Z","repository":{"id":208857046,"uuid":"722624118","full_name":"brainfoolong/js-ascon","owner":"brainfoolong","description":"JavaScript / TypeScript Implementation of Ascon, a family of authenticated encryption (AEAD) and hashing algorithms designed to be lightweight.","archived":false,"fork":false,"pushed_at":"2025-03-15T19:44:58.000Z","size":454,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-02T10:53:06.659Z","etag":null,"topics":["ascon","ascon-family","javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/brainfoolong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"brainfoolong","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2023-11-23T14:48:12.000Z","updated_at":"2025-03-25T11:41:02.000Z","dependencies_parsed_at":"2023-11-23T17:23:00.000Z","dependency_job_id":"581c3d9c-136c-425d-85e7-a0492cb48a4d","html_url":"https://github.com/brainfoolong/js-ascon","commit_stats":null,"previous_names":["brainfoolong/js-ascon"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fjs-ascon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fjs-ascon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fjs-ascon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainfoolong%2Fjs-ascon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainfoolong","download_url":"https://codeload.github.com/brainfoolong/js-ascon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253805063,"owners_count":21967050,"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":["ascon","ascon-family","javascript","typescript"],"created_at":"2024-10-26T19:18:59.337Z","updated_at":"2025-05-12T18:55:29.851Z","avatar_url":"https://github.com/brainfoolong.png","language":"TypeScript","funding_links":["https://github.com/sponsors/brainfoolong"],"categories":[],"sub_categories":[],"readme":"# JavaScript/TypeScript Implementation of Ascon\n\n[![Tests](https://github.com/brainfoolong/js-ascon/actions/workflows/tests.yml/badge.svg)](https://github.com/brainfoolong/js-ascon/actions/workflows/tests.yml)\n\nThis is a JavaScript/TypeScript (JS compiled from TypeScript) implementation of Ascon v1.3, an authenticated cipher and hash function.\nIt allows to encrypt and decrypt any kind of message. Includes the authenticated encryption and hash function variants as specified in [NIST SP 800-232 (initial public draft)](https://csrc.nist.gov/pubs/sp/800/232/ipd).\nHeavily inspired by the python implementation of Ascon by https://github.com/meichlseder/pyascon\n\n\u003e Notice: This library does contain the version 1.3 of Ascon. v1.2 was a draft version and there are already newer versions of ascon. See https://github.com/ascon/ascon-c . Version 1.2 is not compatible with 1.3\n\n## About Ascon\n\nAscon is a family of [authenticated encryption](https://en.wikipedia.org/wiki/Authenticated_encryption) (AEAD)\nand [hashing](https://en.wikipedia.org/wiki/Cryptographic_hash_function) algorithms designed to be lightweight and easy\nto implement, even with added countermeasures against side-channel attacks.\nIt was designed by a team of cryptographers from Graz University of Technology, Infineon Technologies, and Radboud\nUniversity: Christoph Dobraunig, Maria Eichlseder, Florian Mendel, and Martin Schläffer.\n\nAscon has been selected as the standard for lightweight cryptography in\nthe [NIST Lightweight Cryptography competition (2019–2023)](https://csrc.nist.gov/projects/lightweight-cryptography) and\nas the primary choice for lightweight authenticated encryption in the final portfolio of\nthe [CAESAR competition (2014–2019)](https://competitions.cr.yp.to/caesar-submissions.html).\n\nFind more information, including the specification and more implementations here:\n\nhttps://ascon.iaik.tugraz.at/\n\n## About me\n\nI have made library for AES PHP/JS encryption already in the past. Bit juggling is somewhat cool, in a really nerdy way.\nI like the Ascon implementation and it at the time of writing, a JS implementation was missing. So i made one. Would be\ncool if you leave a follow or spend some virtual coffee.\n\n## PHP Implementation\nChances are high that you probably need a PHP implementation too. I've made one here -\u003e https://github.com/brainfoolong/php-ascon\n\n## Installation\n\n    # for npm\n    npm install js-ascon\n    const JsAscon = require('js-ascon')\n    # in browser\n    \u003cscript src=\"ascon.js\"\u003e\u003c/script\u003e\n\n## Usage\n\nFor more demos see in folder `demo`.\n\n```js\n// test convenient methods\nlet key = 'mypassword'\nlet message = ['this can be any data type 😎 文', 123]\nlet associatedData = 'Some data 😋 文 This data is not contained in the encrypt output. You must pass the same data to encrypt and decrypt in order to be able to decrypt the message.'\nlet encrypted = JsAscon.encryptToHex(key, message, associatedData)\nlet decrypted = JsAscon.decryptFromHex(key, encrypted, associatedData)\nJsAscon.assertSame(JSON.stringify(message), JSON.stringify(decrypted), 'Encryption/Decryption to hex failed')\n\n// raw usage of basic methods\n// key must be 16 bytes or 20 bytes, depending on variant\nconst key = [0x90, 0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0xAA, 0x90, 0x90, 0x90, 0x90, 0xCC, 0xEF]\n// nonce must be 16 bytes and should always be random bytes, you must use same nonce for encrypt and decrypt the same message\nconst nonce = JsAscon.getRandomUintArray(16)\n// this is the text you want to encrypt\nconst plaintext = 'Hi, i am a secret message!'\n// associated data is not being encrypted, but is taken into account in the ciphertext\n// this means, you can only decrypt when you pass the exact same associated data to the decrypt function as well\n// so you can make sure that associated data and plaintext is not manipulated for given encrypted message\n// this is optional and can be an empty string\nconst associatedData = 'Some data to pass to encryption and decryption - This data is not contained in the ciphertext output.'\nconst ciphertextByteArray = JsAscon.encrypt(key, nonce, associatedData, plaintext)\nconst plaintextDecrypted = JsAscon.decrypt(key, nonce, associatedData, ciphertextByteArray)\n\nconsole.log(\"Hash\")\nconsole.log(JsAscon.hash(\"Testmessage\"))\n\nconsole.log(\"Mac\")\nconsole.log(JsAscon.mac(key, \"Testmessage\"))\n\n```\n\n## Development\nChange code in `src/ascon.ts`. Test changes with `npm run tests-bun` or `npm run tests-node`. Create dist files with `npm run dist`.\n\n## Algorithms\n\nThis is a simple reference implementation of Ascon as specified in NIST's draft standard, NIST SP 800-232, which includes\n\n  * Authenticated encryption `JsAscon.encrypt` and `JsAscon.decrypt`\n\n    - `Ascon-AEAD128`\n  \n  * Hashing algorithms `JsAscon.hash` including 3 hash function variants with slightly different interfaces:\n\n    - `Ascon-Hash256` with fixed 256-bit output\n    - `Ascon-XOF128` with variable output lengths (specified with `hashlength`)\n    - `Ascon-CXOF128` with variable output lengths (`hashlength`) and supporting a customization string as an additional input (to be implemented)\n\n  * Message Authentication Code `JsAscon.mac`\n\n    - `Ascon-Mac` (128-bit output, arbitrarily long input), \n    - `Ascon-Prf` (arbitrarily long input and output), \n    - `Ascon-PrfShort` (t-bit output for t\u003c=128, m-bit input for m\u003c=128)\n  \n\n## Older Algorithm Variants\n\nOlder versions implement Ascon v1.2 as submitted to the NIST LWC competition and published in the Journal of Cryptology, as well as additional functionality for message authentication. These versions can be found in at https://github.com/brainfoolong/js-ascon/tree/d6a74535555078767fcfe5bd47e7f6376fdad93a, including\n\n  * Authenticated encryption:\n\n    - `Ascon-128`\n    - `Ascon-128a`\n    - `Ascon-80pq`\n  \n  * Hashing algorithms:\n\n    - `Ascon-Hash`\n    - `Ascon-Hasha`\n    - `Ascon-Xof`\n    - `Ascon-Xofa`\n  \n  * Message authentication codes `ascon_mac(key, message, variant=\"Ascon-Mac\", taglength=16)` for 5 MAC variants (from https://eprint.iacr.org/2021/1574, not part of the LWC proposal) with fixed 128-bit (`Mac`) or variable (`Prf`) output lengths, including a variant for short messages of up to 128 bits (`PrfShort`).\n\n    - `Ascon-Mac`\n    - `Ascon-Maca`\n    - `Ascon-Prf`\n    - `Ascon-Prfa`\n    - `Ascon-PrfShort`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainfoolong%2Fjs-ascon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainfoolong%2Fjs-ascon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainfoolong%2Fjs-ascon/lists"}