├── .github └── workflows │ └── build-and-test.yml ├── .gitignore ├── LICENSE ├── README.md ├── configs ├── tsconfig.json └── typedoc.base.json ├── eslint.config.mjs ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── aead │ ├── LICENSE │ ├── aead.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── aes-kw │ ├── LICENSE │ ├── aes-kw.test.ts │ ├── aes-kw.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── aes │ ├── LICENSE │ ├── aes.bench.ts │ ├── aes.test.ts │ ├── aes.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── base64 │ ├── LICENSE │ ├── base64.bench.ts │ ├── base64.test.ts │ ├── base64.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── benchmark │ ├── LICENSE │ ├── benchmark.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── binary │ ├── LICENSE │ ├── binary.test.ts │ ├── binary.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── blake2b │ ├── LICENSE │ ├── blake2b.bench.ts │ ├── blake2b.test.ts │ ├── blake2b.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── blake2s │ ├── LICENSE │ ├── blake2s.bench.ts │ ├── blake2s.test.ts │ ├── blake2s.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── blake2xs │ ├── LICENSE │ ├── blake2xs.bench.ts │ ├── blake2xs.test.ts │ ├── blake2xs.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── blockcipher │ ├── LICENSE │ ├── blockcipher.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── bytereader │ ├── LICENSE │ ├── bytereader.bench.ts │ ├── bytereader.test.ts │ ├── bytereader.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── bytes │ ├── LICENSE │ ├── bytes.bench.ts │ ├── bytes.test.ts │ ├── bytes.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── bytewriter │ ├── LICENSE │ ├── bytewriter.bench.ts │ ├── bytewriter.test.ts │ ├── bytewriter.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── cbor │ ├── LICENSE │ ├── cbor.bench.ts │ ├── cbor.test.ts │ ├── cbor.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── chacha-drbg │ ├── LICENSE │ ├── chacha-drbg.bench.ts │ ├── chacha-drbg.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── chacha │ ├── LICENSE │ ├── chacha.bench.ts │ ├── chacha.test.ts │ ├── chacha.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── chacha20poly1305 │ ├── LICENSE │ ├── chacha20poly1305.bench.ts │ ├── chacha20poly1305.test.ts │ ├── chacha20poly1305.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── cmac │ ├── LICENSE │ ├── cmac.bench.ts │ ├── cmac.test.ts │ ├── cmac.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── constant-time │ ├── LICENSE │ ├── constant-time.test.ts │ ├── constant-time.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── ctr │ ├── LICENSE │ ├── ctr.bench.ts │ ├── ctr.test.ts │ ├── ctr.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── ed25519 │ ├── LICENSE │ ├── ed25519.bench.ts │ ├── ed25519.test.ts │ ├── ed25519.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── float │ ├── LICENSE │ ├── float.test.ts │ ├── float.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── gcm │ ├── LICENSE │ ├── gcm.bench.ts │ ├── gcm.test.ts │ ├── gcm.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── gf256 │ ├── LICENSE │ ├── gf256.bench.ts │ ├── gf256.test.ts │ ├── gf256.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── halfsiphash │ ├── LICENSE │ ├── halfsiphash.bench.ts │ ├── halfsiphash.test.ts │ ├── halfsiphash.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── hash │ ├── LICENSE │ ├── hash.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── hex │ ├── LICENSE │ ├── hex.bench.ts │ ├── hex.test.ts │ ├── hex.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── hkdf │ ├── LICENSE │ ├── hkdf.bench.ts │ ├── hkdf.test.ts │ ├── hkdf.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── hmac-drbg │ ├── LICENSE │ ├── hmac-drbg.bench.ts │ ├── hmac-drbg.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── hmac │ ├── LICENSE │ ├── hmac.test.ts │ ├── hmac.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── int │ ├── LICENSE │ ├── int.test.ts │ ├── int.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── keyagreement │ ├── LICENSE │ ├── concat.ts │ ├── keyagreement.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── nacl │ ├── LICENSE │ ├── box.ts │ ├── nacl.ts │ ├── package.json │ ├── secretbox.bench.ts │ ├── secretbox.test.ts │ ├── secretbox.ts │ ├── tsconfig.json │ └── typedoc.json ├── newhope │ ├── LICENSE │ ├── custom.ts │ ├── newhope.bench.ts │ ├── newhope.test.ts │ ├── newhope.ts │ ├── package.json │ ├── tsconfig.json │ └── typedoc.json ├── pbkdf2 │ ├── LICENSE │ ├── package.json │ ├── pbkdf2.bench.ts │ ├── pbkdf2.test.ts │ ├── pbkdf2.ts │ ├── tsconfig.json │ └── typedoc.json ├── poly1305 │ ├── LICENSE │ ├── package.json │ ├── poly1305.bench.ts │ ├── poly1305.test.ts │ ├── poly1305.ts │ ├── tsconfig.json │ └── typedoc.json ├── random │ ├── LICENSE │ ├── package.json │ ├── random.test.ts │ ├── random.ts │ ├── source │ │ ├── index.ts │ │ ├── system.test.ts │ │ └── system.ts │ ├── tsconfig.json │ └── typedoc.json ├── salsa20 │ ├── LICENSE │ ├── package.json │ ├── salsa20.bench.ts │ ├── salsa20.test.ts │ ├── salsa20.ts │ ├── tsconfig.json │ └── typedoc.json ├── scrypt │ ├── LICENSE │ ├── package.json │ ├── scrypt.bench.ts │ ├── scrypt.test.ts │ ├── scrypt.ts │ ├── tsconfig.json │ └── typedoc.json ├── sha224 │ ├── LICENSE │ ├── package.json │ ├── sha224.test.ts │ ├── sha224.ts │ ├── tsconfig.json │ └── typedoc.json ├── sha256 │ ├── LICENSE │ ├── package.json │ ├── sha256.bench.ts │ ├── sha256.test.ts │ ├── sha256.ts │ ├── tsconfig.json │ └── typedoc.json ├── sha3 │ ├── LICENSE │ ├── package.json │ ├── sha3.bench.ts │ ├── sha3.test.ts │ ├── sha3.ts │ ├── tsconfig.json │ └── typedoc.json ├── sha384 │ ├── LICENSE │ ├── package.json │ ├── sha384.test.ts │ ├── sha384.ts │ ├── tsconfig.json │ └── typedoc.json ├── sha512 │ ├── LICENSE │ ├── package.json │ ├── sha512.bench.ts │ ├── sha512.test.ts │ ├── sha512.ts │ ├── tsconfig.json │ └── typedoc.json ├── sha512_256 │ ├── LICENSE │ ├── package.json │ ├── sha512_256.test.ts │ ├── sha512_256.ts │ ├── tsconfig.json │ └── typedoc.json ├── siv │ ├── LICENSE │ ├── package.json │ ├── siv.bench.ts │ ├── siv.test.ts │ ├── siv.ts │ ├── tsconfig.json │ └── typedoc.json ├── snappy │ ├── LICENSE │ ├── compress.test-data.ts │ ├── compress.ts │ ├── decompress.ts │ ├── package.json │ ├── snappy.bench.ts │ ├── snappy.test.ts │ ├── snappy.ts │ ├── tsconfig.json │ └── typedoc.json ├── tss │ ├── LICENSE │ ├── package.json │ ├── tsconfig.json │ ├── tss.bench.ts │ ├── tss.test.ts │ ├── tss.ts │ └── typedoc.json ├── utf8 │ ├── LICENSE │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── utf8.bench.ts │ ├── utf8.test.ts │ └── utf8.ts ├── uuid │ ├── LICENSE │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── uuid.test.ts │ └── uuid.ts ├── wipe │ ├── LICENSE │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── wipe.test.ts │ └── wipe.ts ├── x25519-session │ ├── LICENSE │ ├── keyagreement.ts │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── x25519-session.bench.ts │ ├── x25519-session.test.ts │ └── x25519-session.ts ├── x25519 │ ├── LICENSE │ ├── keyagreement.ts │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── x25519.bench.ts │ ├── x25519.test.ts │ └── x25519.ts ├── xchacha20 │ ├── LICENSE │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── xchacha20.bench.ts │ ├── xchacha20.test.ts │ └── xchacha20.ts ├── xchacha20poly1305 │ ├── LICENSE │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── xchacha20poly1305.bench.ts │ ├── xchacha20poly1305.test.ts │ └── xchacha20poly1305.ts └── xsalsa20 │ ├── LICENSE │ ├── package.json │ ├── tsconfig.json │ ├── typedoc.json │ ├── xsalsa20.bench.ts │ ├── xsalsa20.test.ts │ └── xsalsa20.ts └── typedoc.json /.github/workflows/build-and-test.yml: -------------------------------------------------------------------------------- 1 | name: Build and test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | node-version: [20.x] 13 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Use Node.js ${{ matrix.node-version }} 18 | uses: actions/setup-node@v3 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | cache: 'npm' 22 | - run: npm ci 23 | - run: npm run build 24 | - run: npm test 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | packages/*/lib 3 | lerna-debug.log 4 | npm-debug.log 5 | yarn-error.log 6 | *.DS_Store 7 | .vscode 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | StableLib 2 | ========= 3 | 4 | A stable library of useful TypeScript/JavaScript code. 5 | 6 | 7 | Principles 8 | ---------- 9 | 10 | * Correctness first, performance later. 11 | * Clear code is better than short. 12 | * Better usability means fewer bugs. 13 | * Typing is good, but not too much. 14 | 15 | 16 | Documentation 17 | ------------- 18 | 19 | See https://www.stablelib.com 20 | 21 | 22 | Usage 23 | ----- 24 | 25 | Install packages via npm from `@stablelib` namespace, for example: 26 | 27 | ``` 28 | npm install @stablelib/base64 29 | ``` 30 | 31 | [See all packages](https://www.npmjs.com/search?q=%40stablelib). 32 | 33 | 34 | Support 35 | ------- 36 | 37 | * Paid support for proprietary projects: write to Dmitry Chestnykh . 38 | * Free support for open source projects and bug reports for everyone: [issue tracker](https://github.com/stablelib/stablelib/issues). 39 | -------------------------------------------------------------------------------- /configs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "node16", 5 | "strict": true, 6 | "noUnusedParameters": true, 7 | "noImplicitReturns": true, 8 | "noUnusedLocals": true, 9 | "removeComments": false, 10 | "preserveConstEnums": true, 11 | "moduleResolution": "node16", 12 | "verbatimModuleSyntax": true, 13 | "newLine": "LF", 14 | "sourceMap": true, 15 | "declaration": true, 16 | "lib": [ 17 | "es2022", 18 | "dom", 19 | "scripthost" 20 | ] 21 | }, 22 | } 23 | -------------------------------------------------------------------------------- /configs/typedoc.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "excludeExternals": true, 3 | "excludePrivate": true, 4 | "excludeInternal": true, 5 | "readme": "none", 6 | "theme": "default" 7 | } 8 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | 6 | export default [ 7 | {files: ["**/*.{js,mjs,cjs,ts}"]}, 8 | {languageOptions: { globals: {...globals.browser, ...globals.node} }}, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | {rules: { 12 | "prefer-const": "off", 13 | "prefer-spread": "off", 14 | "no-constant-condition": "off", 15 | "@typescript-eslint/no-explicit-any": "off", 16 | "@typescript-eslint/consistent-type-imports": "error", 17 | }}, 18 | ]; 19 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "npmClient": "npm", 6 | "command": { 7 | "publish": { 8 | "ignoreChanges": [ 9 | "tsconfig.json" 10 | ] 11 | } 12 | }, 13 | "version": "independent" 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stablelib", 3 | "private": true, 4 | "version": "0.0.1", 5 | "description": "Code library for TypeScript/JavaScript", 6 | "main": "index.js", 7 | "scripts": { 8 | "build": "lerna bootstrap --no-ci && lerna run build", 9 | "test": "lerna run test", 10 | "bench": "lerna run bench", 11 | "lint": "eslint packages/**/*.ts", 12 | "lintfix": "eslint packages/**/*.ts --fix", 13 | "publish-all": "lerna publish", 14 | "docs": "typedoc" 15 | }, 16 | "author": "Dmitry Chestnykh", 17 | "license": "MIT", 18 | "browser": { 19 | "crypto": false, 20 | "buffer": false 21 | }, 22 | "devDependencies": { 23 | "@eslint/js": "^8.56.0", 24 | "@lerna/legacy-package-management": "^8.1.5", 25 | "@types/eslint__js": "^8.42.3", 26 | "@types/node": "^20.14.9", 27 | "eslint": "^8.56.0", 28 | "globals": "^15.6.0", 29 | "lerna": "^8.1.5", 30 | "string-width": "4.2.3", 31 | "strip-ansi": "6.0.0", 32 | "typedoc": "^0.26.3", 33 | "typescript": "^5.5.2", 34 | "typescript-eslint": "^7.14.1", 35 | "vitest": "^1.6.0" 36 | }, 37 | "overrides": { 38 | "string-width": "4.2.3", 39 | "strip-ansi": "6.0.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/aead/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/aead/aead.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package aead provides interface for authentication encryption with associated data. 6 | */ 7 | 8 | /** 9 | * AEAD is a common interface for authenticated encryption with associated Data. 10 | */ 11 | export interface AEAD { 12 | /** 13 | * Byte length of nonce that is used with this AEAD. 14 | */ 15 | nonceLength: number; 16 | 17 | /** 18 | * Byte length of authentication tag included in the sealed ciphertext. 19 | * Result of seal() will be longer than plaintext for this number of bytes. 20 | */ 21 | tagLength: number; 22 | 23 | /** 24 | * Encrypts and authenticates plaintext, authenticates associated data, 25 | * and returns ciphertext, which includes authentication tag. 26 | * 27 | * If dst is given (it must be the size of plaintext + the size of tag length) 28 | * the result will be put into it. Dst and plaintext must not overlap. 29 | */ 30 | seal(nonce: Uint8Array, plaintext: Uint8Array, associatedData?: Uint8Array, 31 | dst?: Uint8Array): Uint8Array; 32 | 33 | /** 34 | * Authenticates ciphertext (which includes authentication tag) and 35 | * associated data, decrypts ciphertext, and returns decrypted plaintext. 36 | * 37 | * If authentication fails, it returns null. 38 | * 39 | * If dst is given (it must be of ciphertext length minus tag length), 40 | * the result will be put into it. Dst and plaintext must not overlap. 41 | */ 42 | open(nonce: Uint8Array, ciphertext: Uint8Array, associatedData?: Uint8Array, 43 | dst?: Uint8Array): Uint8Array | null; 44 | 45 | /** 46 | * Wipes state from memory. 47 | * Doesn't wipe the underlying block cipher state. 48 | */ 49 | clean(): this; 50 | } 51 | -------------------------------------------------------------------------------- /packages/aead/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/aead", 3 | "version": "2.0.0", 4 | "description": "AEAD interface declaration (authenticated encryption with associated data)", 5 | "main": "./lib/aead.js", 6 | "type": "module", 7 | "typings": "./lib/aead.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/aead", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/aead/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/aead/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["aead.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/aes-kw/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/aes-kw", 3 | "version": "2.0.1", 4 | "description": "AES KW (Advanced Encryption Standard Key Wrapping)", 5 | "main": "./lib/aes-kw.js", 6 | "type": "module", 7 | "typings": "./lib/aes-kw.d.ts", 8 | "contributors": [ 9 | { 10 | "name": "Dmitry Chestnykh" 11 | }, 12 | { 13 | "name": "Tobias Looker" 14 | } 15 | ], 16 | "license": "MIT", 17 | "repository": { 18 | "url": "https://github.com/StableLib/stablelib" 19 | }, 20 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/aes-kw", 21 | "publishConfig": { 22 | "access": "public" 23 | }, 24 | "scripts": { 25 | "build": "tsc", 26 | "test": "vitest run" 27 | }, 28 | "dependencies": { 29 | "@stablelib/aes": "^2.0.1", 30 | "@stablelib/binary": "^2.0.1", 31 | "@stablelib/blockcipher": "^2.0.0", 32 | "@stablelib/constant-time": "^2.0.1", 33 | "@stablelib/wipe": "^2.0.1" 34 | }, 35 | "devDependencies": { 36 | "@stablelib/hex": "^2.0.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/aes-kw/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/aes-kw/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["aes-kw.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/aes/aes.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { AES } from "./aes.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const key = byteSeq(32); 8 | const cipher = new AES(key); 9 | const src = byteSeq(16); 10 | const dst = new Uint8Array(16); 11 | 12 | report("AES-256 init", benchmark(() => new AES(key))); 13 | report("AES-256 encrypt", benchmark(() => cipher.encryptBlock(src, dst), src.length)); 14 | report("AES-256 decrypt", benchmark(() => cipher.decryptBlock(src, dst), src.length)); 15 | -------------------------------------------------------------------------------- /packages/aes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/aes", 3 | "version": "2.0.1", 4 | "description": "AES block cipher (Advanced Encryption Standard)", 5 | "main": "./lib/aes.js", 6 | "type": "module", 7 | "typings": "./lib/aes.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/aes", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/aes.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/blockcipher": "^2.0.0", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/aes/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/aes/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["aes.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/base64/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/base64/base64.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { encode, decode } from "./base64.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let buf = byteSeq(1024); 8 | const encBuf = encode(buf); 9 | 10 | report("Base64 encode", benchmark(() => encode(buf), buf.length)); 11 | // Decode benchmark reports MiB/s for decoded MiB, not input. 12 | report("Base64 decode", benchmark(() => decode(encBuf), buf.length)); 13 | 14 | if (typeof Buffer !== "undefined") { 15 | // For comparison with Node.js buffer speed. 16 | const nodeBuf = Buffer.from(buf); 17 | const nodeEncBuf = nodeBuf.toString("base64"); 18 | 19 | report("Buffer - Base64 encode", benchmark(() => 20 | nodeBuf.toString("base64"), nodeBuf.length)); 21 | report("Buffer - Base64 decode", benchmark(() => 22 | Buffer.from(nodeEncBuf, "base64"), nodeBuf.length)); 23 | } 24 | -------------------------------------------------------------------------------- /packages/base64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/base64", 3 | "version": "2.0.1", 4 | "description": "Base64 encoding and decoding", 5 | "main": "./lib/base64.js", 6 | "type": "module", 7 | "typings": "./lib/base64.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/base64", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/base64.bench.js" 21 | }, 22 | "devDependencies": { 23 | "@stablelib/benchmark": "^2.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/base64/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/base64/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["base64.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/benchmark/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/benchmark/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/benchmark", 3 | "version": "2.0.0", 4 | "description": "StableLib benchmarking suite", 5 | "main": "./lib/benchmark.js", 6 | "type": "module", 7 | "typings": "./lib/benchmark.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/benchmark", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/benchmark/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/benchmark/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["benchmark.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/binary/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/binary/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/binary", 3 | "version": "2.0.1", 4 | "description": "Binary encoding and decoding", 5 | "main": "./lib/binary.js", 6 | "type": "module", 7 | "typings": "./lib/binary.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/binary", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | }, 21 | "dependencies": { 22 | "@stablelib/int": "^2.0.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/binary/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/binary/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["binary.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/blake2b/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2017 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/blake2b/blake2b.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { hash } from "./blake2b.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let buf1M = byteSeq(1024 << 10); 8 | let buf8K = byteSeq(8 << 10); 9 | let buf1K = byteSeq(1 << 10); 10 | let buf32 = byteSeq(32); 11 | 12 | report("BLAKE2b 1M", benchmark(() => hash(buf1M), buf1M.length)); 13 | report("BLAKE2b 8K", benchmark(() => hash(buf8K), buf8K.length)); 14 | report("BLAKE2b 1K", benchmark(() => hash(buf1K), buf1K.length)); 15 | report("BLAKE2b 32", benchmark(() => hash(buf32), buf32.length)); 16 | -------------------------------------------------------------------------------- /packages/blake2b/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/blake2b", 3 | "version": "2.0.1", 4 | "description": "BLAKE2b cryptographic hash function", 5 | "main": "./lib/blake2b.js", 6 | "type": "module", 7 | "typings": "./lib/blake2b.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/blake2b", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/blake2b.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/hash": "^2.0.0", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/blake2b/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/blake2b/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["blake2b.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/blake2s/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/blake2s/blake2s.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { hash } from "./blake2s.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let buf1M = byteSeq(1024 << 10); 8 | let buf8K = byteSeq(8 << 10); 9 | let buf1K = byteSeq(1 << 10); 10 | let buf32 = byteSeq(32); 11 | 12 | report("BLAKE2s 1M", benchmark(() => hash(buf1M), buf1M.length)); 13 | report("BLAKE2s 8K", benchmark(() => hash(buf8K), buf8K.length)); 14 | report("BLAKE2s 1K", benchmark(() => hash(buf1K), buf1K.length)); 15 | report("BLAKE2s 32", benchmark(() => hash(buf32), buf32.length)); 16 | -------------------------------------------------------------------------------- /packages/blake2s/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/blake2s", 3 | "version": "2.0.1", 4 | "description": "BLAKE2s cryptographic hash function", 5 | "main": "./lib/blake2s.js", 6 | "type": "module", 7 | "typings": "./lib/blake2s.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/blake2s", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/blake2s.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/hash": "^2.0.0", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/blake2s/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/blake2s/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["blake2s.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/blake2xs/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/blake2xs/blake2xs.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { xof } from "./blake2xs.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let key = byteSeq(32); 8 | let data = byteSeq(32, 1); 9 | 10 | report("BLAKE2Xs 8K out", benchmark(() => xof(8 << 10, data, key), 8 << 10)); 11 | report("BLAKE2Xs 64 out", benchmark(() => xof(64, data, key), 64)); 12 | -------------------------------------------------------------------------------- /packages/blake2xs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/blake2xs", 3 | "version": "2.0.1", 4 | "description": "BLAKE2xs cryptographic extended output function (XOF)", 5 | "main": "./lib/blake2xs.js", 6 | "type": "module", 7 | "typings": "./lib/blake2xs.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/blake2xs", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/blake2xs.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/blake2s": "^2.0.1", 24 | "@stablelib/hash": "^2.0.0", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/bytes": "^2.0.1", 30 | "@stablelib/hex": "^2.0.1" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/blake2xs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/blake2xs/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["blake2xs.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/blockcipher/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/blockcipher/blockcipher.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package blockcipher provides block cipher interface. 6 | */ 7 | 8 | /** 9 | * Block cipher interface. 10 | */ 11 | export interface BlockCipher { 12 | /** 13 | * Byte length of cipher block. 14 | */ 15 | blockSize: number; 16 | 17 | /** 18 | * Sets a new key for cipher. 19 | */ 20 | setKey(key: Uint8Array): this; 21 | 22 | /** 23 | * Encrypts one block of data in src and puts the result into dst. 24 | * 25 | * Src and dst may be equal, but otherwise must not overlap. 26 | */ 27 | encryptBlock(src: Uint8Array, dst: Uint8Array): this; 28 | 29 | /** 30 | * Decrypts one block of data in src and puts the result into dst. 31 | * 32 | * Src and dst may be equal, but otherwise must not overlap. 33 | */ 34 | decryptBlock(src: Uint8Array, dst: Uint8Array): this; 35 | 36 | /** 37 | * Wipes state from memory. 38 | */ 39 | clean(): this; 40 | } 41 | 42 | export interface BlockCipherContructor { 43 | new(key: Uint8Array, noDecryption?: boolean): BlockCipher; 44 | } 45 | -------------------------------------------------------------------------------- /packages/blockcipher/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/blockcipher", 3 | "version": "2.0.0", 4 | "description": "Block cipher interface declaration", 5 | "main": "./lib/blockcipher.js", 6 | "type": "module", 7 | "typings": "./lib/blockcipher.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/blockcipher", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/blockcipher/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/blockcipher/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["blockcipher.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/bytereader/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/bytereader/bytereader.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { ByteReader } from "./bytereader.js"; 5 | import { report, benchmark, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf = byteSeq(8 << 10); 8 | 9 | report("ByteReader read", benchmark(() => benchmarkRead(buf), buf.length)); 10 | report("ByteReader readByte", benchmark(() => benchmarkReadByte(buf), buf.length)); 11 | report("ByteReader readUint32", benchmark(() => benchmarkReadUint32(buf), buf.length)); 12 | report("ByteReader readFloat64", benchmark(() => benchmarkReadFloat64(buf), buf.length)); 13 | 14 | function benchmarkRead(b: Uint8Array) { 15 | const r = new ByteReader(b); 16 | const n = b.length / 32; 17 | for (let i = 0; i < b.length; i += n) { 18 | r.read(n); 19 | } 20 | } 21 | 22 | function benchmarkReadByte(b: Uint8Array) { 23 | const r = new ByteReader(b); 24 | for (let i = 0; i < b.length; i++) { 25 | r.readByte(); 26 | } 27 | } 28 | 29 | function benchmarkReadUint32(b: Uint8Array) { 30 | const r = new ByteReader(b); 31 | for (let i = 0; i < b.length; i += 4) { 32 | r.readUint32BE(); 33 | } 34 | } 35 | 36 | function benchmarkReadFloat64(b: Uint8Array) { 37 | const r = new ByteReader(b); 38 | for (let i = 0; i < b.length; i += 8) { 39 | r.readFloat64BE(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/bytereader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/bytereader", 3 | "version": "2.0.1", 4 | "description": "Byte reader", 5 | "main": "./lib/bytereader.js", 6 | "type": "module", 7 | "typings": "./lib/bytereader.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/bytereader", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/bytereader.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1" 24 | }, 25 | "devDependencies": { 26 | "@stablelib/benchmark": "^2.0.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/bytereader/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/bytereader/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["bytereader.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/bytes/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/bytes/bytes.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { concat } from "./bytes.js"; 5 | import { benchmark, report } from "@stablelib/benchmark"; 6 | 7 | const a0 = new Uint8Array([1, 2, 3]); 8 | const a1 = new Uint8Array([4]); 9 | const a2 = new Uint8Array(0); // empty 10 | const a3 = new Uint8Array([5, 6, 7, 8, 9, 10]); 11 | 12 | report("bytes.concat", benchmark(() => concat(a0, a1, a2, a3))); 13 | -------------------------------------------------------------------------------- /packages/bytes/bytes.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { concat } from "./bytes.js"; 6 | 7 | describe("concat", () => { 8 | it("should concatenate byte arrays", () => { 9 | const arrays = [ 10 | new Uint8Array([1, 2, 3]), 11 | new Uint8Array([4]), 12 | new Uint8Array(0), // empty 13 | new Uint8Array([5, 6, 7, 8, 9, 10]) 14 | ]; 15 | const good = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 16 | expect(concat.apply(null, arrays)).toEqual(good); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/bytes/bytes.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package bytes provides functions for dealing with byte arrays. 6 | */ 7 | 8 | /** 9 | * Concatenates byte arrays. 10 | */ 11 | export function concat(...arrays: Uint8Array[]): Uint8Array { 12 | // Calculate sum of lengths of all arrays. 13 | let totalLength = 0; 14 | for (let i = 0; i < arrays.length; i++) { 15 | totalLength += arrays[i].length; 16 | } 17 | 18 | // Allocate new array of calculated length. 19 | const result = new Uint8Array(totalLength); 20 | 21 | // Copy all arrays into result. 22 | let offset = 0; 23 | for (let i = 0; i < arrays.length; i++) { 24 | const arg = arrays[i]; 25 | result.set(arg, offset); 26 | offset += arg.length; 27 | } 28 | 29 | return result; 30 | } 31 | -------------------------------------------------------------------------------- /packages/bytes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/bytes", 3 | "version": "2.0.1", 4 | "description": "Byte utilities", 5 | "main": "./lib/bytes.js", 6 | "type": "module", 7 | "typings": "./lib/bytes.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/bytes", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/bytes.bench.js" 21 | }, 22 | "devDependencies": { 23 | "@stablelib/benchmark": "^2.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/bytes/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/bytes/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["bytes.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/bytewriter/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/bytewriter/bytewriter.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { ByteWriter } from "./bytewriter.js"; 5 | import { report, benchmark, byteSeq } from "@stablelib/benchmark"; 6 | 7 | report("ByteWriter write", benchmark(() => benchmarkWrite(8192), 8192)); 8 | report("ByteWriter writeByte", benchmark(() => benchmarkWriteByte(8192), 8192)); 9 | report("ByteWriter writeUint32", benchmark(() => benchmarkWriteUint32(8192), 8192)); 10 | report("ByteWriter writeFloat64", benchmark(() => benchmarkWriteFloat64(8192), 8192)); 11 | 12 | function benchmarkWrite(n: number) { 13 | const b = byteSeq(n / 32); 14 | const w = new ByteWriter(); 15 | for (let i = 0; i < n; i += 32) { 16 | w.write(b); 17 | } 18 | w.finish(); 19 | } 20 | 21 | function benchmarkWriteByte(n: number) { 22 | const w = new ByteWriter(); 23 | for (let i = 0; i < n; i++) { 24 | w.writeByte(0x7f); 25 | } 26 | w.finish(); 27 | } 28 | 29 | function benchmarkWriteUint32(n: number) { 30 | const w = new ByteWriter(); 31 | for (let i = 0; i < n; i += 4) { 32 | w.writeUint32BE(12345678); 33 | } 34 | w.finish(); 35 | } 36 | 37 | function benchmarkWriteFloat64(n: number) { 38 | const w = new ByteWriter(); 39 | for (let i = 0; i < n; i += 8) { 40 | w.writeUint32BE(12345.67890); 41 | } 42 | w.finish(); 43 | } 44 | -------------------------------------------------------------------------------- /packages/bytewriter/bytewriter.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { ByteWriter } from "./bytewriter.js"; 6 | 7 | describe("ByteWriter", () => { 8 | it("should write bytes", () => { 9 | const w = new ByteWriter(); 10 | w.write(new Uint8Array([1, 2, 3])); 11 | w.write(new Uint8Array([4, 5])); 12 | w.writeByte(6); 13 | w.write(new Uint8Array([7, 8, 9])); 14 | const result = w.finish(); 15 | const good = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]); 16 | expect(result).toEqual(good); 17 | }); 18 | 19 | it("should write many", () => { 20 | const w = new ByteWriter(); 21 | w.writeMany([ 22 | new Uint8Array([1, 2, 3, 4]), 23 | new Uint8Array([5, 6, 7]), 24 | new Uint8Array(0), 25 | new Uint8Array([8]), 26 | new Uint8Array([9, 0]) 27 | ]); 28 | w.writeByte(255); 29 | const result = w.finish(); 30 | const good = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 255]); 31 | expect(result).toEqual(good); 32 | }); 33 | 34 | it("should write uint32", () => { 35 | const w = new ByteWriter(); 36 | w.writeByte(1); 37 | w.writeUint32BE(4294901660); 38 | w.writeByte(233); 39 | const result = w.finish(); 40 | const good = new Uint8Array([1, 255, 254, 255, 156, 233]); 41 | expect(result).toEqual(good); 42 | }); 43 | 44 | // TODO(dchest): test for writeXXX. 45 | }); 46 | -------------------------------------------------------------------------------- /packages/bytewriter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/bytewriter", 3 | "version": "2.0.1", 4 | "description": "Byte writer", 5 | "main": "./lib/bytewriter.js", 6 | "type": "module", 7 | "typings": "./lib/bytewriter.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/bytewriter", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/bytewriter.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/int": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/bytewriter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/bytewriter/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["bytewriter.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/cbor/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/cbor/cbor.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { encode, decode, Tagged } from "./cbor.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf = byteSeq(128); 8 | 9 | const value = { 10 | someBytes: buf, 11 | someString: "this is a string needed to benchmark CBOR encoder and decoder", 12 | someNumbersInArray: [ 13 | 0.1234, 14 | 1.1, 15 | 3.4028234663852886e+38, 16 | 65536, 17 | 232992399333333, 18 | Infinity 19 | ], 20 | someBoolean: true, 21 | someUndefined: undefined, 22 | someObject: { 23 | someNullsAndTagged: [null, null, null, new Tagged(32, "something")], 24 | anotherString: "hey", 25 | anotherBytes: new Uint8Array([1, 2, 3]), 26 | date: new Date(0), 27 | regexp: /^a[bc]+/gi 28 | } 29 | }; 30 | 31 | const encodedValue = encode(value); 32 | const bigBuf = byteSeq(1024); 33 | const encodedBigBuf = encode(bigBuf); 34 | 35 | // Benchmark report MiB/s for encoded MiB. 36 | report("CBOR encode", benchmark(() => encode(value), encodedValue.length)); 37 | report("CBOR decode", benchmark(() => decode(encodedValue), encodedValue.length)); 38 | report("CBOR encode bytes", benchmark(() => encode(bigBuf), bigBuf.length)); 39 | report("CBOR decode bytes", benchmark(() => decode(encodedBigBuf), encodedBigBuf.length)); 40 | 41 | // JSON for comparison 42 | 43 | const jsonEncodedValue = JSON.stringify(value); 44 | 45 | report("JSON encode", benchmark(() => JSON.stringify(value), encodedValue.length)); 46 | report("JSON decode", benchmark(() => JSON.parse(jsonEncodedValue), encodedValue.length)); 47 | -------------------------------------------------------------------------------- /packages/cbor/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/cbor", 3 | "version": "2.0.1", 4 | "description": "CBOR encoder and decoder", 5 | "main": "./lib/cbor.js", 6 | "type": "module", 7 | "typings": "./lib/cbor.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/cbor", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/cbor.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/bytereader": "^2.0.1", 24 | "@stablelib/bytewriter": "^2.0.1", 25 | "@stablelib/float": "^2.0.1", 26 | "@stablelib/int": "^2.0.1", 27 | "@stablelib/utf8": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "@stablelib/benchmark": "^2.0.0", 31 | "@stablelib/bytes": "^2.0.1", 32 | "@stablelib/hex": "^2.0.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/cbor/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/cbor/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["cbor.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/chacha-drbg/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/chacha-drbg/chacha-drbg.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { ChaChaDRBG } from "./chacha-drbg.js"; 5 | import type { RandomSource } from "@stablelib/random/source/index.js"; 6 | import { benchmark, report } from "@stablelib/benchmark"; 7 | 8 | class XKCDSource implements RandomSource { 9 | isAvailable = true; 10 | 11 | randomBytes(length: number): Uint8Array { 12 | const out = new Uint8Array(length); 13 | 14 | for (let i = 0; i < length; i++) { 15 | out[i] = 4; // chosen by fair dice roll. 16 | // guaranteed to be random 17 | } 18 | return out; 19 | } 20 | } 21 | 22 | const drbg = new ChaChaDRBG(new XKCDSource()); 23 | 24 | report("ChaChaDRBG", benchmark(() => drbg.randomBytes(1024), 1024)); 25 | -------------------------------------------------------------------------------- /packages/chacha-drbg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/chacha-drbg", 3 | "version": "2.0.1", 4 | "description": "ChaCha20-based DRBG (digital random byte generator)", 5 | "main": "./lib/chacha-drbg.js", 6 | "type": "module", 7 | "typings": "./lib/chacha-drbg.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/chacha-drbg", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "echo 'TODO: chacha-drbg test'", 20 | "bench": "node ./lib/chacha-drbg.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/chacha": "^2.0.1", 24 | "@stablelib/random": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/chacha-drbg/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/chacha-drbg/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["chacha-drbg.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/chacha/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/chacha/chacha.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { streamXOR } from "./chacha.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf16K = byteSeq(16 << 10); 8 | const buf8192 = byteSeq(8192); 9 | const buf1111 = byteSeq(1111); 10 | const buf64 = byteSeq(64); 11 | 12 | 13 | const key = byteSeq(32); 14 | const nonce = byteSeq(8); 15 | 16 | report("ChaCha20 xor 16K", benchmark(() => streamXOR(key, nonce, buf16K, buf16K), buf16K.length)); 17 | report("ChaCha20 xor 8K", benchmark(() => streamXOR(key, nonce, buf8192, buf8192), buf8192.length)); 18 | report("ChaCha20 xor 1111", benchmark(() => streamXOR(key, nonce, buf1111, buf1111), buf1111.length)); 19 | report("ChaCha20 xor 64", benchmark(() => streamXOR(key, nonce, buf64, buf64), buf64.length)); 20 | -------------------------------------------------------------------------------- /packages/chacha/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/chacha", 3 | "version": "2.0.1", 4 | "description": "ChaCha stream cipher", 5 | "main": "./lib/chacha.js", 6 | "type": "module", 7 | "typings": "./lib/chacha.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/chacha", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/chacha.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/wipe": "^2.0.1" 25 | }, 26 | "devDependencies": { 27 | "@stablelib/benchmark": "^2.0.0", 28 | "@stablelib/hex": "^2.0.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/chacha/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/chacha/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["chacha.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/chacha20poly1305/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/chacha20poly1305/chacha20poly1305.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { ChaCha20Poly1305 } from "./chacha20poly1305.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf8192 = byteSeq(8192); 8 | const buf1111 = byteSeq(1111); 9 | const buf0 = new Uint8Array(0); 10 | 11 | const key = byteSeq(32); 12 | const nonce = byteSeq(12); 13 | 14 | const aead = new ChaCha20Poly1305(key); 15 | 16 | report("ChaCha20Poly1305 seal 8K", 17 | benchmark(() => aead.seal(nonce, buf8192), buf8192.length)); 18 | report("ChaCha20Poly1305 seal 1111", 19 | benchmark(() => aead.seal(nonce, buf1111), buf1111.length)); 20 | report("ChaCha20Poly1305 seal 8K + AD", 21 | benchmark(() => aead.seal(nonce, buf8192, buf8192), buf8192.length * 2)); 22 | report("ChaCha20Poly1305 seal 1111 + AD", 23 | benchmark(() => aead.seal(nonce, buf1111, buf1111), buf1111.length * 2)); 24 | report("ChaCha20Poly1305 seal 0 + AD 8K", 25 | benchmark(() => aead.seal(nonce, buf0, buf8192), buf8192.length)); 26 | 27 | const sealed8192 = aead.seal(nonce, buf8192); 28 | const sealed1111 = aead.seal(nonce, buf1111); 29 | const sealed8192ad = aead.seal(nonce, buf8192, buf8192); 30 | const sealed1111ad = aead.seal(nonce, buf1111, buf1111); 31 | 32 | report("ChaCha20Poly1305 open 8K", 33 | benchmark(() => aead.open(nonce, sealed8192), buf8192.length)); 34 | report("ChaCha20Poly1305 open 1111", 35 | benchmark(() => aead.open(nonce, sealed1111), buf1111.length)); 36 | report("ChaCha20Poly1305 open 8K + AD", 37 | benchmark(() => aead.open(nonce, sealed8192ad, buf8192), buf8192.length * 2)); 38 | report("ChaCha20Poly1305 open 1111 + AD", 39 | benchmark(() => aead.seal(nonce, sealed1111ad, buf1111), buf1111.length * 2)); 40 | 41 | sealed8192[0] ^= sealed8192[0]; 42 | 43 | report("ChaCha20Poly1305 open (bad)", 44 | benchmark(() => aead.open(nonce, sealed8192), buf8192.length)); 45 | -------------------------------------------------------------------------------- /packages/chacha20poly1305/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/chacha20poly1305", 3 | "version": "2.0.1", 4 | "description": "ChaCha20-Poly1305 AEAD (RFC 7539)", 5 | "main": "./lib/chacha20poly1305.js", 6 | "type": "module", 7 | "typings": "./lib/chacha20poly1305.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/chacha20poly1305", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/chacha20poly1305.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/aead": "^2.0.0", 24 | "@stablelib/binary": "^2.0.1", 25 | "@stablelib/chacha": "^2.0.1", 26 | "@stablelib/constant-time": "^2.0.1", 27 | "@stablelib/poly1305": "^2.0.1", 28 | "@stablelib/wipe": "^2.0.1" 29 | }, 30 | "devDependencies": { 31 | "@stablelib/benchmark": "^2.0.0", 32 | "@stablelib/hex": "^2.0.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/chacha20poly1305/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/chacha20poly1305/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["chacha20poly1305.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/cmac/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/cmac/cmac.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { CMAC } from "./cmac.js"; 5 | import { AES } from "@stablelib/aes"; 6 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 7 | 8 | const buf8192 = byteSeq(8192); 9 | const buf1024 = byteSeq(1024); 10 | const buf32 = byteSeq(32); 11 | const aes = new AES(byteSeq(32)); 12 | 13 | report("CMAC-AES-256 8K", benchmark(() => (new CMAC(aes)).update(buf8192).digest(), buf8192.length)); 14 | report("CMAC-AES-256 1K", benchmark(() => (new CMAC(aes)).update(buf1024).digest(), buf1024.length)); 15 | report("CMAC-AES-256 32", benchmark(() => (new CMAC(aes)).update(buf32).digest(), buf32.length)); 16 | -------------------------------------------------------------------------------- /packages/cmac/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/cmac", 3 | "version": "2.0.1", 4 | "description": "CMAC message authentication code", 5 | "main": "./lib/cmac.js", 6 | "type": "module", 7 | "typings": "./lib/cmac.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/cmac", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/cmac.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/blockcipher": "^2.0.0", 24 | "@stablelib/constant-time": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/aes": "^2.0.1", 29 | "@stablelib/benchmark": "^2.0.0", 30 | "@stablelib/hex": "^2.0.1" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/cmac/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/cmac/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["cmac.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/constant-time/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/constant-time", 3 | "version": "2.0.1", 4 | "description": "Algorithmically constant-time utility functions", 5 | "main": "./lib/constant-time.js", 6 | "type": "module", 7 | "typings": "./lib/constant-time.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/constant-time", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/constant-time/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/constant-time/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["constant-time.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/ctr/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/ctr/ctr.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { AES } from "@stablelib/aes"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | import { CTR } from "./ctr.js"; 7 | 8 | const buf8192 = byteSeq(8192); 9 | const buf1111 = byteSeq(1111); 10 | 11 | const key = byteSeq(32); 12 | const iv = new Uint8Array(16); 13 | 14 | const cipher = new AES(key); 15 | const ctr = new CTR(cipher, iv); 16 | 17 | report("AES-CTR 8K", benchmark(() => ctr.streamXOR(buf8192, buf8192), buf8192.length)); 18 | report("AES-CTR 1111", benchmark(() => ctr.streamXOR(buf1111, buf1111), buf1111.length)); 19 | -------------------------------------------------------------------------------- /packages/ctr/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/ctr", 3 | "version": "2.0.1", 4 | "description": "Counter block cipher mode (CTR)", 5 | "main": "./lib/ctr.js", 6 | "type": "module", 7 | "typings": "./lib/ctr.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/ctr", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/ctr.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/blockcipher": "^2.0.0", 24 | "@stablelib/wipe": "^2.0.1" 25 | }, 26 | "devDependencies": { 27 | "@stablelib/aes": "^2.0.1", 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/ctr/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/ctr/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["ctr.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/ed25519/ed25519.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { sign, verify, generateKeyPairFromSeed, generateKeyPair } from "./ed25519.js"; 5 | import { benchmark, report } from "@stablelib/benchmark"; 6 | 7 | const k = generateKeyPair(); 8 | 9 | const buf = new Uint8Array(256); 10 | const seed = k.secretKey.subarray(0, 32); 11 | const sig = sign(k.secretKey, buf); 12 | const badsig = new Uint8Array(sig); badsig[0] = 1; 13 | 14 | report("ed25519.generateKeyPairFromSeed", benchmark(() => generateKeyPairFromSeed(seed))); 15 | report("ed25519.sign", benchmark(() => sign(k.secretKey, buf))); 16 | report("ed25519.verify", benchmark(() => verify(k.publicKey, buf, sig))); 17 | report("ed25519.verify (bad)", benchmark(() => verify(k.publicKey, buf, badsig))); 18 | -------------------------------------------------------------------------------- /packages/ed25519/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/ed25519", 3 | "version": "2.0.2", 4 | "description": "Ed25519 public-key signature (EdDSA with Curve25519)", 5 | "main": "./lib/ed25519.js", 6 | "type": "module", 7 | "typings": "./lib/ed25519.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/ed25519", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/ed25519.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/random": "^2.0.1", 24 | "@stablelib/sha512": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/base64": "^2.0.1", 29 | "@stablelib/benchmark": "^2.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/ed25519/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/ed25519/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["ed25519.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/float/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/float/float.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { isNegativeZero, fround } from "./float.js"; 6 | 7 | describe("isNegativeZero", () => { 8 | it("should return true for -0", () => { 9 | expect(isNegativeZero(-0)).toBe(true); 10 | }); 11 | it("should return false for +0", () => { 12 | expect(isNegativeZero(0)).toBe(false); 13 | }); 14 | it("should return false for 1", () => { 15 | expect(isNegativeZero(1)).toBe(false); 16 | }); 17 | it("should return false for -1", () => { 18 | expect(isNegativeZero(-1)).toBe(false); 19 | }); 20 | it("should return false for -Infinity", () => { 21 | expect(isNegativeZero(-Infinity)).toBe(false); 22 | }); 23 | it("should return false for +Infinity", () => { 24 | expect(isNegativeZero(+Infinity)).toBe(false); 25 | }); 26 | it("should return false for NaN", () => { 27 | expect(isNegativeZero(NaN)).toBe(false); 28 | }); 29 | }); 30 | 31 | describe("fround", () => { 32 | it("should return correct values for test vectors", () => { 33 | const vectors = [ 34 | [0, 0], 35 | [1, 1], 36 | [1.337, 1.3370000123977661], 37 | [1.5, 1.5], 38 | [-1, -1], 39 | [-1.337, -1.3370000123977661], 40 | [Infinity, Infinity], 41 | [-Infinity, -Infinity], 42 | [-1.337, -1.3370000123977661] 43 | ]; 44 | vectors.forEach(([arg, result]) => { 45 | expect(fround(arg)).toBe(result); 46 | }); 47 | expect(isNaN(fround(NaN))).toBe(true); 48 | expect(isNegativeZero(fround(-0))).toBe(true); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /packages/float/float.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package float provides helper functions for floating-point numbers. 6 | */ 7 | 8 | /** 9 | * Returns true if the argument is -0, false otherwise. 10 | */ 11 | export const isNegativeZero = (x: number) => Object.is(x, -0) 12 | 13 | /** 14 | * Returns new number rounded to float32. 15 | */ 16 | export const fround = Math.fround; 17 | 18 | /** 19 | * Returns base 2 logarithm. 20 | * 21 | * Note that result approximation is implementation-dependent. 22 | * If result is to be used in bit masks, use Math.round() on it. 23 | */ 24 | export const log2 = Math.log2; 25 | 26 | -------------------------------------------------------------------------------- /packages/float/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/float", 3 | "version": "2.0.1", 4 | "description": "Floating-point number utilities", 5 | "main": "./lib/float.js", 6 | "type": "module", 7 | "typings": "./lib/float.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/float", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/float/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/float/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["float.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/gcm/gcm.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { AES } from "@stablelib/aes"; 5 | import { GCM } from "./gcm.js"; 6 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 7 | 8 | const buf8192 = byteSeq(8192); 9 | const buf1111 = byteSeq(1111); 10 | const buf0 = new Uint8Array(0); 11 | 12 | const key = byteSeq(32); 13 | const nonce = byteSeq(12); 14 | 15 | const cipher = new AES(key); 16 | const gcm = new GCM(cipher); 17 | 18 | report("AES-GCM seal 8K", benchmark(() => gcm.seal(nonce, buf8192), buf8192.length)); 19 | report("AES-GCM seal 1111", benchmark(() => gcm.seal(nonce, buf1111), buf1111.length)); 20 | report("AES-GCM seal 8K + AD", benchmark(() => gcm.seal(nonce, buf8192, buf8192), buf8192.length * 2)); 21 | report("AES-GCM seal 1111 + AD", benchmark(() => gcm.seal(nonce, buf1111, buf1111), buf1111.length * 2)); 22 | report("AES-GCM seal 0 + AD 8K", benchmark(() => gcm.seal(nonce, buf0, buf8192), buf8192.length)); 23 | 24 | 25 | const sealed8192 = gcm.seal(nonce, buf8192); 26 | const sealed1111 = gcm.seal(nonce, buf1111); 27 | const sealed8192ad = gcm.seal(nonce, buf8192, buf8192); 28 | const sealed1111ad = gcm.seal(nonce, buf1111, buf1111); 29 | 30 | report("AES-GCM open 8K", benchmark(() => gcm.open(nonce, sealed8192), buf8192.length)); 31 | report("AES-GCM open 1111", benchmark(() => gcm.open(nonce, sealed1111), buf1111.length)); 32 | report("AES-GCM open 8K + AD", benchmark(() => gcm.open(nonce, sealed8192ad, buf8192), buf8192.length * 2)); 33 | report("AES-GCM open 1111 + AD", benchmark(() => gcm.seal(nonce, sealed1111ad, buf1111), buf1111.length * 2)); 34 | 35 | sealed8192[0] ^= sealed8192[0]; 36 | 37 | report("AES-GCM open (bad)", benchmark(() => gcm.open(nonce, sealed8192), buf8192.length)); 38 | -------------------------------------------------------------------------------- /packages/gcm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/gcm", 3 | "version": "2.0.1", 4 | "description": "GCM authenticated encryption mode with associated data (AEAD)", 5 | "main": "./lib/gcm.js", 6 | "type": "module", 7 | "typings": "./lib/gcm.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/gcm", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/gcm.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/aead": "^2.0.0", 24 | "@stablelib/binary": "^2.0.1", 25 | "@stablelib/blockcipher": "^2.0.0", 26 | "@stablelib/constant-time": "^2.0.1", 27 | "@stablelib/ctr": "^2.0.1", 28 | "@stablelib/wipe": "^2.0.1" 29 | }, 30 | "devDependencies": { 31 | "@stablelib/aes": "^2.0.1", 32 | "@stablelib/benchmark": "^2.0.0", 33 | "@stablelib/hex": "^2.0.1" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/gcm/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/gcm/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["gcm.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/gf256/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/gf256/gf256.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { benchmark, report } from "@stablelib/benchmark"; 5 | import { mul, div } from "./gf256.js"; 6 | 7 | report("gf256.mul", benchmark(() => mul(100, 18))); 8 | report("gf256.div", benchmark(() => div(100, 18))); 9 | -------------------------------------------------------------------------------- /packages/gf256/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/gf256", 3 | "version": "2.0.1", 4 | "description": "Arithmetic in GF(256)", 5 | "main": "./lib/gf256.js", 6 | "type": "module", 7 | "typings": "./lib/gf256.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/gf256", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/gf256.bench.js" 21 | }, 22 | "devDependencies": { 23 | "@stablelib/benchmark": "^2.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/gf256/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/gf256/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["gf256.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/halfsiphash/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/halfsiphash/halfsiphash.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { halfSipHash } from "./halfsiphash.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf1M = byteSeq(1024 << 10); 8 | const buf8K = byteSeq(8 << 10); 9 | const buf1K = byteSeq(1 << 10); 10 | const buf32 = byteSeq(32); 11 | const buf16 = byteSeq(16); 12 | const buf8 = byteSeq(8); 13 | const buf4 = byteSeq(4); 14 | const buf3 = byteSeq(3); 15 | 16 | const key = byteSeq(8); 17 | 18 | report("halfSipHash 1M", benchmark(() => halfSipHash(key, buf1M), buf1M.length)); 19 | report("halfSipHash 8K", benchmark(() => halfSipHash(key, buf8K), buf8K.length)); 20 | report("halfSipHash 1K", benchmark(() => halfSipHash(key, buf1K), buf1K.length)); 21 | report("halfSipHash 32", benchmark(() => halfSipHash(key, buf32), buf32.length)); 22 | report("halfSipHash 16", benchmark(() => halfSipHash(key, buf16), buf16.length)); 23 | report("halfSipHash 8", benchmark(() => halfSipHash(key, buf8), buf8.length)); 24 | report("halfSipHash 4", benchmark(() => halfSipHash(key, buf4), buf4.length)); 25 | report("halfSipHash 3", benchmark(() => halfSipHash(key, buf3), buf3.length)); 26 | -------------------------------------------------------------------------------- /packages/halfsiphash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/halfsiphash", 3 | "version": "2.0.1", 4 | "description": "Half-SipHash 32-bit cryptographic pseudorandom function", 5 | "main": "./lib/halfsiphash.js", 6 | "type": "module", 7 | "typings": "./lib/halfsiphash.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/halfsiphash", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/halfsiphash.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/int": "^2.0.1" 25 | }, 26 | "devDependencies": { 27 | "@stablelib/benchmark": "^2.0.0", 28 | "@stablelib/hex": "^2.0.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/halfsiphash/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/halfsiphash/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["halfsiphash.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/hash/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/hash/hash.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package hash provides interface for hash functions. 6 | */ 7 | 8 | /** 9 | * Hash interface describes properties of 10 | * cryptographic hash functions. 11 | */ 12 | export interface Hash { 13 | readonly digestLength: number; 14 | readonly blockSize: number; 15 | update(data: Uint8Array): this; 16 | reset(): this; 17 | finish(out: Uint8Array): this; 18 | digest(): Uint8Array; 19 | clean(): void; 20 | } 21 | 22 | export interface SerializableHash extends Hash { 23 | saveState(): any; 24 | restoreState(savedState: any): this; 25 | cleanSavedState(savedState: any): void; 26 | } 27 | 28 | export function isSerializableHash(h: Hash): h is SerializableHash { 29 | return ( 30 | typeof (h as SerializableHash).saveState !== "undefined" && 31 | typeof (h as SerializableHash).restoreState !== "undefined" && 32 | typeof (h as SerializableHash).cleanSavedState !== "undefined" 33 | ); 34 | } 35 | 36 | // TODO(dchest): figure out the standardized interface for XOF such as 37 | // SHAKE and BLAKE2X. 38 | -------------------------------------------------------------------------------- /packages/hash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/hash", 3 | "version": "2.0.0", 4 | "description": "Cryptographic hash function interface declarations", 5 | "main": "./lib/hash.js", 6 | "type": "module", 7 | "typings": "./lib/hash.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/hash", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/hash/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/hash/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["hash.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/hex/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/hex/hex.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { encode, decode } from "./hex.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let buf = byteSeq(1024); 8 | const encBuf = encode(buf); 9 | 10 | report("Hex encode", benchmark(() => encode(buf), buf.length)); 11 | // Decode benchmark reports MiB/s for decoded MiB, not input. 12 | report("Hex decode", benchmark(() => decode(encBuf), buf.length)); 13 | -------------------------------------------------------------------------------- /packages/hex/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/hex", 3 | "version": "2.0.1", 4 | "description": "Hex (Base16) encoding and decoding", 5 | "main": "./lib/hex.js", 6 | "type": "module", 7 | "typings": "./lib/hex.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/hex", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/hex.bench.js" 21 | }, 22 | "devDependencies": { 23 | "@stablelib/benchmark": "^2.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/hex/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/hex/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["hex.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/hkdf/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/hkdf/hkdf.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { HKDF } from "./hkdf.js"; 5 | import { SHA256 } from "@stablelib/sha256"; 6 | import { SHA512 } from "@stablelib/sha512"; 7 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 8 | 9 | let key = byteSeq(32); 10 | let salt = byteSeq(32); 11 | let info = byteSeq(5); 12 | 13 | report("hkdf/sha256 64", benchmark(() => new HKDF(SHA256, key, salt, info).expand(64))); 14 | report("hkdf/sha256 1K", benchmark(() => new HKDF(SHA256, key, salt, info).expand(1024))); 15 | report("hkdf/sha512 64", benchmark(() => new HKDF(SHA512, key, salt, info).expand(64))); 16 | report("hkdf/sha512 1K", benchmark(() => new HKDF(SHA512, key, salt, info).expand(1024))); 17 | -------------------------------------------------------------------------------- /packages/hkdf/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/hkdf", 3 | "version": "2.0.1", 4 | "description": "HMAC-based Extract-and-Expand Key Derivation Function (HKDF, RFC 5869)", 5 | "main": "./lib/hkdf.js", 6 | "type": "module", 7 | "typings": "./lib/hkdf.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/hkdf", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/hkdf.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/hash": "^2.0.0", 24 | "@stablelib/hmac": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1", 30 | "@stablelib/sha256": "^2.0.1", 31 | "@stablelib/sha512": "^2.0.1" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/hkdf/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/hkdf/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["hkdf.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/hmac-drbg/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/hmac-drbg/hmac-drbg.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { HMACDRBG } from "./hmac-drbg.js"; 5 | import type { RandomSource } from "@stablelib/random/source/index.js"; 6 | import { benchmark, report } from "@stablelib/benchmark"; 7 | 8 | class XKCDSource implements RandomSource { 9 | isAvailable = true; 10 | 11 | randomBytes(length: number): Uint8Array { 12 | const out = new Uint8Array(length); 13 | 14 | for (let i = 0; i < length; i++) { 15 | out[i] = 4; // chosen by fair dice roll. 16 | // guaranteed to be random 17 | } 18 | return out; 19 | } 20 | } 21 | 22 | const drbg = new HMACDRBG(new XKCDSource()); 23 | 24 | report("HMAC_DRBG", benchmark(() => drbg.randomBytes(1024), 1024)); 25 | -------------------------------------------------------------------------------- /packages/hmac-drbg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/hmac-drbg", 3 | "version": "2.0.1", 4 | "description": "HMAC DRBG (digital random byte generator, NIST)", 5 | "main": "./lib/hmac-drbg.js", 6 | "type": "module", 7 | "typings": "./lib/hmac-drbg.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/hmac-drbg", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "echo 'TODO: hmac-drbg test'", 20 | "bench": "node ./lib/hmac-drbg.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/hash": "^2.0.0", 24 | "@stablelib/hmac": "^2.0.1", 25 | "@stablelib/random": "^2.0.1", 26 | "@stablelib/sha256": "^2.0.1", 27 | "@stablelib/wipe": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "@stablelib/benchmark": "^2.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/hmac-drbg/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/hmac-drbg/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["hmac-drbg.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/hmac/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/hmac/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/hmac", 3 | "version": "2.0.1", 4 | "description": "Hash-based message authentication code (HMAC)", 5 | "main": "./lib/hmac.js", 6 | "type": "module", 7 | "typings": "./lib/hmac.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/hmac", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | }, 21 | "dependencies": { 22 | "@stablelib/constant-time": "^2.0.1", 23 | "@stablelib/hash": "^2.0.0", 24 | "@stablelib/wipe": "^2.0.1" 25 | }, 26 | "devDependencies": { 27 | "@stablelib/base64": "^2.0.1", 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/sha224": "^2.0.1", 30 | "@stablelib/sha256": "^2.0.1" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/hmac/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/hmac/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["hmac.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/int/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/int/int.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { mul, add, sub } from "./int.js"; 6 | 7 | describe("int.mul", () => { 8 | it("should overflow", () => { 9 | const float = 0xffffffff * 0x7fffffff; 10 | const int = mul(0xffffffff, 0x7fffffff); 11 | expect(int).toBeLessThan(float); 12 | }); 13 | it("should return correct result", () => { 14 | expect(mul(0x7fffffff, 0x5ffffff5)).toBe(0x2000000b); 15 | }); 16 | it("should be commutative", () => { 17 | expect(mul(0x7fffffff, 0x5ffffff5)) 18 | .toBe(mul(0x5ffffff5, 0x7fffffff)); 19 | }); 20 | }); 21 | 22 | describe("int.add", () => { 23 | it("should overflow", () => { 24 | const float = 0xffffffff + 0x7fffffff; 25 | const int = add(0xffffffff, 0x7fffffff); 26 | expect(int).toBeLessThan(float); 27 | }); 28 | it("should return correct result", () => { 29 | expect(add(0xffffffff, 1)).toBe(0); 30 | expect(add(2, 0xffffffff)).toBe(1); 31 | }); 32 | it("should be commutative", () => { 33 | expect(add(0x7fffffff, 0x5ffffff5)) 34 | .toBe(add(0x5ffffff5, 0x7fffffff)); 35 | }); 36 | }); 37 | 38 | describe("int.sub", () => { 39 | it("should overflow", () => { 40 | const float = 0xffffffff + 0x7fffffff; 41 | const int = sub(0x7fffffff, 0xffffffff); 42 | expect(int).toBeLessThan(float); 43 | }); 44 | it("should return correct result", () => { 45 | expect(sub(1, 0xffffffff)).toBe(2); 46 | expect(sub(2, 0xffffffff)).toBe(3); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /packages/int/int.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package int provides helper functions for integerss. 6 | */ 7 | 8 | /** 32-bit integer multiplication. */ 9 | export const mul = Math.imul; 10 | 11 | /** 32-bit integer addition. */ 12 | export function add(a: number, b: number): number { 13 | return (a + b) | 0; 14 | } 15 | 16 | /** 32-bit integer subtraction. */ 17 | export function sub(a: number, b: number): number { 18 | return (a - b) | 0; 19 | } 20 | 21 | /** 32-bit integer left rotation */ 22 | export function rotl(x: number, n: number): number { 23 | return x << n | x >>> (32 - n); 24 | } 25 | 26 | /** 32-bit integer left rotation */ 27 | export function rotr(x: number, n: number): number { 28 | return x << (32 - n) | x >>> n; 29 | } 30 | 31 | /** 32 | * Returns true if the argument is an integer number. 33 | */ 34 | export const isInteger = Number.isInteger; 35 | 36 | /** 37 | * Math.pow(2, 53) - 1 38 | */ 39 | export const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; 40 | 41 | /** 42 | * Returns true if the argument is a safe integer number 43 | * (-MIN_SAFE_INTEGER < number <= MAX_SAFE_INTEGER) 44 | */ 45 | export const isSafeInteger = Number.isSafeInteger; 46 | -------------------------------------------------------------------------------- /packages/int/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/int", 3 | "version": "2.0.1", 4 | "description": "Integer number utilities", 5 | "main": "./lib/int.js", 6 | "type": "module", 7 | "typings": "./lib/int.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/int", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/int/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/int/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["int.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/keyagreement/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/keyagreement/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/keyagreement", 3 | "version": "2.0.1", 4 | "description": "Key agreement interface declaration and utilities", 5 | "main": "./lib/keyagreement.js", 6 | "type": "module", 7 | "typings": "./lib/keyagreement.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/keyagreement", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "echo No test" 20 | }, 21 | "dependencies": { 22 | "@stablelib/bytes": "^2.0.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/keyagreement/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/keyagreement/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["keyagreement.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/nacl/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/nacl/box.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { scalarMult } from "@stablelib/x25519"; 5 | import { hsalsa } from "@stablelib/xsalsa20"; 6 | import { secretBox, openSecretBox } from "./secretbox.js"; 7 | import { wipe } from "@stablelib/wipe"; 8 | 9 | export { generateKeyPair } from "@stablelib/x25519"; 10 | 11 | const zeros16 = new Uint8Array(16); 12 | 13 | export function precomputeSharedKey(theirPublicKey: Uint8Array, mySecretKey: Uint8Array): Uint8Array { 14 | // Compute scalar multiplication result. 15 | const key = scalarMult(mySecretKey, theirPublicKey); 16 | 17 | // Hash key with HSalsa function. 18 | hsalsa(key, zeros16, key); 19 | 20 | return key; 21 | } 22 | 23 | export function box(theirPublicKey: Uint8Array, mySecretKey: Uint8Array, 24 | nonce: Uint8Array, data: Uint8Array): Uint8Array { 25 | const sharedKey = precomputeSharedKey(theirPublicKey, mySecretKey); 26 | const result = secretBox(sharedKey, nonce, data); 27 | wipe(sharedKey); 28 | return result; 29 | } 30 | 31 | export function openBox(theirPublicKey: Uint8Array, mySecretKey: Uint8Array, 32 | nonce: Uint8Array, data: Uint8Array): Uint8Array | null { 33 | const sharedKey = precomputeSharedKey(theirPublicKey, mySecretKey); 34 | const result = openSecretBox(sharedKey, nonce, data); 35 | wipe(sharedKey); 36 | return result; 37 | } 38 | -------------------------------------------------------------------------------- /packages/nacl/nacl.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package nacl implements NaCl (Networking and Cryptography library) cryptography. 6 | */ 7 | 8 | export * from "./box.js"; 9 | export * from "./secretbox.js"; 10 | -------------------------------------------------------------------------------- /packages/nacl/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/nacl", 3 | "version": "2.0.1", 4 | "description": "Implementation of secretbox and box from NaCl (Networking and Cryptography Library)", 5 | "main": "./lib/nacl.js", 6 | "type": "module", 7 | "typings": "./lib/nacl.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/nacl", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/secretbox.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/poly1305": "^2.0.1", 24 | "@stablelib/random": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1", 26 | "@stablelib/x25519": "^2.0.1", 27 | "@stablelib/xsalsa20": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "@stablelib/benchmark": "^2.0.0", 31 | "@stablelib/hex": "^2.0.1" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/nacl/secretbox.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { secretBox } from "./secretbox.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf8192 = byteSeq(8192); 8 | const buf1111 = byteSeq(1111); 9 | 10 | const key = byteSeq(32); 11 | const nonce = byteSeq(24); 12 | 13 | report("secretBox 8K", benchmark(() => secretBox(key, nonce, buf8192), buf8192.length)); 14 | report("secretBox 1111", benchmark(() => secretBox(key, nonce, buf1111), buf1111.length)); 15 | -------------------------------------------------------------------------------- /packages/nacl/secretbox.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { secretBox, openSecretBox } from "./secretbox.js"; 6 | import { encode, decode } from "@stablelib/hex"; 7 | 8 | describe("secretBox", () => { 9 | const key = new Uint8Array(32); 10 | for (let i = 0; i < key.length; i++) { 11 | key[i] = 1; 12 | } 13 | const nonce = new Uint8Array(24); 14 | for (let i = 0; i < nonce.length; i++) { 15 | nonce[i] = 2; 16 | } 17 | const data = new Uint8Array(64); 18 | for (let i = 0; i < data.length; i++) { 19 | data[i] = 3; 20 | } 21 | const good = "8442bc313f4626f1359e3b50122b6ce6fe66ddfe7d39d14e637eb4fd5b45beadab55198" + 22 | "df6ab5368439792a23c87db70acb6156dc5ef957ac04f6276cf6093b84be77ff0849cc" + 23 | "33e34b7254d5a8f65ad"; 24 | 25 | it("should generate correct secretbox", () => { 26 | expect(encode(secretBox(key, nonce, data), true)).toBe(good); 27 | }); 28 | 29 | it("should open secretbox", () => { 30 | const result = openSecretBox(key, nonce, decode(good)); 31 | expect(result).not.toBeNull(); 32 | expect(result).toEqual(data); 33 | }); 34 | 35 | it("should not open invalid secretbox", () => { 36 | const bad = decode(good); 37 | bad[50] = 0; 38 | expect(openSecretBox(key, nonce, bad)).toBeNull(); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /packages/nacl/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/nacl/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["nacl.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/newhope/newhope.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { NewHope } from "./newhope.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const seed = byteSeq(32); 8 | const offerMsg = new NewHope(seed).offer(seed); 9 | const acceptMsg = new NewHope(seed).accept(offerMsg); 10 | 11 | report("NewHope-SHA3 offer/finish", benchmark(() => { 12 | const state = new NewHope(seed); 13 | state.offer(seed); 14 | state.finish(acceptMsg); 15 | })); 16 | 17 | report("NewHope-SHA3 accept", benchmark(() => 18 | new NewHope(seed).accept(offerMsg))); 19 | -------------------------------------------------------------------------------- /packages/newhope/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/newhope", 3 | "version": "2.0.1", 4 | "description": "NewHope post-quantum secure key agreement", 5 | "main": "./lib/newhope.js", 6 | "type": "module", 7 | "typings": "./lib/newhope.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/newhope", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/newhope.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/bytes": "^2.0.1", 25 | "@stablelib/chacha": "^2.0.1", 26 | "@stablelib/hash": "^2.0.0", 27 | "@stablelib/keyagreement": "^2.0.1", 28 | "@stablelib/random": "^2.0.1", 29 | "@stablelib/sha3": "^2.0.1", 30 | "@stablelib/wipe": "^2.0.1" 31 | }, 32 | "devDependencies": { 33 | "@stablelib/benchmark": "^2.0.0", 34 | "@stablelib/hex": "^2.0.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/newhope/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/newhope/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["newhope.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/pbkdf2/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/pbkdf2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/pbkdf2", 3 | "version": "2.0.1", 4 | "description": "PBKDF2 (Password-based key derivation function)", 5 | "main": "./lib/pbkdf2.js", 6 | "type": "module", 7 | "typings": "./lib/pbkdf2.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/pbkdf2", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/pbkdf2.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/hash": "^2.0.0", 25 | "@stablelib/hmac": "^2.0.1", 26 | "@stablelib/wipe": "^2.0.1" 27 | }, 28 | "devDependencies": { 29 | "@stablelib/base64": "^2.0.1", 30 | "@stablelib/benchmark": "^2.0.0", 31 | "@stablelib/hex": "^2.0.1", 32 | "@stablelib/sha224": "^2.0.1", 33 | "@stablelib/sha256": "^2.0.1", 34 | "@stablelib/sha3": "^2.0.1", 35 | "@stablelib/sha512": "^2.0.1" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/pbkdf2/pbkdf2.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { deriveKey } from "./pbkdf2.js"; 5 | import { SHA256 } from "@stablelib/sha256"; 6 | import { SHA512 } from "@stablelib/sha512"; 7 | import { SHA3512 } from "@stablelib/sha3"; 8 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 9 | 10 | let password = byteSeq(14); 11 | let salt = byteSeq(32); 12 | 13 | report("pbkdf2/sha256 1", benchmark(() => deriveKey(SHA256, password, salt, 1, 32))); 14 | report("pbkdf2/sha256 5000", benchmark(() => deriveKey(SHA256, password, salt, 5000, 32))); 15 | report("pbkdf2/sha256 10000", benchmark(() => deriveKey(SHA256, password, salt, 10000, 32))); 16 | report("pbkdf2/sha512 5000", benchmark(() => deriveKey(SHA512, password, salt, 5000, 64))); 17 | report("pbkdf2/sha3-512 5000", benchmark(() => deriveKey(SHA3512, password, salt, 5000, 64))); 18 | -------------------------------------------------------------------------------- /packages/pbkdf2/pbkdf2.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package pbkdf2 implements PBKDF2 password-based key derivation function. 6 | */ 7 | 8 | import type { SerializableHash } from "@stablelib/hash"; 9 | import { HMAC } from "@stablelib/hmac"; 10 | import { writeUint32BE } from "@stablelib/binary"; 11 | import { wipe } from "@stablelib/wipe"; 12 | 13 | /** 14 | * Derives key from password with PBKDF2 algorithm using 15 | * the given hash function in HMAC construction. 16 | */ 17 | export function deriveKey(hash: new () => SerializableHash, password: Uint8Array, 18 | salt: Uint8Array, iterations: number, length: number): Uint8Array { 19 | const prf = new HMAC(hash, password); 20 | const dlen = prf.digestLength; 21 | const ctr = new Uint8Array(4); 22 | const t = new Uint8Array(dlen); 23 | const u = new Uint8Array(dlen); 24 | const dk = new Uint8Array(length); 25 | 26 | const saltedState = prf.update(salt).saveState(); 27 | 28 | for (let i = 0; i * dlen < length; i++) { 29 | writeUint32BE(i + 1, ctr); 30 | prf.restoreState(saltedState).update(ctr).finish(u); 31 | for (let j = 0; j < dlen; j++) { 32 | t[j] = u[j]; 33 | } 34 | for (let j = 2; j <= iterations; j++) { 35 | prf.reset().update(u).finish(u); 36 | for (let k = 0; k < dlen; k++) { 37 | t[k] ^= u[k]; 38 | } 39 | } 40 | for (let j = 0; j < dlen && i * dlen + j < length; j++) { 41 | dk[i * dlen + j] = t[j]; 42 | } 43 | } 44 | 45 | wipe(t); 46 | wipe(u); 47 | wipe(ctr); 48 | prf.cleanSavedState(saltedState); 49 | prf.clean(); 50 | 51 | return dk; 52 | } 53 | -------------------------------------------------------------------------------- /packages/pbkdf2/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/pbkdf2/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["pbkdf2.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/poly1305/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/poly1305", 3 | "version": "2.0.1", 4 | "description": "Poly1305 one-time message authentication code", 5 | "main": "./lib/poly1305.js", 6 | "type": "module", 7 | "typings": "./lib/poly1305.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/poly1305", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/poly1305.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/constant-time": "^2.0.1", 24 | "@stablelib/wipe": "^2.0.1" 25 | }, 26 | "devDependencies": { 27 | "@stablelib/benchmark": "^2.0.0", 28 | "@stablelib/bytes": "^2.0.1", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/poly1305/poly1305.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { oneTimeAuth } from "./poly1305.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf8192 = byteSeq(8192); 8 | const buf1024 = byteSeq(1024); 9 | const buf32 = byteSeq(32); 10 | const key = byteSeq(32); 11 | 12 | report("Poly1305 8K", benchmark(() => oneTimeAuth(key, buf8192), buf8192.length)); 13 | report("Poly1305 1K", benchmark(() => oneTimeAuth(key, buf1024), buf1024.length)); 14 | report("Poly1305 32", benchmark(() => oneTimeAuth(key, buf32), buf32.length)); 15 | -------------------------------------------------------------------------------- /packages/poly1305/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/poly1305/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["poly1305.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/random/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/random/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/random", 3 | "version": "2.0.1", 4 | "description": "Cryptographically-secure pseudorandom number generator", 5 | "main": "./lib/random.js", 6 | "type": "module", 7 | "typings": "./lib/random.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/random", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | }, 21 | "dependencies": { 22 | "@stablelib/binary": "^2.0.1", 23 | "@stablelib/wipe": "^2.0.1" 24 | }, 25 | "devDependencies": { 26 | "@stablelib/benchmark": "^2.0.0", 27 | "@stablelib/hex": "^2.0.1" 28 | }, 29 | "browser": { 30 | "crypto": false 31 | }, 32 | "react-native": { 33 | "crypto": false 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/random/source/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | export interface RandomSource { 5 | 6 | /** 7 | * Returns the availability of random source. 8 | * A source can only be used if isAvailable returns true. 9 | */ 10 | isAvailable: boolean; 11 | 12 | /** 13 | * Returns a byte array of the given length filled with random bytes. 14 | */ 15 | randomBytes(length: number): Uint8Array; 16 | } 17 | -------------------------------------------------------------------------------- /packages/random/source/system.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | import { describe, expect, it } from 'vitest'; 4 | import { SystemRandomSource } from "./system.js"; 5 | 6 | describe("SystemRandomSource.randomBytes", () => { 7 | 8 | const source = new SystemRandomSource(); 9 | 10 | it("should generate random bytes", () => { 11 | const len = 64; 12 | const zeros = new Uint8Array(len); 13 | const a = source.randomBytes(len); 14 | const b = source.randomBytes(len); 15 | expect(a.length).toBe(len); 16 | expect(b.length).toBe(len); 17 | expect(a).not.toEqual(b); 18 | expect(a).not.toEqual(zeros); 19 | expect(b).not.toEqual(zeros); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /packages/random/source/system.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import type { RandomSource } from "./index.js"; 5 | 6 | const QUOTA = 65536; 7 | 8 | export class SystemRandomSource implements RandomSource { 9 | isAvailable = false; 10 | isInstantiated = false; 11 | 12 | constructor() { 13 | if (typeof crypto !== "undefined" && 'getRandomValues' in crypto) { 14 | this.isAvailable = true; 15 | this.isInstantiated = true; 16 | } 17 | } 18 | 19 | randomBytes(length: number): Uint8Array { 20 | if (!this.isAvailable) { 21 | throw new Error("System random byte generator is not available."); 22 | } 23 | const out = new Uint8Array(length); 24 | for (let i = 0; i < out.length; i += QUOTA) { 25 | crypto.getRandomValues(out.subarray(i, i + Math.min(out.length - i, QUOTA))); 26 | } 27 | return out; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/random/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ], 10 | } 11 | -------------------------------------------------------------------------------- /packages/random/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["random.ts"], 4 | } 5 | -------------------------------------------------------------------------------- /packages/salsa20/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/salsa20/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/salsa20", 3 | "version": "2.0.1", 4 | "description": "Salsa20 stream cipher", 5 | "main": "./lib/salsa20.js", 6 | "type": "module", 7 | "typings": "./lib/salsa20.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/salsa20", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/salsa20.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/constant-time": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/salsa20/salsa20.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { streamXOR } from "./salsa20.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf8192 = byteSeq(8192); 8 | const buf1111 = byteSeq(1111); 9 | 10 | const key = byteSeq(32); 11 | const nonce = byteSeq(8); 12 | 13 | report("Salsa20/20 xor 8K", benchmark(() => streamXOR(key, nonce, buf8192, buf8192), buf8192.length)); 14 | report("Salsa20/20 xor 1111", benchmark(() => streamXOR(key, nonce, buf1111, buf1111), buf1111.length)); 15 | -------------------------------------------------------------------------------- /packages/salsa20/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/salsa20/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["salsa20.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/scrypt/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/scrypt/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/scrypt", 3 | "version": "2.0.1", 4 | "description": "Scrypt sequential memory-hard key derivation function (RFC 7914)", 5 | "main": "./lib/scrypt.js", 6 | "type": "module", 7 | "typings": "./lib/scrypt.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/scrypt", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/scrypt.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/int": "^2.0.1", 25 | "@stablelib/pbkdf2": "^2.0.1", 26 | "@stablelib/sha256": "^2.0.1", 27 | "@stablelib/wipe": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "@stablelib/base64": "^2.0.1", 31 | "@stablelib/benchmark": "^2.0.0", 32 | "@stablelib/utf8": "^2.0.1", 33 | "@types/node": "^18.7.6" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/scrypt/scrypt.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { deriveKey, deriveKeyNonBlocking, Scrypt } from "./scrypt.js"; 5 | import { benchmarkPromise, benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | (async () => { 8 | 9 | let password = byteSeq(14); 10 | let salt = byteSeq(32); 11 | 12 | report("scrypt 1024, 8, 1 ", 13 | benchmark(() => deriveKey(password, salt, 1024, 8, 1, 32))); 14 | 15 | report("scrypt 32768, 8, 1 ", 16 | benchmark(() => deriveKey(password, salt, 32768, 8, 1, 32))); 17 | 18 | report("scrypt 2**18, 8, 1 ", 19 | benchmark(() => deriveKey(password, salt, 2 ** 18, 8, 1, 32))); 20 | 21 | let inst = new Scrypt(32768, 8, 1); 22 | report("scrypt 32768, 8, 1 (shared) ", 23 | benchmark(() => inst.deriveKey(password, salt, 32))); 24 | 25 | 26 | report("scrypt 1024, 8, 1 (non-blocking) ", 27 | await benchmarkPromise(() => deriveKeyNonBlocking(password, salt, 1024, 8, 1, 32))); 28 | 29 | report("scrypt 32768, 8, 1 (non-blocking) ", 30 | await benchmarkPromise(() => deriveKeyNonBlocking(password, salt, 32768, 8, 1, 32))); 31 | 32 | report("scrypt 2**18, 8, 1 (non-blocking) ", 33 | await benchmarkPromise(() => deriveKeyNonBlocking(password, salt, 2 ** 18, 8, 1, 32))); 34 | 35 | inst = new Scrypt(32768, 8, 1); 36 | report("scrypt 32768, 8, 1 (non-blocking, shared)", 37 | await benchmarkPromise(() => inst.deriveKeyNonBlocking(password, salt, 32))); 38 | })(); 39 | 40 | -------------------------------------------------------------------------------- /packages/scrypt/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/scrypt/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["scrypt.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/sha224/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/sha224/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/sha224", 3 | "version": "2.0.1", 4 | "description": "SHA-224 cryptographic hash function", 5 | "main": "./lib/sha224.js", 6 | "type": "module", 7 | "typings": "./lib/sha224.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/sha224", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | }, 21 | "dependencies": { 22 | "@stablelib/sha256": "^2.0.1" 23 | }, 24 | "devDependencies": { 25 | "@stablelib/base64": "^2.0.1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/sha224/sha224.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package sha224 implements SHA-2-224 cryptographic hash function. 6 | */ 7 | 8 | import { SHA256 } from "@stablelib/sha256"; 9 | 10 | export const DIGEST_LENGTH = 28; 11 | export const BLOCK_SIZE = 64; 12 | 13 | /** 14 | * SHA-2-224 cryptographic hash algorithm. 15 | * 16 | * SHA-224 is the same algorithm as SHA-256, but with 17 | * different initialization vectors and digest length. 18 | */ 19 | export class SHA224 extends SHA256 { 20 | 21 | readonly digestLength: number = DIGEST_LENGTH; 22 | 23 | protected _initState() { 24 | this._state[0] = 0xc1059ed8; 25 | this._state[1] = 0x367cd507; 26 | this._state[2] = 0x3070dd17; 27 | this._state[3] = 0xf70e5939; 28 | this._state[4] = 0xffc00b31; 29 | this._state[5] = 0x68581511; 30 | this._state[6] = 0x64f98fa7; 31 | this._state[7] = 0xbefa4fa4; 32 | } 33 | } 34 | 35 | export function hash(data: Uint8Array): Uint8Array { 36 | const h = new SHA224(); 37 | h.update(data); 38 | const digest = h.digest(); 39 | h.clean(); 40 | return digest; 41 | } 42 | -------------------------------------------------------------------------------- /packages/sha224/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/sha224/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["sha224.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/sha256/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/sha256/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/sha256", 3 | "version": "2.0.1", 4 | "description": "SHA-256 cryptographic hash function", 5 | "main": "./lib/sha256.js", 6 | "type": "module", 7 | "typings": "./lib/sha256.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/sha256", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/sha256.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/hash": "^2.0.0", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/base64": "^2.0.1", 29 | "@stablelib/benchmark": "^2.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/sha256/sha256.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { hash } from "./sha256.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let buf1M = byteSeq(1024 << 10); 8 | let buf8K = byteSeq(8 << 10); 9 | let buf1K = byteSeq(1 << 10); 10 | let buf32 = byteSeq(32); 11 | 12 | report("SHA256 1M", benchmark(() => hash(buf1M), buf1M.length)); 13 | report("SHA256 8K", benchmark(() => hash(buf8K), buf8K.length)); 14 | report("SHA256 1K", benchmark(() => hash(buf1K), buf1K.length)); 15 | report("SHA256 32", benchmark(() => hash(buf32), buf32.length)); 16 | -------------------------------------------------------------------------------- /packages/sha256/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/sha256/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["sha256.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/sha3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/sha3", 3 | "version": "2.0.1", 4 | "description": "SHA-3 cryptographic hash function", 5 | "main": "./lib/sha3.js", 6 | "type": "module", 7 | "typings": "./lib/sha3.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/sha3", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/sha3.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/hash": "^2.0.0", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/base64": "^2.0.1", 29 | "@stablelib/benchmark": "^2.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/sha3/sha3.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { hash256 } from "./sha3.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let buf1M = byteSeq(1024 << 10); 8 | let buf8K = byteSeq(8 << 10); 9 | let buf1K = byteSeq(1 << 10); 10 | let buf32 = byteSeq(32); 11 | 12 | report("SHA3-256 1M", benchmark(() => hash256(buf1M), buf1M.length)); 13 | report("SHA3-256 8K", benchmark(() => hash256(buf8K), buf8K.length)); 14 | report("SHA3-256 1K", benchmark(() => hash256(buf1K), buf1K.length)); 15 | report("SHA3-256 32", benchmark(() => hash256(buf32), buf32.length)); 16 | -------------------------------------------------------------------------------- /packages/sha3/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/sha3/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["sha3.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/sha384/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/sha384/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/sha384", 3 | "version": "2.0.1", 4 | "description": "SHA-384 cryptographic hash function", 5 | "main": "./lib/sha384.js", 6 | "type": "module", 7 | "typings": "./lib/sha384.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/sha384", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | }, 21 | "dependencies": { 22 | "@stablelib/sha512": "^2.0.1" 23 | }, 24 | "devDependencies": { 25 | "@stablelib/base64": "^2.0.1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/sha384/sha384.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package sha384 implements SHA-2-384 cryptographic hash function. 6 | */ 7 | 8 | import { SHA512 } from "@stablelib/sha512"; 9 | 10 | export const DIGEST_LENGTH = 48; 11 | export const BLOCK_SIZE = 128; 12 | 13 | /** 14 | * SHA2-384 cryptographic hash algorithm. 15 | * 16 | * SHA-384 is the same algorithm as SHA-512, but with 17 | * different initialization vectors and digest length. 18 | */ 19 | export class SHA384 extends SHA512 { 20 | 21 | readonly digestLength = DIGEST_LENGTH; 22 | 23 | protected _initState() { 24 | this._stateHi[0] = 0xcbbb9d5d; 25 | this._stateHi[1] = 0x629a292a; 26 | this._stateHi[2] = 0x9159015a; 27 | this._stateHi[3] = 0x152fecd8; 28 | this._stateHi[4] = 0x67332667; 29 | this._stateHi[5] = 0x8eb44a87; 30 | this._stateHi[6] = 0xdb0c2e0d; 31 | this._stateHi[7] = 0x47b5481d; 32 | 33 | this._stateLo[0] = 0xc1059ed8; 34 | this._stateLo[1] = 0x367cd507; 35 | this._stateLo[2] = 0x3070dd17; 36 | this._stateLo[3] = 0xf70e5939; 37 | this._stateLo[4] = 0xffc00b31; 38 | this._stateLo[5] = 0x68581511; 39 | this._stateLo[6] = 0x64f98fa7; 40 | this._stateLo[7] = 0xbefa4fa4; 41 | } 42 | } 43 | 44 | export function hash(data: Uint8Array): Uint8Array { 45 | const h = new SHA384(); 46 | h.update(data); 47 | const digest = h.digest(); 48 | h.clean(); 49 | return digest; 50 | } 51 | -------------------------------------------------------------------------------- /packages/sha384/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/sha384/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["sha384.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/sha512/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/sha512", 3 | "version": "2.0.1", 4 | "description": "SHA-512 cryptographic hash function", 5 | "main": "./lib/sha512.js", 6 | "type": "module", 7 | "typings": "./lib/sha512.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/sha512", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/sha512.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/hash": "^2.0.0", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/base64": "^2.0.1", 29 | "@stablelib/benchmark": "^2.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/sha512/sha512.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { hash } from "./sha512.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | let buf1M = byteSeq(1024 << 10); 8 | let buf8K = byteSeq(8 << 10); 9 | let buf1K = byteSeq(1 << 10); 10 | let buf32 = byteSeq(32); 11 | 12 | report("SHA512 1M", benchmark(() => hash(buf1M), buf1M.length)); 13 | report("SHA512 8K", benchmark(() => hash(buf8K), buf8K.length)); 14 | report("SHA512 1K", benchmark(() => hash(buf1K), buf1K.length)); 15 | report("SHA512 32", benchmark(() => hash(buf32), buf32.length)); 16 | -------------------------------------------------------------------------------- /packages/sha512/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/sha512/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["sha512.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/sha512_256/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2017 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/sha512_256/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/sha512_256", 3 | "version": "2.0.1", 4 | "description": "SHA-512/256 cryptographic hash function", 5 | "main": "./lib/sha512_256.js", 6 | "type": "module", 7 | "typings": "./lib/sha512_256.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/sha512_256", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | }, 21 | "dependencies": { 22 | "@stablelib/sha512": "^2.0.1" 23 | }, 24 | "devDependencies": { 25 | "@stablelib/base64": "^2.0.1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/sha512_256/sha512_256.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package sha512_256 implements SHA-2-512/256 cryptographic hash function. 6 | */ 7 | 8 | import { SHA512 } from "@stablelib/sha512"; 9 | 10 | export const DIGEST_LENGTH = 32; 11 | export const BLOCK_SIZE = 128; 12 | 13 | /** 14 | * SHA2-512/256 cryptographic hash algorithm. 15 | * 16 | * SHA-512/256 is the same algorithm as SHA-512, but with 17 | * different initialization vectors and digest length. 18 | */ 19 | // eslint:disable-next-line 20 | export class SHA512_256 extends SHA512 { 21 | 22 | readonly digestLength = DIGEST_LENGTH; 23 | 24 | protected _initState() { 25 | this._stateHi[0] = 0x22312194; 26 | this._stateHi[1] = 0x9f555fa3; 27 | this._stateHi[2] = 0x2393b86b; 28 | this._stateHi[3] = 0x96387719; 29 | this._stateHi[4] = 0x96283ee2; 30 | this._stateHi[5] = 0xbe5e1e25; 31 | this._stateHi[6] = 0x2b0199fc; 32 | this._stateHi[7] = 0x0eb72ddc; 33 | 34 | this._stateLo[0] = 0xfc2bf72c; 35 | this._stateLo[1] = 0xc84c64c2; 36 | this._stateLo[2] = 0x6f53b151; 37 | this._stateLo[3] = 0x5940eabd; 38 | this._stateLo[4] = 0xa88effe3; 39 | this._stateLo[5] = 0x53863992; 40 | this._stateLo[6] = 0x2c85b8aa; 41 | this._stateLo[7] = 0x81c52ca2; 42 | } 43 | } 44 | 45 | export function hash(data: Uint8Array): Uint8Array { 46 | const h = new SHA512_256(); 47 | h.update(data); 48 | const digest = h.digest(); 49 | h.clean(); 50 | return digest; 51 | } 52 | -------------------------------------------------------------------------------- /packages/sha512_256/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/sha512_256/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["sha512_256.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/siv/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/siv/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/siv", 3 | "version": "2.0.1", 4 | "description": "Synthetic Initialization Vector (SIV) authenticated encryption", 5 | "main": "./lib/siv.js", 6 | "type": "module", 7 | "typings": "./lib/siv.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/siv", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/siv.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/blockcipher": "^2.0.0", 24 | "@stablelib/cmac": "^2.0.1", 25 | "@stablelib/constant-time": "^2.0.1", 26 | "@stablelib/ctr": "^2.0.1", 27 | "@stablelib/wipe": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "@stablelib/aes": "^2.0.1", 31 | "@stablelib/benchmark": "^2.0.0", 32 | "@stablelib/hex": "^2.0.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/siv/siv.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { SIV } from "./siv.js"; 5 | import { AES } from "@stablelib/aes"; 6 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 7 | 8 | const buf8192 = byteSeq(8192); 9 | const buf1111 = byteSeq(1111); 10 | 11 | const key = byteSeq(64); 12 | const ad = [byteSeq(12)]; 13 | const siv = new SIV(AES, key); 14 | 15 | report("AES-SIV seal 8K", benchmark(() => siv.seal(ad, buf8192), buf8192.length)); 16 | report("AES-SIV seal 1111", benchmark(() => siv.seal(ad, buf1111), buf1111.length)); 17 | 18 | const sealed8192 = siv.seal(ad, buf8192); 19 | const sealed1111 = siv.seal(ad, buf1111); 20 | 21 | report("AES-SIV open 8K", benchmark(() => siv.open(ad, sealed8192), buf8192.length)); 22 | report("AES-SIV open 1111", benchmark(() => siv.open(ad, sealed1111), buf1111.length)); 23 | 24 | sealed8192[0] ^= sealed8192[0]; 25 | 26 | report("AES-SIV open (bad)", benchmark(() => siv.open(ad, sealed8192), buf8192.length)); 27 | -------------------------------------------------------------------------------- /packages/siv/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/siv/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["siv.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/snappy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/snappy", 3 | "version": "2.0.1", 4 | "description": "Snappy compression algorithm", 5 | "main": "./lib/snappy.js", 6 | "type": "module", 7 | "typings": "./lib/snappy.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/snappy", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/snappy.bench.js" 21 | }, 22 | "devDependencies": { 23 | "@stablelib/benchmark": "^2.0.0", 24 | "@stablelib/hex": "^2.0.1", 25 | "@stablelib/utf8": "^2.0.1", 26 | "@types/node": "^18.7.6" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/snappy/snappy.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { benchmark, report } from "@stablelib/benchmark"; 5 | import { compress, maxCompressedLength } from "./compress.js"; 6 | import { decompress } from "./decompress.js"; 7 | import * as zlib from "zlib"; 8 | import data from "./compress.test-data.js"; 9 | 10 | 11 | const compressedData = compress(data); 12 | const decompressedData = new Uint8Array(data.length); 13 | const compressedDst = new Uint8Array(maxCompressedLength(data.length)); 14 | 15 | // console.log("Length: ", data.length, "/", compressedData.length); 16 | 17 | report("Snappy compress", benchmark(() => compress(data, compressedDst), data.length)); 18 | report("Snappy decompress", benchmark(() => decompress(compressedData, decompressedData), data.length)); 19 | 20 | const zOpts = { level: zlib.constants.Z_BEST_SPEED, strategy: zlib.constants.Z_HUFFMAN_ONLY }; 21 | const zData = Buffer.from(data); 22 | const zCompressedData = zlib.deflateSync(zData, zOpts); 23 | 24 | report("zlib-1 compress", benchmark(() => zlib.deflateSync(zData, zOpts), zData.length)); 25 | report("zlib-1 decompress", benchmark(() => zlib.inflateSync(zCompressedData), zData.length)); 26 | 27 | console.log("Snappy compressed length:", compressedData.length); 28 | console.log("zlib-1 compressed length:", zCompressedData.length); 29 | -------------------------------------------------------------------------------- /packages/snappy/snappy.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | // Based on snappy-go: https://github.com/golang/snappy 5 | // Copyright 2011 The Snappy-Go Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style 7 | // license that can be found in the LICENSE file. 8 | // https://github.com/golang/snappy/blob/master/LICENSE 9 | 10 | /** 11 | * Package snappy implements Snappy compression and decompression. 12 | */ 13 | 14 | export * from "./compress.js"; 15 | export * from "./decompress.js"; 16 | -------------------------------------------------------------------------------- /packages/snappy/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/snappy/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["snappy.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/tss/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/tss/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/tss", 3 | "version": "2.0.1", 4 | "description": "Threshold Secret Sharing (TSS and RTSS, IETF draft-mcgrew-tss-03)", 5 | "main": "./lib/tss.js", 6 | "type": "module", 7 | "typings": "./lib/tss.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/tss", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/tss.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/constant-time": "^2.0.1", 24 | "@stablelib/gf256": "^2.0.1", 25 | "@stablelib/hash": "^2.0.0", 26 | "@stablelib/random": "^2.0.1", 27 | "@stablelib/sha256": "^2.0.1", 28 | "@stablelib/wipe": "^2.0.1" 29 | }, 30 | "devDependencies": { 31 | "@stablelib/benchmark": "^2.0.0", 32 | "@stablelib/hex": "^2.0.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/tss/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/tss/tss.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { splitRaw, combineRaw, split, combine } from "./tss.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const secret = byteSeq(32); 8 | const threshold = 5; 9 | const totalShares = 10; 10 | const rawShares = splitRaw(secret, threshold, totalShares); 11 | const shares = split(secret, threshold, totalShares); 12 | 13 | report("tss.combineRaw", benchmark(() => combineRaw(rawShares, threshold))); 14 | report("tss.combine", benchmark(() => combine(shares))); 15 | report("tss.splitRaw", benchmark(() => splitRaw(secret, threshold, totalShares))); 16 | report("tss.split", benchmark(() => split(secret, threshold, totalShares))); 17 | -------------------------------------------------------------------------------- /packages/tss/tss.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { split, combine, combineRaw } from "./tss.js"; 6 | import { decode } from "@stablelib/hex"; 7 | 8 | describe("tss", () => { 9 | it("should split and combine", () => { 10 | const secret = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]); 11 | const threshold = 3; 12 | const totalShares = 8; 13 | 14 | const shares = split(secret, threshold, totalShares); 15 | 16 | const haveShares = [ 17 | shares[0], 18 | shares[5], 19 | shares[7] 20 | ]; 21 | 22 | const restored = combine(haveShares); 23 | 24 | expect(restored).toEqual(secret); 25 | }); 26 | 27 | it("should match test vectors", () => { 28 | // https://tools.ietf.org/html/draft-mcgrew-tss-03#section-9 29 | const secret = decode("7465737400"); 30 | const threshold = 2; 31 | const shares = [decode("01B9FA07E185"), decode("02F5409B4511")]; 32 | const restored = combineRaw(shares, threshold); 33 | expect(restored).toEqual(secret); 34 | }); 35 | }); 36 | 37 | // TODO(dchest): add more tests for invalid parameters, different hashes, etc. 38 | -------------------------------------------------------------------------------- /packages/tss/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["tss.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/utf8/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/utf8/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/utf8", 3 | "version": "2.0.1", 4 | "description": "UTF-8 encoder and decoder", 5 | "main": "./lib/utf8.js", 6 | "type": "module", 7 | "typings": "./lib/utf8.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/utf8", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/utf8.bench.js" 21 | }, 22 | "devDependencies": { 23 | "@stablelib/benchmark": "^2.0.0", 24 | "@stablelib/hex": "^2.0.1" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/utf8/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/utf8/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["utf8.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/uuid/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/uuid/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/uuid", 3 | "version": "2.0.1", 4 | "description": "UUID v4 (random) generator", 5 | "main": "./lib/uuid.js", 6 | "type": "module", 7 | "typings": "./lib/uuid.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/uuid", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | }, 21 | "dependencies": { 22 | "@stablelib/hex": "^2.0.1", 23 | "@stablelib/random": "^2.0.1", 24 | "@stablelib/wipe": "^2.0.1" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/uuid/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/uuid/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["uuid.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/uuid/uuid.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { uuid } from "./uuid.js"; 6 | 7 | describe("uuid", () => { 8 | it("should generate UUID", () => { 9 | expect(uuid()).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/); 10 | }); 11 | 12 | it("should generate different UUIDs", () => { 13 | const u1 = uuid(); 14 | const u2 = uuid(); 15 | expect(u1).not.toEqual(u2); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/uuid/uuid.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package uuid implements UUID generator. 6 | */ 7 | 8 | import type { RandomSource } from "@stablelib/random"; 9 | import { randomBytes } from "@stablelib/random"; 10 | import { encode } from "@stablelib/hex"; 11 | import { wipe } from "@stablelib/wipe"; 12 | 13 | /** 14 | * Returns a new universally unique identifier. 15 | * 16 | * UUID v4, generated using a cryptographically 17 | * strong random number generator. 18 | */ 19 | export function uuid(prng?: RandomSource): string { 20 | const b = randomBytes(16, prng); 21 | b[6] = (b[6] & 0x0f) | 0x40; 22 | b[8] = (b[8] & 0x3f) | 0x80; 23 | const x = encode(b, true); 24 | wipe(b); 25 | return x.substring(0, 8) + "-" + 26 | x.substring(8, 12) + "-" + 27 | x.substring(12, 16) + "-" + 28 | x.substring(16, 20) + "-" + 29 | x.substring(20, 32); 30 | } 31 | -------------------------------------------------------------------------------- /packages/wipe/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/wipe/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/wipe", 3 | "version": "2.0.1", 4 | "description": "Wipes bytes and arrays (sets all values to zero)", 5 | "main": "./lib/wipe.js", 6 | "type": "module", 7 | "typings": "./lib/wipe.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/wipe", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/wipe/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/wipe/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["wipe.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/wipe/wipe.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { wipe } from "./wipe.js"; 6 | 7 | describe("wipe", () => { 8 | it("should wipe bytes", () => { 9 | const a = new Uint8Array([1, 2, 3, 4]); 10 | wipe(a); 11 | expect(a).toEqual(new Uint8Array(4)); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/wipe/wipe.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | /** 5 | * Package wipe implements functions for zeroing arrays. 6 | */ 7 | 8 | export type NumericArray = number[] | Uint8Array | Int8Array | Uint16Array 9 | | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array; 10 | 11 | /** 12 | * Sets all values in the given array to zero and returns it. 13 | * 14 | * The fact that it sets bytes to zero can be relied on. 15 | * 16 | * There is no guarantee that this function makes data disappear from memory, 17 | * as runtime implementation can, for example, have copying garbage collector 18 | * that will make copies of sensitive data before we wipe it. Or that an 19 | * operating system will write our data to swap or sleep image. Another thing 20 | * is that an optimizing compiler can remove calls to this function or make it 21 | * no-op. There's nothing we can do with it, so we just do our best and hope 22 | * that everything will be okay and good will triumph over evil. 23 | */ 24 | export function wipe(array: NumericArray): NumericArray { 25 | // Right now it's similar to array.fill(0). If it turns 26 | // out that runtimes optimize this call away, maybe 27 | // we can try something else. 28 | for (let i = 0; i < array.length; i++) { 29 | array[i] = 0; 30 | } 31 | return array; 32 | } 33 | -------------------------------------------------------------------------------- /packages/x25519-session/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/x25519-session", 3 | "version": "2.0.1", 4 | "description": "libsodium compatible session keys generation based on X25519 key agreement", 5 | "main": "./lib/x25519-session.js", 6 | "type": "module", 7 | "typings": "./lib/x25519-session.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/x25519-session", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/x25519-session.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/blake2b": "^2.0.1", 24 | "@stablelib/keyagreement": "^2.0.1", 25 | "@stablelib/random": "^2.0.1", 26 | "@stablelib/wipe": "^2.0.1", 27 | "@stablelib/x25519": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "@stablelib/benchmark": "^2.0.0", 31 | "@stablelib/hash": "^2.0.0", 32 | "@stablelib/hex": "^2.0.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/x25519-session/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/x25519-session/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["x25519-session.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/x25519-session/x25519-session.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { X25519Session } from "./keyagreement.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const r = new Uint8Array(32); r[0] = 1; 8 | 9 | const seed = byteSeq(32); 10 | 11 | const offerMsg = new X25519Session(seed).offer(); 12 | const acceptMsg = new X25519Session(seed).accept(offerMsg); 13 | 14 | report("X25519Session offer/finish", benchmark(() => { 15 | const state = new X25519Session(seed); 16 | state.offer(); 17 | state.finish(acceptMsg); 18 | })); 19 | 20 | report("X25519Session accept", benchmark(() => 21 | new X25519Session(seed).accept(offerMsg))); 22 | -------------------------------------------------------------------------------- /packages/x25519/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/x25519", 3 | "version": "2.0.1", 4 | "description": "X25519 key agreement (Curve25519)", 5 | "main": "./lib/x25519.js", 6 | "type": "module", 7 | "typings": "./lib/x25519.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/x25519", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/x25519.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/keyagreement": "^2.0.1", 24 | "@stablelib/random": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/x25519/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/x25519/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["x25519.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/x25519/x25519.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { scalarMultBase } from "./x25519.js"; 5 | import { X25519KeyAgreement } from "./keyagreement.js"; 6 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 7 | 8 | const r = new Uint8Array(32); r[0] = 1; 9 | 10 | report("x25519.scalarMultBase", benchmark(() => scalarMultBase(r))); 11 | 12 | const seed = byteSeq(32); 13 | 14 | const offerMsg = new X25519KeyAgreement(seed).offer(); 15 | const acceptMsg = new X25519KeyAgreement(seed).accept(offerMsg); 16 | 17 | report("X25519KeyAgreement offer/finish", benchmark(() => { 18 | const state = new X25519KeyAgreement(seed); 19 | state.offer(); 20 | state.finish(acceptMsg); 21 | })); 22 | 23 | report("X25519KeyAgreement accept", benchmark(() => 24 | new X25519KeyAgreement(seed).accept(offerMsg))); 25 | -------------------------------------------------------------------------------- /packages/xchacha20/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2019 Kyle Den Hartog 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/xchacha20/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/xchacha20", 3 | "version": "2.0.1", 4 | "description": "XChaCha20 stream cipher", 5 | "main": "./lib/xchacha20.js", 6 | "type": "module", 7 | "typings": "./lib/xchacha20.d.ts", 8 | "contributors": [ 9 | { 10 | "name": "Dmitry Chestnykh" 11 | }, 12 | { 13 | "name": "Kyle Den Hartog" 14 | } 15 | ], 16 | "license": "MIT", 17 | "repository": { 18 | "url": "https://github.com/StableLib/stablelib" 19 | }, 20 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/xchacha20", 21 | "publishConfig": { 22 | "access": "public" 23 | }, 24 | "scripts": { 25 | "build": "tsc", 26 | "test": "vitest run", 27 | "bench": "node ./lib/xchacha20.bench.js" 28 | }, 29 | "dependencies": { 30 | "@stablelib/binary": "^2.0.1", 31 | "@stablelib/chacha": "^2.0.1", 32 | "@stablelib/wipe": "^2.0.1" 33 | }, 34 | "devDependencies": { 35 | "@stablelib/benchmark": "^2.0.0", 36 | "@stablelib/hex": "^2.0.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/xchacha20/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/xchacha20/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["xchacha20.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/xchacha20/xchacha20.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { streamXOR } from "./xchacha20.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf16K = byteSeq(16 << 10); 8 | const buf8192 = byteSeq(8192); 9 | const buf1111 = byteSeq(1111); 10 | const buf64 = byteSeq(64); 11 | 12 | 13 | const key = byteSeq(32); 14 | const nonce = byteSeq(24); 15 | 16 | report("ChaCha20 xor 16K", benchmark(() => streamXOR(key, nonce, buf16K, buf16K), buf16K.length)); 17 | report("ChaCha20 xor 8K", benchmark(() => streamXOR(key, nonce, buf8192, buf8192), buf8192.length)); 18 | report("ChaCha20 xor 1111", benchmark(() => streamXOR(key, nonce, buf1111, buf1111), buf1111.length)); 19 | report("ChaCha20 xor 64", benchmark(() => streamXOR(key, nonce, buf64, buf64), buf64.length)); 20 | -------------------------------------------------------------------------------- /packages/xchacha20poly1305/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2019 Kyle Den Hartog 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/xchacha20poly1305/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/xchacha20poly1305", 3 | "version": "2.0.1", 4 | "description": "XChaCha20-Poly1305 AEAD (draft-irtf-cfrg-xchacha-01)", 5 | "main": "./lib/xchacha20poly1305.js", 6 | "type": "module", 7 | "typings": "./lib/xchacha20poly1305.d.ts", 8 | "contributors": [ 9 | { 10 | "name": "Dmitry Chestnykh" 11 | }, 12 | { 13 | "name": "Kyle Den Hartog" 14 | } 15 | ], 16 | "license": "MIT", 17 | "repository": { 18 | "url": "https://github.com/StableLib/stablelib" 19 | }, 20 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/xchacha20poly1305", 21 | "publishConfig": { 22 | "access": "public" 23 | }, 24 | "scripts": { 25 | "build": "tsc", 26 | "test": "vitest run", 27 | "bench": "node ./lib/xchacha20poly1305.bench.js" 28 | }, 29 | "dependencies": { 30 | "@stablelib/aead": "^2.0.0", 31 | "@stablelib/chacha20poly1305": "^2.0.1", 32 | "@stablelib/constant-time": "^2.0.1", 33 | "@stablelib/wipe": "^2.0.1", 34 | "@stablelib/xchacha20": "^2.0.1" 35 | }, 36 | "devDependencies": { 37 | "@stablelib/benchmark": "^2.0.0", 38 | "@stablelib/hex": "^2.0.1" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/xchacha20poly1305/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/xchacha20poly1305/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["xchacha20poly1305.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/xsalsa20/LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT license: 2 | 3 | Copyright (C) 2016 Dmitry Chestnykh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/xsalsa20/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@stablelib/xsalsa20", 3 | "version": "2.0.1", 4 | "description": "XSalsa20 (eXtended-nonce Salsa20) stream cipher", 5 | "main": "./lib/xsalsa20.js", 6 | "type": "module", 7 | "typings": "./lib/xsalsa20.d.ts", 8 | "author": "Dmitry Chestnykh", 9 | "license": "MIT", 10 | "repository": { 11 | "url": "https://github.com/StableLib/stablelib" 12 | }, 13 | "homepage": "https://github.com/StableLib/stablelib/tree/master/packages/xsalsa20", 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "build": "tsc", 19 | "test": "vitest run", 20 | "bench": "node ./lib/xsalsa20.bench.js" 21 | }, 22 | "dependencies": { 23 | "@stablelib/binary": "^2.0.1", 24 | "@stablelib/salsa20": "^2.0.1", 25 | "@stablelib/wipe": "^2.0.1" 26 | }, 27 | "devDependencies": { 28 | "@stablelib/benchmark": "^2.0.0", 29 | "@stablelib/hex": "^2.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/xsalsa20/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../configs/tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "lib", 5 | }, 6 | "exclude": [ 7 | "node_modules", 8 | "lib" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/xsalsa20/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../configs/typedoc.base.json"], 3 | "entryPoints": ["xsalsa20.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/xsalsa20/xsalsa20.bench.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { streamXOR } from "./xsalsa20.js"; 5 | import { benchmark, report, byteSeq } from "@stablelib/benchmark"; 6 | 7 | const buf8192 = byteSeq(8192); 8 | const buf1111 = byteSeq(1111); 9 | 10 | const key = byteSeq(32); 11 | const nonce = byteSeq(24); 12 | 13 | report("XSalsa20/20 xor 8K", benchmark(() => streamXOR(key, nonce, buf8192, buf8192), buf8192.length)); 14 | report("XSalsa20/20 xor 1111", benchmark(() => streamXOR(key, nonce, buf1111, buf1111), buf1111.length)); 15 | -------------------------------------------------------------------------------- /packages/xsalsa20/xsalsa20.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Dmitry Chestnykh 2 | // MIT License. See LICENSE file for details. 3 | 4 | import { describe, expect, it } from 'vitest'; 5 | import { stream, hsalsa } from "./xsalsa20.js"; 6 | import { encode, decode } from "@stablelib/hex"; 7 | 8 | describe("xsalsa20.hsalsa", () => { 9 | it("should produce correct value", () => { 10 | const key = decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); 11 | const src = decode("FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0"); 12 | const good = "C6CB53882782B5B86DF1AB2ED9B810EC8A88C0A7F29211E693F0019FE0728858"; 13 | const dst = new Uint8Array(32); 14 | expect(encode(hsalsa(key, src, dst))).toBe(good); 15 | }); 16 | }); 17 | 18 | describe("xsalsa20.stream", () => { 19 | it("should produce correct result", () => { 20 | const key = decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); 21 | const nonce = decode("FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0EFEEEDECEBEAE9E8"); 22 | const good = "300885CCE813D8CDBE05F89706F9D5557041E4FADC3EBC5DB89C6CA60F7" + 23 | "3EDE4F91FF1F9521D3E9AF058E037E7FD0601DB9CCBD7A9F5CED151426F" + 24 | "DE32FC544F4F95576E2614377049C258664845A93D5FF5DD479CFEB55C7" + 25 | "579B60D419B8A8C03DA3494993577B4597DCB658BE52AB7"; 26 | const dst = new Uint8Array(good.length / 2); 27 | expect(encode(stream(key, nonce, dst))).toBe(good); 28 | }); 29 | }); 30 | 31 | // TODO(dchest): test nonceInplaceCounterLength 32 | -------------------------------------------------------------------------------- /typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "out": "../stablelib.github.io/", 3 | "excludeExternals": true, 4 | "excludePrivate": true, 5 | "excludeInternal": true, 6 | "theme": "default", 7 | "entryPointStrategy": "packages", 8 | "externalPattern": [ 9 | "**/node_modules/**" 10 | ], 11 | "exclude": [ 12 | "**/*.+(test|test-data|bench).ts" 13 | ], 14 | "name": "StableLib", 15 | "entryPoints": [ 16 | "./packages/*" 17 | ] 18 | } 19 | --------------------------------------------------------------------------------