-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 69bd4f5
Showing
18 changed files
with
1,925 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
*.js text eol=lf | ||
*.sh text eol=lf | ||
*.json text eol=lf | ||
*.ts text eol=lf | ||
*.html text eol=lf | ||
*.min.js binary | ||
vendor/* binary | ||
|
||
.github export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.npmignore export-ignore | ||
.npmrc export-ignore | ||
build export-ignore | ||
tests export-ignore | ||
playwright.config.ts export-ignore | ||
tsconfig.json export-ignore | ||
package-lock.json export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: brainfoolong | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: JS tests | ||
on: | ||
push: | ||
pull_request: | ||
jobs: | ||
tests: | ||
strategy: | ||
matrix: | ||
node-version: [ '12.x', '14.x', '16.x', '18.x' ,'20.x' ,'latest' ] | ||
timeout-minutes: 10 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Run tests on ${{ matrix.node-version }} | ||
run: node tests/test-all.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea | ||
.npmrc | ||
node_modules | ||
package-lock.json | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* | ||
!dist/* | ||
!src/* | ||
!CHANGELOG.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 BrainFooLong (Roland Eigelsreiter) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# JavaScript/TypeScript Implementation of Ascon | ||
|
||
[![Tests](https://github.com/brainfoolong/js-ascon/actions/workflows/tests.yml/badge.svg)](https://github.com/brainfoolong/js-ascon/actions/workflows/tests.yml) | ||
|
||
This is a JavaScript/TypeScript (JS compiled from TypeScript) implementation of Ascon v1.2, an authenticated cipher and hash function. | ||
It allows to encrypt and decrypt any kind of message. At kind be somewhat seen as the successor to AES encryption. | ||
Heavily inspired by the python implementation of Ascon by https://github.com/meichlseder/pyascon | ||
|
||
## About Ascon | ||
|
||
Ascon is a family of [authenticated encryption](https://en.wikipedia.org/wiki/Authenticated_encryption) (AEAD) | ||
and [hashing](https://en.wikipedia.org/wiki/Cryptographic_hash_function) algorithms designed to be lightweight and easy | ||
to implement, even with added countermeasures against side-channel attacks. | ||
It was designed by a team of cryptographers from Graz University of Technology, Infineon Technologies, and Radboud | ||
University: Christoph Dobraunig, Maria Eichlseder, Florian Mendel, and Martin Schläffer. | ||
|
||
Ascon has been selected as the standard for lightweight cryptography in | ||
the [NIST Lightweight Cryptography competition (2019–2023)](https://csrc.nist.gov/projects/lightweight-cryptography) and | ||
as the primary choice for lightweight authenticated encryption in the final portfolio of | ||
the [CAESAR competition (2014–2019)](https://competitions.cr.yp.to/caesar-submissions.html). | ||
|
||
Find more information, including the specification and more implementations here: | ||
|
||
https://ascon.iaik.tugraz.at/ | ||
|
||
## About me | ||
|
||
I have made library for AES PHP/JS encryption already in the past. Bit juggling is somewhat cool, in a really nerdy way. | ||
I like the Ascon implementation and it at the time of writing, a JS implementation was missing. So i made one. Would be | ||
cool if you leave a follow or spend some virtual coffee. | ||
|
||
## Usage | ||
|
||
For more demos see in folder `demo`. | ||
|
||
```js | ||
``` | ||
|
||
See `tests/performance.html` for some tests with various message data size. | ||
|
||
``` | ||
# no scientific tests, just executed on my local machine, results depend on your machine | ||
# a "cycle" is one encryption and one decryption | ||
### 10 cycles with 32 byte message data and 128 byte associated data ### | ||
Total Time: 0.080 seconds | ||
### 10 cycles with 128 byte message data and 512 byte associated data ### | ||
Total Time: 0.260 seconds | ||
### 10 cycles with 1024 byte message data and 2048 byte associated data ### | ||
Total Time: 1.370 seconds | ||
### 10 cycles with 4096 byte message data and 0 byte associated data ### | ||
Total Time: 2.869 seconds | ||
``` | ||
|
||
## Implemented Algorithms | ||
|
||
This is a simple reference implementation of Ascon v1.2 as submitted to the NIST LWC competition that includes | ||
|
||
* Authenticated encryption/decryption with the following 3 variants: | ||
|
||
- `Ascon-128` | ||
- `Ascon-128a` | ||
- `Ascon-80pq` | ||
|
||
* Hashing algorithms including 4 hash function variants with fixed 256-bit (`Hash`) or variable (`Xof`) output lengths: | ||
|
||
- `Ascon-Hash` | ||
- `Ascon-Hasha` | ||
- `Ascon-Xof` | ||
- `Ascon-Xofa` | ||
|
||
* Message authentication codes including 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`). | ||
|
||
- `Ascon-Mac` | ||
- `Ascon-Maca` | ||
- `Ascon-Prf` | ||
- `Ascon-Prfa` | ||
- `Ascon-PrfShort` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// create all required dist files | ||
const fs = require('fs') | ||
|
||
const packageJson = require('../package.json') | ||
const srcFile = __dirname + '/../dist/ascon.js' | ||
let contents = fs.readFileSync(srcFile).toString() | ||
contents = '// js-ascon v' + packageJson.version + ' @ ' + packageJson.homepage + '\n' + contents | ||
contents = contents.replace(/export default class JsAscon/, 'class JsAscon') | ||
contents += ` | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = JsAscon | ||
} | ||
if(typeof crypto === 'undefined' && typeof global !== 'undefined'){ | ||
global.crypto = require('crypto') | ||
} | ||
` | ||
fs.writeFileSync(srcFile, contents) |
Oops, something went wrong.