├── .editorconfig ├── .gitignore ├── .gitmodules ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assembly ├── binding-c.ts ├── binding-js.ts ├── sodium-c.ts ├── sodium-js.ts └── tsconfig.json ├── bench └── index.js ├── build ├── aead_chacha20poly1305.js ├── aead_chacha20poly1305.wasm ├── aead_xchacha20poly1305.js ├── aead_xchacha20poly1305.wasm ├── binding-c.js ├── binding-c.wasm ├── binding-js.js ├── binding-js.wasm ├── core_hchacha20.js ├── core_hchacha20.wasm ├── crypto_kx.js ├── crypto_kx.wasm ├── onetimeauth_poly1305.js ├── onetimeauth_poly1305.wasm ├── stream_chacha20.js └── stream_chacha20.wasm ├── extend.js ├── index.js ├── lib ├── create-import.js ├── heap.js ├── load-sodium-wasm.js └── load-sync.js ├── package-lock.json ├── package.json ├── scripts ├── binding-to-base64.js └── build-sodium.js ├── sodium-modules.json └── tests └── index.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libsodium"] 2 | path = libsodium 3 | url = https://github.com/jedisct1/libsodium 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | libsodium 2 | bench 3 | assembly 4 | build/*.wasm 5 | tests 6 | scripts 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | - "12" 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## 0.0.6 - 2020-05-15 [YANKED] 10 | 11 | ## 0.0.5 - 2020-04-15 [YANKED] 12 | 13 | ## 0.0.4 - 2020-04-09 [YANKED] 14 | 15 | ## 0.0.3 - 2020-04-06 [YANKED] 16 | 17 | ## 0.0.2 - 2020-04-06 [YANKED] 18 | [Unreleased]: https://github.com/geut/sodium-javascript-plus/compare/v0.0.6...HEAD 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to sodium-javascript-plus 2 | 3 | ## Issue Contributions 4 | 5 | When opening new issues or commenting on existing issues on this repository 6 | please make sure discussions are related to concrete technical issues. 7 | 8 | Try to be *friendly* (we are not animals :monkey: or bad people :rage4:) and explain correctly how we can reproduce your issue. 9 | 10 | ## Code Contributions 11 | 12 | This document will guide you through the contribution process. 13 | 14 | ### Step 1: Fork 15 | 16 | Fork the project [on GitHub](https://github.com/geut/sodium-javascript-plus) and check out your copy locally. 17 | 18 | ```bash 19 | $ git clone git@github.com:username/sodium-javascript-plus.git 20 | $ cd sodium-javascript-plus 21 | $ npm install 22 | $ git remote add upstream git://github.com/geut/sodium-javascript-plus.git 23 | ``` 24 | 25 | ### Step 2: Branch 26 | 27 | Create a feature branch and start hacking: 28 | 29 | ```bash 30 | $ git checkout -b my-feature-branch -t origin/master 31 | ``` 32 | 33 | ### Step 3: Test 34 | 35 | Bug fixes and features **should come with tests**. We use [jest](https://jestjs.io/) to do that. 36 | 37 | ```bash 38 | $ npm test 39 | ``` 40 | 41 | ### Step 4: Lint 42 | 43 | Make sure the linter is happy and that all tests pass. Please, do not submit 44 | patches that fail either check. 45 | 46 | We use [standard](https://standardjs.com/) 47 | 48 | ### Step 5: Commit 49 | 50 | Make sure git knows your name and email address: 51 | 52 | ```bash 53 | $ git config --global user.name "Bruce Wayne" 54 | $ git config --global user.email "bruce@batman.com" 55 | ``` 56 | 57 | Writing good commit logs is important. A commit log should describe what 58 | changed and why. 59 | 60 | ### Step 6: Changelog 61 | 62 | If your changes are really important for the project probably the users want to know about it. 63 | 64 | We use [chan](https://github.com/geut/chan/) to maintain a well readable changelog for our users. 65 | 66 | ### Step 7: Push 67 | 68 | ```bash 69 | $ git push origin my-feature-branch 70 | ``` 71 | 72 | ### Step 8: Make a pull request ;) 73 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 GEUT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sodium-javascript-plus 2 | 3 | [![Build Status](https://travis-ci.com/geut/sodium-javascript-plus.svg?branch=master)](https://travis-ci.com/geut/sodium-javascript-plus) 4 | [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges) 5 | [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) 6 | [![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) 7 | 8 | > **Experimental** :microscope: sodium-javascript with support for xchacha20 and kx 9 | 10 | ## Install 11 | 12 | ``` 13 | $ npm install @geut/sodium-javascript-plus 14 | ``` 15 | 16 | ## Usage 17 | 18 | ```javascript 19 | const message = Buffer.from('some secret message') 20 | const ad = Buffer.from('50515253c0c1c2c3c4c5c6c7', 'hex') 21 | const nonce = Buffer.from('404142434445464748494a4b4c4d4e4f5051525354555657', 'hex') 22 | const key = Buffer.from('808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f', 'hex') 23 | const cipher = Buffer.alloc(message.length + sodium.crypto_aead_xchacha20poly1305_ietf_ABYTES) 24 | 25 | sodium.crypto_aead_xchacha20poly1305_ietf_encrypt( 26 | cipher, 27 | message, 28 | ad, 29 | null, 30 | nonce, 31 | key 32 | ) 33 | 34 | const decrypted = Buffer.alloc(message.length) 35 | 36 | sodium.crypto_aead_xchacha20poly1305_ietf_decrypt( 37 | decrypted, 38 | null, 39 | cipher, 40 | ad, 41 | nonce, 42 | key 43 | ) 44 | 45 | console.log(message.equals(decrypted), 'same message') 46 | ``` 47 | 48 | ### You can extend your sodium instance 49 | 50 | ```javascript 51 | const extend = require('@geut/sodium-javascript-plus/extend') 52 | const sodium = extend(require('sodium-javascript')) 53 | 54 | // ... 55 | ``` 56 | 57 | ## Issues 58 | 59 | :bug: If you found an issue we encourage you to report it on [github](https://github.com/geut/sodium-javascript-plus/issues). Please specify your OS and the actions to reproduce it. 60 | 61 | ## Contributing 62 | 63 | :busts_in_silhouette: Ideas and contributions to the project are welcome. You must follow this [guideline](https://github.com/geut/sodium-javascript-plus/blob/master/CONTRIBUTING.md). 64 | 65 | ## License 66 | 67 | MIT © A [**GEUT**](http://geutstudio.com/) project 68 | -------------------------------------------------------------------------------- /assembly/binding-c.ts: -------------------------------------------------------------------------------- 1 | import * as sodiumC from './sodium-c' 2 | 3 | export function crypto_aead_chacha20poly1305_ietf_encrypt( 4 | c: u32, 5 | clen: u32, 6 | m: u32, 7 | mlen: u32, 8 | ad: u32, 9 | adlen: u32, 10 | nsec: u32, 11 | npub: u32, 12 | k: u32 13 | ): u32 { 14 | return sodiumC.crypto_aead_chacha20poly1305_ietf_encrypt(c, clen, m, u64(mlen), ad, u64(adlen), nsec, npub, k) 15 | } 16 | 17 | export function crypto_aead_chacha20poly1305_ietf_decrypt( 18 | m: u32, 19 | mlen: u32, 20 | nsec: u32, 21 | c: u32, 22 | clen: u32, 23 | ad: u32, 24 | adlen: u32, 25 | npub: u32, 26 | k: u32 27 | ): u32 { 28 | return sodiumC.crypto_aead_chacha20poly1305_ietf_decrypt(m, mlen, nsec, c, u64(clen), ad, u64(adlen), npub, k) 29 | } 30 | 31 | export function crypto_aead_xchacha20poly1305_ietf_encrypt( 32 | c: u32, 33 | clen: u32, 34 | m: u32, 35 | mlen: u32, 36 | ad: u32, 37 | adlen: u32, 38 | nsec: u32, 39 | npub: u32, 40 | k: u32 41 | ): u32 { 42 | return sodiumC.crypto_aead_xchacha20poly1305_ietf_encrypt(c, clen, m, u64(mlen), ad, u64(adlen), nsec, npub, k) 43 | } 44 | 45 | export function crypto_aead_xchacha20poly1305_ietf_decrypt( 46 | m: u32, 47 | mlen: u32, 48 | nsec: u32, 49 | c: u32, 50 | clen: u32, 51 | ad: u32, 52 | adlen: u32, 53 | npub: u32, 54 | k: u32 55 | ): u32 { 56 | return sodiumC.crypto_aead_xchacha20poly1305_ietf_decrypt(m, mlen, nsec, c, u64(clen), ad, u64(adlen), npub, k) 57 | } 58 | -------------------------------------------------------------------------------- /assembly/binding-js.ts: -------------------------------------------------------------------------------- 1 | import * as sodiumJS from './sodium-js' 2 | 3 | export function crypto_generichash( 4 | out: u32, 5 | outlen: u32, 6 | inn: u32, 7 | innlen: u64, 8 | key: u32, 9 | keylen: u32 10 | ): u32 { 11 | return sodiumJS.crypto_generichash(out, outlen, inn, u32(innlen), key, keylen); 12 | } 13 | 14 | export function crypto_generichash_update( 15 | state: u32, 16 | inn: u32, 17 | innlen: u64 18 | ): u32 { 19 | return sodiumJS.crypto_generichash_update(state, inn, u32(innlen)); 20 | } 21 | -------------------------------------------------------------------------------- /assembly/sodium-c.ts: -------------------------------------------------------------------------------- 1 | export declare function crypto_aead_chacha20poly1305_ietf_encrypt( 2 | c: u32, 3 | clen: u32, 4 | m: u32, 5 | mlen: u64, 6 | ad: u32, 7 | adlen: u64, 8 | nsec: u32, 9 | npub: u32, 10 | k: u32 11 | ): u32 12 | 13 | export declare function crypto_aead_chacha20poly1305_ietf_decrypt( 14 | m: u32, 15 | mlen: u32, 16 | nsec: u32, 17 | c: u32, 18 | clen: u64, 19 | ad: u32, 20 | adlen: u64, 21 | npub: u32, 22 | k: u32 23 | ): u32 24 | 25 | export declare function crypto_aead_xchacha20poly1305_ietf_encrypt( 26 | c: u32, 27 | clen: u32, 28 | m: u32, 29 | mlen: u64, 30 | ad: u32, 31 | adlen: u64, 32 | nsec: u32, 33 | npub: u32, 34 | k: u32 35 | ): u32 36 | 37 | export declare function crypto_aead_xchacha20poly1305_ietf_decrypt( 38 | m: u32, 39 | mlen: u32, 40 | nsec: u32, 41 | c: u32, 42 | clen: u64, 43 | ad: u32, 44 | adlen: u64, 45 | npub: u32, 46 | k: u32 47 | ): u32 48 | -------------------------------------------------------------------------------- /assembly/sodium-js.ts: -------------------------------------------------------------------------------- 1 | export declare function crypto_generichash( 2 | out: u32, 3 | outlen: u32, 4 | inn: u32, 5 | innlen: u32, 6 | key: u32, 7 | keylen: u32 8 | ): u32 9 | 10 | export declare function crypto_generichash_update( 11 | state: u32, 12 | inn: u32, 13 | innlen: u32 14 | ): u32 15 | -------------------------------------------------------------------------------- /assembly/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../node_modules/assemblyscript/std/assembly.json", 3 | "include": [ 4 | "./**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /bench/index.js: -------------------------------------------------------------------------------- 1 | const bench = require('nanobench') 2 | const sodiumNative = require('sodium-native') 3 | const sodiumWrappers = require('libsodium-wrappers') 4 | const sodiumJS = require('..') 5 | 6 | sodiumWrappers.ready.then(() => { 7 | bench('sodiumNative xchacha20poly1305 (encrypt/decrypt) 200.000 times', function (b) { 8 | b.start() 9 | 10 | for (var i = 0; i < 200000; i++) { 11 | xchacha20poly1305(sodiumNative) 12 | } 13 | 14 | b.end() 15 | }) 16 | 17 | bench('sodiumWrappers xchacha20poly1305 (encrypt/decrypt) 200.000 times', function (b) { 18 | b.start() 19 | 20 | for (var i = 0; i < 200000; i++) { 21 | const message = Buffer.from( 22 | '4c616469657320616e642047656e746c656d656e206f662074686520636c6173' + 23 | '73206f66202739393a204966204920636f756c64206f6666657220796f75206f' + 24 | '6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73' + 25 | '637265656e20776f756c642062652069742e', 26 | 'hex' 27 | ) 28 | const ad = Buffer.from('50515253c0c1c2c3c4c5c6c7', 'hex') 29 | const nonce = Buffer.from('404142434445464748494a4b4c4d4e4f5051525354555657', 'hex') 30 | const key = Buffer.from('808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f', 'hex') 31 | 32 | const cipher = sodiumWrappers.crypto_aead_xchacha20poly1305_ietf_encrypt( 33 | message, 34 | ad, 35 | null, 36 | nonce, 37 | key 38 | ) 39 | 40 | const decrypted = sodiumWrappers.crypto_aead_xchacha20poly1305_ietf_decrypt( 41 | null, 42 | cipher, 43 | ad, 44 | nonce, 45 | key 46 | ) 47 | 48 | if (!Buffer.from(decrypted).equals(message)) { 49 | throw new Error('wrong') 50 | } 51 | } 52 | 53 | b.end() 54 | }) 55 | 56 | bench('sodiumJS xchacha20poly1305 (encrypt/decrypt) 200.000 times', function (b) { 57 | b.start() 58 | 59 | for (var i = 0; i < 200000; i++) { 60 | xchacha20poly1305(sodiumJS) 61 | } 62 | 63 | b.end() 64 | }) 65 | }) 66 | 67 | function xchacha20poly1305 (sodium) { 68 | const message = Buffer.from( 69 | '4c616469657320616e642047656e746c656d656e206f662074686520636c6173' + 70 | '73206f66202739393a204966204920636f756c64206f6666657220796f75206f' + 71 | '6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73' + 72 | '637265656e20776f756c642062652069742e', 73 | 'hex' 74 | ) 75 | const ad = Buffer.from('50515253c0c1c2c3c4c5c6c7', 'hex') 76 | const nonce = Buffer.from('404142434445464748494a4b4c4d4e4f5051525354555657', 'hex') 77 | const key = Buffer.from('808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f', 'hex') 78 | const cipher = Buffer.alloc(message.length + sodium.crypto_aead_xchacha20poly1305_ietf_ABYTES) 79 | 80 | sodium.crypto_aead_xchacha20poly1305_ietf_encrypt( 81 | cipher, 82 | message, 83 | ad, 84 | null, 85 | nonce, 86 | key 87 | ) 88 | 89 | const decrypted = Buffer.alloc(message.length) 90 | 91 | sodium.crypto_aead_xchacha20poly1305_ietf_decrypt( 92 | decrypted, 93 | null, 94 | cipher, 95 | ad, 96 | nonce, 97 | key 98 | ) 99 | 100 | if (!decrypted.equals(message)) { 101 | throw new Error('wrong') 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /build/aead_chacha20poly1305.js: -------------------------------------------------------------------------------- 1 | module.exports = 'AGFzbQEAAAABYgxgAAF/YAJ/fwF/YAAAYAJ/fwBgCH9/f35/fn9/AGACf34AYAl/f39/fn9+f38Bf2AJf39/fn9+f39/AX9gA39/fgF/YAZ/f35/f38Bf2AIf39+f39+f38Bf2AEf35/fwF/ApMCCQNlbnYiY3J5cHRvX29uZXRpbWVhdXRoX3BvbHkxMzA1X3VwZGF0ZQAIA2Vudg5zb2RpdW1fbWVtemVybwADA2VudiJjcnlwdG9fc3RyZWFtX2NoYWNoYTIwX2lldGZfeG9yX2ljAAkDZW52G2NyeXB0b19zdHJlYW1fY2hhY2hhMjBfaWV0ZgALA2VudiFjcnlwdG9fb25ldGltZWF1dGhfcG9seTEzMDVfZmluYWwAAQNlbnYgY3J5cHRvX29uZXRpbWVhdXRoX3BvbHkxMzA1X2luaXQAAQNlbnYQY3J5cHRvX3ZlcmlmeV8xNgABA2Vudg1zb2RpdW1fbWlzdXNlAAIDZW52Bm1lbW9yeQIAgAIDDAsFAgAAAAAGCgcEAwYJAX8BQbCYgAILB5YCByljcnlwdG9fYWVhZF9jaGFjaGEyMHBvbHkxMzA1X2lldGZfZW5jcnlwdAAQKWNyeXB0b19hZWFkX2NoYWNoYTIwcG9seTEzMDVfaWV0Zl9kZWNyeXB0AA4qY3J5cHRvX2FlYWRfY2hhY2hhMjBwb2x5MTMwNV9pZXRmX2tleWJ5dGVzAA0rY3J5cHRvX2FlYWRfY2hhY2hhMjBwb2x5MTMwNV9pZXRmX25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EEAOgACIAFBB0kNACACQXxqQQA6AAAgAEEAOgADIAFBCUkNACAAQQAgAGtBA3EiAmoiAEEANgIAIAAgASACa0F8cSICaiIBQXxqQQA2AgAgAkEJSQ0AIABBADYCCCAAQQA2AgQgAUF4akEANgIAIAFBdGpBADYCACACQRlJDQAgAEEANgIYIABBADYCFCAAQQA2AhAgAEEANgIMIAFBcGpBADYCACABQWxqQQA2AgAgAUFoakEANgIAIAFBZGpBADYCACACIABBBHFBGHIiAmsiAUEgSQ0AIAAgAmohAANAIABCADcDGCAAQgA3AxAgAEIANwMIIABCADcDACAAQSBqIQAgAUFgaiIBQR9LDQALCwsLDAEAQbCYwAELA9AMQA==' -------------------------------------------------------------------------------- /build/aead_chacha20poly1305.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/aead_chacha20poly1305.wasm -------------------------------------------------------------------------------- /build/aead_xchacha20poly1305.js: -------------------------------------------------------------------------------- 1 | module.exports = 'AGFzbQEAAAABag1gAAF/YAJ/fwF/YAAAYAJ/fwBgCH9/f35/fn9/AGAIf39+f39+f38Bf2ACf34AYAR/f39/AX9gCX9/f39+f35/fwF/YAl/f39+f35/f38Bf2ADf39+AX9gBn9/fn9/fwF/YAR/fn9/AX8CtwIKA2VudiJjcnlwdG9fb25ldGltZWF1dGhfcG9seTEzMDVfdXBkYXRlAAoDZW52DnNvZGl1bV9tZW16ZXJvAAMDZW52IWNyeXB0b19vbmV0aW1lYXV0aF9wb2x5MTMwNV9maW5hbAABA2VudiZjcnlwdG9fc3RyZWFtX2NoYWNoYTIwX2lldGZfZXh0X3hvcl9pYwALA2VudiBjcnlwdG9fb25ldGltZWF1dGhfcG9seTEzMDVfaW5pdAABA2Vudh9jcnlwdG9fc3RyZWFtX2NoYWNoYTIwX2lldGZfZXh0AAwDZW52FWNyeXB0b19jb3JlX2hjaGFjaGEyMAAHA2VudhBjcnlwdG9fdmVyaWZ5XzE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2ogAiADIAQgBSAHIAgQFSABBEAgASADQhB8NwMAC0EADwsQCAAL2gEBAX8jAEHQAmsiCCQAIAhBEGpCwAAgBiAHEAUaIAhB0ABqIAhBEGoQBBogCEEQakHAABABIAhB0ABqIAQgBRAAGiAIQdAAakGwmIACQgAgBX1CD4MQABogACACIAMgBkEBIAcQAxogCEHQAGogACADEAAaIAhB0ABqQbCYgAJCACADfUIPgxAAGiAIQQhqIAUQCSAIQdAAaiAIQQhqQggQABogCEEIaiADEAkgCEHQAGogCEEIakIIEAAaIAhB0ABqIAEQAhogCEHQAGpBgAIQASAIQdACaiQAC9YCAQF/AkAgAUUNACAAIAFqIgJBf2pBADoAACAAQQA6AAAgAUEDSQ0AIAJBfmpBADoAACAAQQA6AAEgAkF9akEAOgAAIABBADoAAiABQQdJDQAgAkF8akEAOgAAIABBADoAAyABQQlJDQAgAEEAIABrQQNxIgJqIgBBADYCACAAIAEgAmtBfHEiAmoiAUF8akEANgIAIAJBCUkNACAAQQA2AgggAEEANgIEIAFBeGpBADYCACABQXRqQQA2AgAgAkEZSQ0AIABBADYCGCAAQQA2AhQgAEEANgIQIABBADYCDCABQXBqQQA2AgAgAUFsakEANgIAIAFBaGpBADYCACABQWRqQQA2AgAgAiAAQQRxQRhyIgJrIgFBIEkNACAAIAJqIQADQCAAQgA3AxggAEIANwMQIABCADcDCCAAQgA3AwAgAEEgaiEAIAFBYGoiAUEfSw0ACwsLBABBEAsEAEEAC1QBAX8jAEEwayIIJAAgCEEANgIEIAhBEGogBiAHQQAQBhogCCAGKQAQNwIIIAAgASACIAMgBCAFIAhBBGogCEEQahARIAhBEGpBIBABIAhBMGokAAsLDAEAQcCcgAILA+AOUA==' -------------------------------------------------------------------------------- /build/aead_xchacha20poly1305.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/aead_xchacha20poly1305.wasm -------------------------------------------------------------------------------- /build/binding-c.js: -------------------------------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AIAAgBBALIAAgBBAKIgNFBEBBAEHAnMACQfYDQRMQAAALCwsgAygCAEF8cSAESQRAQQBBwJzAAkH+A0ENEAAACyADQQA2AgQgAyACNgIIIAMgATYCDCAAIAMQBSAAIAMgBBAMIAMLDQAQCCAAIAEQDUEQagtVAQF/IAAoAgQiAUGAgICAf3EgAUEBakGAgICAf3FHBEBBAEGwncACQe0AQQIQAAALIAAgAUEBajYCBCAAKAIAQQFxBEBBAEGwncACQfAAQQ0QAAALCxYAIABB7J3AAksEQCAAQRBrEA8LIAALFAAgAEHsncACSwRAIABBEGsQFwsLGAAgACABIAIgA60gBCAFrSAGIAcgCBABCxgAIAAgASACIAMgBK0gBSAGrSAHIAgQAgsYACAAIAEgAiADrSAEIAWtIAYgByAIEAMLGAAgACABIAIgAyAErSAFIAatIAcgCBAECwMAAQuXAQECfyAAKAIEIgJB/////wBxIQEgACgCAEEBcQRAQQBBsJ3AAkH6AEENEAAACyABQQFGBEAgAEEQahAYIAJBgICAgHhxBEBBAEGwncACQf4AQREQAAALIAAgACgCAEEBcjYCACMAIAAQBgUgAUEATQRAQQBBsJ3AAkGIAUEPEAAACyAAIAFBAWsgAkGAgICAf3FyNgIECws4AAJAAkACQCAAQQhrKAIADgMAAAECCw8LIAAoAgAiAARAIABB7J3AAk8EQCAAQRBrEBcLCw8LAAsLxwEEAEGwnMACCy0eAAAAAQAAAAEAAAAeAAAAfgBsAGkAYgAvAHIAdAAvAHQAbABzAGYALgB0AHMAQeCcwAILNygAAAABAAAAAQAAACgAAABhAGwAbABvAGMAYQB0AGkAbwBuACAAdABvAG8AIABsAGEAcgBnAGUAQaCdwAILLR4AAAABAAAAAQAAAB4AAAB+AGwAaQBiAC8AcgB0AC8AcAB1AHIAZQAuAHQAcwBB0J3AAgsVAwAAABAAAAAAAAAAEAAAAAAAAAAQ' -------------------------------------------------------------------------------- /build/binding-c.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/binding-c.wasm -------------------------------------------------------------------------------- /build/binding-js.js: -------------------------------------------------------------------------------- 1 | module.exports = 'AGFzbQEAAAABIwRgA39/fwF/YAZ/f39/f38Bf2AGf39/fn9/AX9gA39/fgF/AkYCCXNvZGl1bS1qcxJjcnlwdG9fZ2VuZXJpY2hhc2gAAQlzb2RpdW0tanMZY3J5cHRvX2dlbmVyaWNoYXNoX3VwZGF0ZQAAAwMCAgMFAwEAAAc7AwZtZW1vcnkCABJjcnlwdG9fZ2VuZXJpY2hhc2gAAhljcnlwdG9fZ2VuZXJpY2hhc2hfdXBkYXRlAAMKHwIRACAAIAEgAiADpyAEIAUQAAsLACAAIAEgAqcQAQs=' -------------------------------------------------------------------------------- /build/binding-js.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/binding-js.wasm -------------------------------------------------------------------------------- /build/core_hchacha20.js: -------------------------------------------------------------------------------- 1 | module.exports = 'AGFzbQEAAAABFwRgAABgAn9/AGACf38Bf2AEf39/fwF/AhABA2VudgZtZW1vcnkCAIACAwUEAgEAAwciAhVjcnlwdG9fY29yZV9oY2hhY2hhMjAAAwZfc3RhcnQAAgrsBQQHACAAIAF3CwkAIAAgATYAAAsDAAEL0wUBEX8CfyADRQRAQbLaiMsHIQRB7siBmQMhCkHl8MGLBiELQfTKgdkGDAELIAMoAAAhCyADKAAEIQogAygACCEEIAMoAAwLIQUgAigAACEDIAIoAAQhByACKAAIIQYgAigADCEIIAIoABAhDCACKAAUIQ0gAigAGCEPIAIoABwhESABKAAAIQIgASgABCEOIAEoAAghCSABKAAMIQEDQCADIAwgAiADIAtqIgtzQRAQACIQaiIMc0EMEAAhAiACIAwgECACIAtqIgtzQQgQACIQaiIMc0EHEAAhAyAHIA4gByAKaiIKc0EQEAAiDiANaiINc0EMEAAhAiACIA4gAiAKaiIKc0EIEAAiDiANaiINc0EHEAAhAiAGIAkgBCAGaiIHc0EQEAAiCSAPaiIPc0EMEAAhBCAEIAkgBCAHaiISc0EIEAAiCSAPaiIHc0EHEAAhBCAIIAEgBSAIaiIFc0EQEAAiBiARaiIPc0EMEAAhASABIAYgASAFaiITc0EIEAAiBiAPaiIIc0EHEAAhBSACIAcgBiACIAtqIgFzQRAQACIGaiIHc0EMEAAhAiACIAcgBiABIAJqIgtzQQgQACIBaiIPc0EHEAAhByAEIAggECAEIApqIgJzQRAQACIGaiIIc0EMEAAhBCAEIAggBiACIARqIgpzQQgQACICaiIRc0EHEAAhBiAFIA4gBSASaiIEc0EQEAAiCCAMaiIMc0EMEAAhBSAFIAwgCCAEIAVqIgRzQQgQACIOaiIMc0EHEAAhCCADIAkgAyATaiIFc0EQEAAiCSANaiINc0EMEAAhAyADIAkgAyAFaiIFc0EIEAAiCSANaiINc0EHEAAhAyAUQQFqIhRBCkcNAAsgACALEAEgAEEEaiAKEAEgAEEIaiAEEAEgAEEMaiAFEAEgAEEQaiACEAEgAEEUaiAOEAEgAEEYaiAJEAEgAEEcaiABEAFBAAsLDAEAQZCQwAALA7AIIA==' -------------------------------------------------------------------------------- /build/core_hchacha20.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/core_hchacha20.wasm -------------------------------------------------------------------------------- /build/crypto_kx.js: -------------------------------------------------------------------------------- 1 | module.exports = 'AGFzbQEAAAABPAlgA39/fwF/YAAAYAJ/fwBgAn9/AX9gBX9/f39/AX9gAAF/YAR/f39/AX9gBn9/f35/fwF/YAN/f34BfwL6AQoDZW52DnNvZGl1bV9tZW16ZXJvAAIDZW52GWNyeXB0b19nZW5lcmljaGFzaF91cGRhdGUACANlbnYNc29kaXVtX21pc3VzZQABA2VudhhjcnlwdG9fZ2VuZXJpY2hhc2hfZmluYWwAAANlbnYXY3J5cHRvX2dlbmVyaWNoYXNoX2luaXQABgNlbnYRY3J5cHRvX3NjYWxhcm11bHQ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wsQAgALDgAgAUEgEAcgACABEAYLFwAgAUEgIAJCIEEAQQAQCBogACABEAYLCwwBAEHAoMACCwPgEGA=' -------------------------------------------------------------------------------- /build/crypto_kx.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/crypto_kx.wasm -------------------------------------------------------------------------------- /build/onetimeauth_poly1305.js: -------------------------------------------------------------------------------- 1 | module.exports = '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' -------------------------------------------------------------------------------- /build/onetimeauth_poly1305.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/onetimeauth_poly1305.wasm -------------------------------------------------------------------------------- /build/stream_chacha20.js: -------------------------------------------------------------------------------- 1 | module.exports = 'AGFzbQEAAAABOAhgBH9+f38Bf2AGf39+f39/AX9gAn9/AGAAAGADf39/AGACf38Bf2AEf39/fgBgBn9/fn9+fwF/AjkDA2Vudg5zb2RpdW1fbWVtemVybwACA2Vudg1zb2RpdW1fbWlzdXNlAAMDZW52Bm1lbW9yeQIAgAIDERAFAgYCBQMEAQQAAAABAAEHBAUBcAEGBgYJAX8BQaCUwAELB5gBBR9jcnlwdG9fc3RyZWFtX2NoYWNoYTIwX2lldGZfZXh0AAsmY3J5cHRvX3N0cmVhbV9jaGFjaGEyMF9pZXRmX2V4dF94b3JfaWMACRtjcnlwdG9fc3RyZWFtX2NoYWNoYTIwX2lldGYADyJjcnlwdG9fc3RyZWFtX2NoYWNoYTIwX2lldGZfeG9yX2ljAA4GX3N0YXJ0AAcJCwEAQQELBQ0MERAHCoISEAcAIAAgAXcLCQAgACABNgAAC9QJATF/IwBBQGoiHCQAIANQRQRAIAAoAjwhHSAAKAI4IR4gACgCNCESIAAoAjAhEyAAKAIsIR8gACgCKCEgIAAoAiQhISAAKAIgISIgACgCHCEjIAAoAhghJCAAKAIUISUgACgCECEmIAAoAgwhJyAAKAIIISggACgCBCEpIAAoAgAhKgNAAkAgA0I/VgRAIAIhBAwBC0EAIQYgHEHAABAGIQQDQCAEIAZqIAEgBmotAAA6AAAgAyAGQQFqIgatVg0ACyAEIQEgAiErC0EUIRcgKiENICkhFCAoIRAgJyEOICYhBiAlIQggJCECICMhDyAiIQwgISEJICAhFSAdIREgHiEKIBIhByATIQUgHyELA0AgBiAMIAYgDWoiDSAFc0EQEAIiFmoiBXNBDBACIQwgDCAWIAwgDWoiDXNBCBACIhogBWoiG3NBBxACIRggCSAIIBRqIgwgB3NBEBACIgdqIgUgCHNBDBACIQkgCSAHIAkgDGoiFHNBCBACIgwgBWoiFnNBBxACIQggAiAVIAogAiAQaiIVc0EQEAIiB2oiBXNBDBACIQIgAiAHIAIgFWoiCXNBCBACIgYgBWoiCnNBBxACIRkgCyAOIA9qIgUgEXNBEBACIgJqIgsgD3NBDBACIREgESALIAIgBSARaiIOc0EIEAIiAmoiB3NBBxACIRAgCCACIAggDWoiBXNBEBACIgsgCmoiAnNBDBACIQogCiALIAUgCmoiDXNBCBACIhEgAmoiFXNBBxACIQggGSAaIBQgGWoiBXNBEBACIgsgB2oiAnNBDBACIQcgByALIAUgB2oiFHNBCBACIgUgAmoiC3NBBxACIQIgECAMIAkgEGoiCXNBEBACIgcgG2oiCnNBDBACIQ8gDyAKIAcgCSAPaiIQc0EIEAIiB2oiDHNBBxACIQ8gGCAGIA4gGGoiDnNBEBACIgogFmoiCXNBDBACIQYgBiAJIAogBiAOaiIOc0EIEAIiCmoiCXNBBxACIQYgF0F+aiIXDQALIAEoAAQhLCABKAAIIS0gASgADCEuIAEoABAhLyABKAAUITAgASgAGCExIAEoABwhMiABKAAgITMgASgAJCE0IAEoACghFyABKAAsIRggASgAMCEZIAEoADQhGiABKAA4IRsgASgAPCEWIAQgASgAACANICpqcxADIARBBGogLCAUIClqcxADIARBCGogLSAQIChqcxADIARBDGogLiAOICdqcxADIARBEGogLyAGICZqcxADIARBFGogMCAIICVqcxADIARBGGogMSACICRqcxADIARBHGogMiAPICNqcxADIARBIGogMyAMICJqcxADIARBJGogNCAJICFqcxADIARBKGogFyAVICBqcxADIARBLGogGCALIB9qcxADIARBMGogGSAFIBNqcxADIARBNGogGiAHIBJqcxADIARBOGogGyAKIB5qcxADIARBPGogFiARIB1qcxADIBIgE0EBaiILIBNJaiESIANCwABYBEACQCADQj9WDQAgA6ciAUUNAEEAIQgDQCAIICtqIAQgCGotAAA6AAAgCEEBaiIIIAFHDQALCyAAIBI2AjQgACALNgIwBSABQUBrIQEgBEFAayECIANCQHwhAyALIRMMAQsLCyAcQUBrJAALcQAgAELl8MGL5o2ZkDM3AgAgAEKy2ojLx66ZkOsANwIIIAAgASgAADYCECAAIAEoAAQ2AhQgACABKAAINgIYIAAgASgADDYCHCAAIAEoABA2AiAgACABKAAUNgIkIAAgASgAGDYCKCAAIAEoABw2AiwL2AIBAn8CQCABRQ0AIAAgAWoiAkF/akEAOgAAIABBADoAACABQQNJDQAgAkF+akEAOgAAIABBADoAASACQX1qQQA6AAAgAEEAOgACIAFBB0kNACACQXxqQQA6AAAgAEEAOgADIAFBCUkNACAAQQAgAGtBA3EiA2oiAkEANgIAIAIgASADa0F8cSIDaiIBQXxqQQA2AgAgA0EJSQ0AIAJBADYCCCACQQA2AgQgAUF4akEANgIAIAFBdGpBADYCACADQRlJDQAgAkEANgIYIAJBADYCFCACQQA2AhAgAkEANgIMIAFBcGpBADYCACABQWxqQQA2AgAgAUFoakEANgIAIAFBZGpBADYCACADIAJBBHFBGHIiA2siAUEgSQ0AIAIgA2ohAgNAIAJCADcDGCACQgA3AxAgAkIANwMIIAJCADcDACACQSBqIQIgAUFgaiIBQR9LDQALCyAACwMAAQs9ACAAAn8gAgRAIAAgAigAADYCMCACKAAEDAELIABBADYCMEEACzYCNCAAIAEoAAA2AjggACABKAAENgI8CygAIAJCgICAgBBaBEAQAQALIAAgASACIAMgBCAFQZyQgAEoAgARAQALMgAgACACBH8gAigAAAVBAAs2AjAgACABKAAANgI0IAAgASgABDYCOCAAIAEoAAg2AjwLJAAgAUKAgICAEFoEQBABAAsgACABIAIgA0GUkIABKAIAEQAAC0MBAX8jAEFAaiIEJAAgAVBFBEAgBCADEAUgBCACQQAQCiAEIAAgAacQBiIAIAAgARAEIARBwAAQAAsgBEFAayQAQQALQwEBfyMAQUBqIgQkACABUEUEQCAEIAMQBSAEIAJBABAIIAQgACABpxAGIgAgACABEAQgBEHAABAACyAEQUBrJABBAAspAEKAgICAECACQj98QgaIfSAErVQEQBABAAsgACABIAIgAyAEIAUQCQsbACABQoCAgIAQWgRAEAEACyAAIAEgAiADEAsLVgEBfyMAQdAAayIGJAAgAlBFBEAgBkEMaiAEEAMgBkEQaiAFEAUgBkEQaiADIAZBDGoQCiAGQRBqIAEgACACEAQgBkEQakHAABAACyAGQdAAaiQAQQALZAEBfyMAQdAAayIGJAAgAlBFBEAgBkEIaiAEpxADIAZBDGogBEIgiKcQAyAGQRBqIAUQBSAGQRBqIAMgBkEIahAIIAZBEGogASAAIAIQBCAGQRBqQcAAEAALIAZB0ABqJABBAAsLIQIAQZCQgAELDQEAAAACAAAAAwAAAAQAQaCUgAELA8AKMA==' -------------------------------------------------------------------------------- /build/stream_chacha20.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geut/sodium-javascript-plus/9665aabf25ffa83b188217d4fdba9dfff5257eeb/build/stream_chacha20.wasm -------------------------------------------------------------------------------- /extend.js: -------------------------------------------------------------------------------- 1 | const Heap = require('./lib/heap') 2 | const loadSodiumWasm = require('./lib/load-sodium-wasm') 3 | 4 | module.exports = (sodiumJS) => { 5 | const heap = new Heap() 6 | 7 | const sodiumWasm = loadSodiumWasm(sodiumJS, heap) 8 | 9 | sodiumJS.crypto_aead_chacha20poly1305_ietf_encrypt = function (out, m, ad, nsec, nonce, key) { 10 | const cipherLength = m.length + sodiumJS.crypto_aead_chacha20poly1305_ietf_ABYTES 11 | const _out = heap.alloc(cipherLength) 12 | 13 | sodiumWasm.crypto_aead_chacha20poly1305_ietf_encrypt( 14 | _out, 15 | null, 16 | heap.set(m), 17 | m.length, 18 | ad ? heap.set(ad) : null, 19 | ad ? ad.length : null, 20 | nsec ? heap.set(nsec) : null, 21 | heap.set(nonce), 22 | heap.set(key) 23 | ) 24 | 25 | heap.copy(out, _out, cipherLength) 26 | heap.release() 27 | return cipherLength 28 | } 29 | 30 | sodiumJS.crypto_aead_chacha20poly1305_ietf_decrypt = function (out, nsec, c, ad, nonce, key) { 31 | const messageLength = c.length - sodiumJS.crypto_aead_chacha20poly1305_ietf_ABYTES 32 | const _out = heap.alloc(messageLength) 33 | 34 | sodiumWasm.crypto_aead_chacha20poly1305_ietf_decrypt( 35 | _out, 36 | null, 37 | nsec ? heap.set(nsec) : null, 38 | heap.set(c), 39 | c.length, 40 | ad ? heap.set(ad) : null, 41 | ad ? ad.length : null, 42 | heap.set(nonce), 43 | heap.set(key) 44 | ) 45 | 46 | heap.copy(out, _out, messageLength) 47 | heap.release() 48 | return messageLength 49 | } 50 | 51 | sodiumJS.crypto_aead_xchacha20poly1305_ietf_encrypt = function (out, m, ad, nsec, nonce, key) { 52 | const cipherLength = m.length + sodiumJS.crypto_aead_xchacha20poly1305_ietf_ABYTES 53 | const _out = heap.alloc(cipherLength) 54 | 55 | sodiumWasm.crypto_aead_xchacha20poly1305_ietf_encrypt( 56 | _out, 57 | null, 58 | heap.set(m), 59 | m.length, 60 | ad ? heap.set(ad) : null, 61 | ad ? ad.length : null, 62 | nsec ? heap.set(nsec) : null, 63 | heap.set(nonce), 64 | heap.set(key) 65 | ) 66 | 67 | heap.copy(out, _out, cipherLength) 68 | heap.release() 69 | return cipherLength 70 | } 71 | 72 | sodiumJS.crypto_aead_xchacha20poly1305_ietf_decrypt = function (out, nsec, c, ad, nonce, key) { 73 | const messageLength = c.length - sodiumJS.crypto_aead_xchacha20poly1305_ietf_ABYTES 74 | const _out = heap.alloc(messageLength) 75 | 76 | sodiumWasm.crypto_aead_xchacha20poly1305_ietf_decrypt( 77 | _out, 78 | null, 79 | nsec ? heap.set(nsec) : null, 80 | heap.set(c), 81 | c.length, 82 | ad ? heap.set(ad) : null, 83 | ad ? ad.length : null, 84 | heap.set(nonce), 85 | heap.set(key) 86 | ) 87 | 88 | heap.copy(out, _out, messageLength) 89 | heap.release() 90 | return messageLength 91 | } 92 | 93 | sodiumJS.crypto_kx_keypair = function (pk, sk) { 94 | const _pk = heap.alloc(pk.length) 95 | const _sk = heap.alloc(pk.length) 96 | 97 | sodiumWasm.crypto_kx_keypair( 98 | _pk, 99 | _sk 100 | ) 101 | 102 | heap.copy(pk, _pk, pk.length) 103 | heap.copy(sk, _sk, sk.length) 104 | heap.release() 105 | } 106 | 107 | sodiumJS.crypto_kx_seed_keypair = function (pk, sk, seed) { 108 | const _pk = heap.alloc(pk.length) 109 | const _sk = heap.alloc(pk.length) 110 | 111 | sodiumWasm.crypto_kx_seed_keypair( 112 | _pk, 113 | _sk, 114 | heap.set(seed) 115 | ) 116 | 117 | heap.copy(pk, _pk, pk.length) 118 | heap.copy(sk, _sk, sk.length) 119 | heap.release() 120 | } 121 | 122 | sodiumJS.crypto_kx_client_session_keys = function (clientRx, clientTx, clientPk, clientSk, serverPk) { 123 | const _clientRx = heap.alloc(clientRx.length) 124 | const _clientTx = heap.alloc(clientTx.length) 125 | 126 | sodiumWasm.crypto_kx_client_session_keys( 127 | _clientRx, 128 | _clientTx, 129 | heap.set(clientPk), 130 | heap.set(clientSk), 131 | heap.set(serverPk) 132 | ) 133 | 134 | heap.copy(clientRx, _clientRx, clientRx.length) 135 | heap.copy(clientTx, _clientTx, clientTx.length) 136 | heap.release() 137 | } 138 | 139 | sodiumJS.crypto_kx_server_session_keys = function (serverRx, serverTx, serverPk, serverSk, clientPk) { 140 | const _serverRx = heap.alloc(serverRx.length) 141 | const _serverTx = heap.alloc(serverTx.length) 142 | 143 | sodiumWasm.crypto_kx_server_session_keys( 144 | _serverRx, 145 | _serverTx, 146 | heap.set(serverPk), 147 | heap.set(serverSk), 148 | heap.set(clientPk) 149 | ) 150 | 151 | heap.copy(serverRx, _serverRx, serverRx.length) 152 | heap.copy(serverTx, _serverTx, serverTx.length) 153 | heap.release() 154 | } 155 | 156 | return sodiumJS 157 | } 158 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | const sodiumJS = require('sodium-javascript') 3 | const extend = require('./extend') 4 | 5 | module.exports = extend(sodiumJS) 6 | -------------------------------------------------------------------------------- /lib/create-import.js: -------------------------------------------------------------------------------- 1 | const loadSync = require('./load-sync') 2 | 3 | module.exports = (sodiumJS, heap) => { 4 | const blakeStates = new Map() 5 | 6 | const bindingJS = loadSync(Buffer.from(require('../build/binding-js'), 'base64'), { 7 | 'sodium-js': { 8 | crypto_generichash (out, outlen, inn, innlen, key, keylen) { 9 | let keyBuffer 10 | if (keylen !== 0) { 11 | keyBuffer = heap.slice(key, keylen) 12 | } 13 | sodiumJS.crypto_generichash( 14 | heap.slice(out, outlen), 15 | heap.slice(inn, innlen), 16 | keyBuffer 17 | ) 18 | return 0 19 | }, 20 | crypto_generichash_update (state, key, keylen) { 21 | blakeStates.get(state).update(heap.slice(key, keylen)) 22 | return 0 23 | } 24 | } 25 | }) 26 | 27 | return { 28 | env: { 29 | memory: heap.memory, 30 | crypto_verify_16 (x, y) { 31 | const n = 16 32 | const buf = heap.buffer 33 | let i; let d = 0 34 | for (i = 0; i < n; i++) d |= buf[x + i] ^ buf[y + i] 35 | return (1 & ((d - 1) >>> 8)) - 1 36 | }, 37 | sodium_misuse () { 38 | console.error('sodium_misuse') 39 | }, 40 | sodium_memzero (address, length) { 41 | const buffer = heap.slice(address, length) 42 | for (let i = 0; i < buffer.length; i++) { 43 | buffer[i] = 0 44 | } 45 | }, 46 | randombytes_buf (address, length) { 47 | const buffer = heap.slice(address, length) 48 | sodiumJS.randombytes_buf(buffer) 49 | }, 50 | crypto_scalarmult (q, n, p) { 51 | return sodiumJS.crypto_scalarmult( 52 | heap.slice(q, sodiumJS.crypto_scalarmult_BYTES), 53 | heap.slice(n, sodiumJS.crypto_scalarmult_SCALARBYTES), 54 | heap.slice(p, sodiumJS.crypto_scalarmult_BYTES) 55 | ) 56 | }, 57 | crypto_scalarmult_base (q, n) { 58 | return sodiumJS.crypto_scalarmult_base( 59 | heap.slice(q, sodiumJS.crypto_scalarmult_BYTES), 60 | heap.slice(n, sodiumJS.crypto_scalarmult_SCALARBYTES) 61 | ) 62 | }, 63 | crypto_generichash_init (state, key, keylen, outlen) { 64 | let keyBuffer 65 | if (keylen !== 0) { 66 | keyBuffer = heap.slice(key, keylen) 67 | } 68 | blakeStates.set(state, sodiumJS.crypto_generichash_instance(keyBuffer, outlen)) 69 | return 0 70 | }, 71 | crypto_generichash_final (state, out, outlen) { 72 | blakeStates.get(state).final(heap.slice(out, outlen)) 73 | blakeStates.delete(state) 74 | return 0 75 | }, 76 | 77 | // BINDING-JS for i64 types 78 | // the @assemblyscript/loader override the original methods (we don't want to use those here) 79 | crypto_generichash: bindingJS.crypto_generichash, 80 | crypto_generichash_update: bindingJS.crypto_generichash_update 81 | }, 82 | wasi_snapshot_preview1: { 83 | proc_exit (code) { 84 | process.exit(code) 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /lib/heap.js: -------------------------------------------------------------------------------- 1 | const INITIAL_INITIAL_MEMORY = 16777216 2 | const WASM_PAGE_SIZE = 65536 3 | const TOTAL_MEMORY = INITIAL_INITIAL_MEMORY / WASM_PAGE_SIZE 4 | 5 | module.exports = class Heap { 6 | constructor () { 7 | this.memory = new WebAssembly.Memory({ 8 | initial: TOTAL_MEMORY 9 | }) 10 | this._toRelease = [] 11 | this._buffer = Buffer.from(this.memory.buffer) 12 | } 13 | 14 | get buffer () { 15 | if (this._buffer.length === 0) { 16 | this._buffer = Buffer.from(this.memory.buffer) 17 | } 18 | return this._buffer 19 | } 20 | 21 | setRuntime (runtime) { 22 | this._runtime = runtime 23 | } 24 | 25 | alloc (length) { 26 | const address = this._runtime.__retain(this._runtime.__alloc(length)) 27 | this._toRelease.push(address) 28 | return address 29 | } 30 | 31 | set (bytes) { 32 | const address = this.alloc(bytes.length) 33 | this.buffer.set(bytes, address) 34 | return address 35 | } 36 | 37 | slice (start, end) { 38 | return this.buffer.slice(start, start + end) 39 | } 40 | 41 | release () { 42 | const toRelease = this._toRelease 43 | const len = toRelease.length 44 | for (let i = 0; i < len; i++) { 45 | this._runtime.__release(toRelease[i]) 46 | } 47 | this._toRelease = [] 48 | } 49 | 50 | copy (to, address, len) { 51 | for (let i = 0; i < len; i++) { 52 | to[i] = this.buffer[address + i] 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/load-sodium-wasm.js: -------------------------------------------------------------------------------- 1 | const modules = require('../sodium-modules') 2 | const createImport = require('./create-import') 3 | const loadSync = require('./load-sync') 4 | 5 | const binaries = { 6 | core_hchacha20: Buffer.from(require('../build/core_hchacha20'), 'base64'), 7 | stream_chacha20: Buffer.from(require('../build/stream_chacha20'), 'base64'), 8 | onetimeauth_poly1305: Buffer.from(require('../build/onetimeauth_poly1305'), 'base64'), 9 | aead_chacha20poly1305: Buffer.from(require('../build/aead_chacha20poly1305'), 'base64'), 10 | aead_xchacha20poly1305: Buffer.from(require('../build/aead_xchacha20poly1305'), 'base64'), 11 | crypto_kx: Buffer.from(require('../build/crypto_kx'), 'base64') 12 | } 13 | 14 | function loadSodiumWasm (sodiumJS, heap) { 15 | const sodium = { 16 | _original: {} 17 | } 18 | 19 | const importObj = createImport(sodiumJS, heap) 20 | const { env } = importObj 21 | 22 | modules.forEach(({ name, functions = [], constants = {} }) => { 23 | try { 24 | const binary = binaries[name] 25 | // const binary = require('fs').readFileSync(`${__dirname}/../build/${name}.wasm`) 26 | const wasmModule = loadSync(binary, importObj) 27 | 28 | functions.forEach(fn => { 29 | sodium[fn] = wasmModule[fn] 30 | env[fn] = wasmModule[fn] 31 | sodium._original[fn] = wasmModule[fn] 32 | }) 33 | 34 | Object.keys(constants).forEach(constant => { 35 | sodium[constants[constant]] = wasmModule[constant]() 36 | sodiumJS[constants[constant]] = wasmModule[constant]() 37 | env[constant] = wasmModule[constant] 38 | }) 39 | } catch (err) { 40 | throw new Error(`Error loading: ${name} - ${err.message}`) 41 | } 42 | }) 43 | 44 | sodiumJS.sodium_memzero = (buffer) => { 45 | if (!(buffer instanceof Uint8Array)) { 46 | throw new Error('Only Uint8Array instances accepted') 47 | } 48 | for (let i = 0; i < buffer.length; i++) { 49 | buffer[i] = 0 50 | } 51 | } 52 | 53 | sodiumJS.sodium_memcmp = (b1, b2) => { 54 | if (!(b1 instanceof Uint8Array && b2 instanceof Uint8Array)) { 55 | throw new Error('Only Uint8Array instances can be compared') 56 | } 57 | if (b1.length !== b2.length) { 58 | throw new Error( 59 | 'Only instances of identical length can be compared' 60 | ) 61 | } 62 | for (var d = 0 | 0, i = 0 | 0, j = b1.length; i < j; i++) { 63 | d |= b1[i] ^ b2[i] 64 | } 65 | return d === 0 66 | } 67 | 68 | sodiumJS.sodium_is_zero = (buffer) => { 69 | if (!(buffer instanceof Uint8Array)) { 70 | throw new TypeError('Only Uint8Array instances can be checked') 71 | } 72 | var d = 0 | 0 73 | for (var i = 0 | 0, j = buffer.length; i < j; i++) { 74 | d |= buffer[i] 75 | } 76 | return d === 0 77 | } 78 | 79 | sodiumJS.sodium_increment = (buffer) => { 80 | if (!(buffer instanceof Uint8Array)) { 81 | throw new TypeError('Only Uint8Array instances can be incremented') 82 | } 83 | var c = 1 << 8 84 | for (var i = 0 | 0, j = buffer.length; i < j; i++) { 85 | c >>= 8 86 | c += buffer[i] 87 | buffer[i] = c & 0xff 88 | } 89 | } 90 | 91 | sodiumJS.sodium_free = () => {} // noop 92 | sodiumJS.crypto_stream_xor_STATEBYTES = 136 93 | 94 | // some functions in C expect unsigned long long types (u64 in wasm) 95 | // because js cannot understand that type we provide bindings to cast u64 into u32 96 | const bindingC = loadSync(Buffer.from(require('../build/binding-c'), 'base64'), { 97 | env: { 98 | memory: heap.memory, 99 | abort: (msg, file, line, colm) => { 100 | throw new Error(`bindingC abort line=${line} colm=${colm}`) 101 | } 102 | }, 103 | 'sodium-c': sodium._original 104 | }) 105 | 106 | heap.setRuntime(bindingC) 107 | 108 | sodium.crypto_aead_chacha20poly1305_ietf_encrypt = bindingC.crypto_aead_chacha20poly1305_ietf_encrypt 109 | sodium.crypto_aead_chacha20poly1305_ietf_decrypt = bindingC.crypto_aead_chacha20poly1305_ietf_decrypt 110 | sodium.crypto_aead_xchacha20poly1305_ietf_encrypt = bindingC.crypto_aead_xchacha20poly1305_ietf_encrypt 111 | sodium.crypto_aead_xchacha20poly1305_ietf_decrypt = bindingC.crypto_aead_xchacha20poly1305_ietf_decrypt 112 | 113 | return sodium 114 | } 115 | 116 | module.exports = loadSodiumWasm 117 | -------------------------------------------------------------------------------- /lib/load-sync.js: -------------------------------------------------------------------------------- 1 | module.exports = function loadSync (binary, importObj) { 2 | const instance = new WebAssembly.Instance(new WebAssembly.Module(binary), importObj) 3 | return instance.exports 4 | } 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@geut/sodium-javascript-plus", 3 | "version": "0.0.6", 4 | "description": "sodium-javascript with xchacha20 and kx support", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js", 8 | "build": "npm run clean:wasm && npm run build:sodium && npm run build:binding", 9 | "build:sodium": "node scripts/build-sodium.js", 10 | "build:binding": "npm run build:bindingc && npm run build:bindingjs && node scripts/binding-to-base64.js", 11 | "build:bindingc": "npm run asbuild -- -b build/binding-c.wasm assembly/binding-c.ts --importMemory --memoryBase 5246512", 12 | "build:bindingjs": "npm run asbuild -- -b build/binding-js.wasm assembly/binding-js.ts --runtime none", 13 | "asbuild": "asc --validate --optimize", 14 | "test": "jest --passWithNoTests", 15 | "posttest": "npm run lint", 16 | "lint": "standard \"index.js\" \"lib/*.js\" \"tests/*.js\"", 17 | "version": "chan release --allow-yanked ${npm_package_version} && git add .", 18 | "prepublishOnly": "npm run build && npm run test", 19 | "clean": "npm run clean:wasm && npm run clean:sodium", 20 | "clean:wasm": "del-cli build/*", 21 | "clean:sodium": "del-cli libsodium/libsodium-js" 22 | }, 23 | "dependencies": { 24 | "sodium-javascript": "^0.5.6" 25 | }, 26 | "devDependencies": { 27 | "@geut/chan": "^2.0.0", 28 | "assemblyscript": "^0.9.4", 29 | "binaryen": "^91.0.0", 30 | "del-cli": "^3.0.0", 31 | "execa": "^4.0.0", 32 | "jest": "^25.2.6", 33 | "libsodium-wrappers": "^0.7.6", 34 | "nanobench": "^2.1.1", 35 | "sodium-native": "^3.0.1", 36 | "standard": "^14.3.3" 37 | }, 38 | "jest": { 39 | "testMatch": [ 40 | "**/tests/**/*.test.js" 41 | ] 42 | }, 43 | "standard": { 44 | "env": [ 45 | "jest", 46 | "node", 47 | "browser" 48 | ] 49 | }, 50 | "repository": { 51 | "type": "git", 52 | "url": "git+https://github.com/geut/sodium-javascript-plus.git" 53 | }, 54 | "keywords": [ 55 | "sodium", 56 | "wasm", 57 | "xchacha20", 58 | "kx" 59 | ], 60 | "author": { 61 | "name": "GEUT", 62 | "email": "contact@geutstudio.com" 63 | }, 64 | "license": "MIT", 65 | "bugs": { 66 | "url": "https://github.com/geut/sodium-javascript-plus/issues" 67 | }, 68 | "homepage": "https://github.com/geut/sodium-javascript-plus#readme", 69 | "publishConfig": { 70 | "access": "public" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /scripts/binding-to-base64.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const path = require('path') 3 | 4 | const BUILD_PATH = path.join(path.resolve(__dirname, '..'), 'build') 5 | 6 | const bindingC = fs.readFileSync(path.join(BUILD_PATH, 'binding-c.wasm')) 7 | const bindingJS = fs.readFileSync(path.join(BUILD_PATH, 'binding-js.wasm')) 8 | 9 | fs.writeFileSync(path.join(BUILD_PATH, 'binding-c.js'), `module.exports = '${bindingC.toString('base64')}'`) 10 | fs.writeFileSync(path.join(BUILD_PATH, 'binding-js.js'), `module.exports = '${bindingJS.toString('base64')}'`) 11 | -------------------------------------------------------------------------------- /scripts/build-sodium.js: -------------------------------------------------------------------------------- 1 | const { promises: fs } = require('fs') 2 | const path = require('path') 3 | const execa = require('execa') 4 | const binaryen = require('binaryen') 5 | 6 | const ROOT_PATH = path.resolve(__dirname, '..') 7 | const LIBSODIUM_PATH = path.resolve(ROOT_PATH, 'libsodium') 8 | const LIBSODIUM_JS_PATH = path.join(LIBSODIUM_PATH, 'libsodium-js') 9 | const LIBSODIUM_SOURCE_PATH = path.join(LIBSODIUM_PATH, 'src', 'libsodium') 10 | const BUILD_PATH = path.join(ROOT_PATH, 'build') 11 | const DEBUG = process.argv.includes('--debug') 12 | 13 | // MEMORY USAGE 14 | const STACK_SIZE = 1 * 1024 * 1024 // this library is not using the stack memory implementation of emscripten 15 | 16 | const DEFAULT_LDFLAGS = [ 17 | 'RESERVED_FUNCTION_POINTERS=8', 18 | 'ASSERTIONS=0', 19 | 'AGGRESSIVE_VARIABLE_ELIMINATION=1', 20 | 'ALIASING_FUNCTION_POINTERS=1', 21 | 'DISABLE_EXCEPTION_CATCHING=1', 22 | 'ERROR_ON_UNDEFINED_SYMBOLS=0', 23 | `TOTAL_STACK=${STACK_SIZE}`, 24 | 'ALLOW_MEMORY_GROWTH=1' 25 | ] 26 | 27 | const modules = require('../sodium-modules') 28 | 29 | if (DEBUG) { 30 | binaryen.setOptimizeLevel(0) 31 | binaryen.setShrinkLevel(0) 32 | binaryen.setDebugInfo(true) 33 | } else { 34 | binaryen.setOptimizeLevel(3) 35 | binaryen.setShrinkLevel(2) 36 | } 37 | 38 | ;(async () => { 39 | if (!await exists(LIBSODIUM_JS_PATH)) { 40 | await buildSodium() 41 | } 42 | 43 | // const toCompile = [ 44 | // compileToWASM({ 45 | // core: true, 46 | // to: 'all.wasm', 47 | // functions: [ 48 | // 'crypto_stream_chacha20_ietf_ext', 49 | // 'crypto_stream_chacha20_ietf_ext_xor_ic', 50 | // 'crypto_core_hchacha20', 51 | // 'crypto_onetimeauth_poly1305_final', 52 | // 'crypto_onetimeauth_poly1305_init', 53 | // 'crypto_onetimeauth_poly1305_update', 54 | // 'crypto_aead_xchacha20poly1305_ietf_decrypt', 55 | // 'crypto_aead_xchacha20poly1305_ietf_encrypt', 56 | // 'crypto_aead_xchacha20poly1305_ietf_keybytes', 57 | // 'crypto_aead_xchacha20poly1305_ietf_npubbytes', 58 | // 'crypto_aead_xchacha20poly1305_ietf_nsecbytes', 59 | // 'crypto_aead_xchacha20poly1305_ietf_abytes' 60 | // ] 61 | // }) 62 | // ] 63 | 64 | let memoryBase = 1024 65 | 66 | for (const cryptoModule of modules) { 67 | memoryBase = await compileToWASM(memoryBase, cryptoModule) 68 | } 69 | 70 | console.log(`\nMemory base: ${memoryBase}`) 71 | })() 72 | 73 | const execaOpts = { shell: true, cwd: LIBSODIUM_PATH, stdout: process.stdout, stderr: process.stderr } 74 | 75 | async function exists (path) { 76 | try { 77 | await fs.access(path) 78 | return true 79 | } catch (err) { 80 | return false 81 | } 82 | } 83 | 84 | async function buildSodium () { 85 | if (!await exists(path.join(LIBSODIUM_PATH, 'configure'))) { 86 | await execa('sh', ['autogen.sh'], execaOpts) 87 | } 88 | 89 | await execa('emconfigure', [ 90 | './configure', 91 | '--enable-minimal', 92 | '--disable-shared', 93 | `--prefix=${LIBSODIUM_JS_PATH}`, 94 | '--without-pthreads', 95 | '--disable-ssp', 96 | '--disable-asm', 97 | '--disable-pie', 98 | 'CFLAGS=-Os' 99 | ], execaOpts) 100 | await execa('emmake', ['make', 'clean'], execaOpts) 101 | await execa('emmake', ['make', '-j4', 'install'], execaOpts) 102 | } 103 | 104 | async function compileToWASM (memoryBase, { lib, name, functions = [], constants = {} }) { 105 | console.log(`\n- compiling ${name}\n`) 106 | 107 | const binaryPath = path.join(BUILD_PATH, `${name}.wasm`) 108 | const base64Path = path.join(BUILD_PATH, `${name}.js`) 109 | 110 | const EXPORTED_FUNCTIONS = functions.concat(Object.keys(constants)).map(f => `"_${f}"`).join(',') 111 | 112 | const args = [ 113 | '-s GLOBAL_BASE=' + memoryBase, 114 | `-s EXPORTED_FUNCTIONS='[${EXPORTED_FUNCTIONS}]'`, 115 | `-o ${binaryPath}` 116 | ].reduce((prev, curr) => { 117 | return [...prev, ...curr.split(' ')] 118 | }, []) 119 | 120 | DEFAULT_LDFLAGS.forEach(flag => { 121 | args.push('-s') 122 | args.push(flag) 123 | }) 124 | 125 | if (DEBUG) { 126 | args.push('-g4') 127 | args.push('-O1') 128 | } else { 129 | args.push('--llvm-lto') 130 | args.push('1') 131 | args.push('-Oz') 132 | } 133 | 134 | await execa('emcc', [ 135 | ...args, 136 | ...lib.map(file => path.join(LIBSODIUM_SOURCE_PATH, file)) 137 | ], execaOpts) 138 | 139 | const wasmModule = binaryen.readBinary(await fs.readFile(binaryPath)) 140 | 141 | memoryBase = updateMemory(memoryBase, wasmModule) 142 | 143 | const binary = wasmModule.emitBinary() 144 | 145 | await fs.writeFile(binaryPath, binary) 146 | await fs.writeFile(base64Path, `module.exports = '${Buffer.from(wasmModule.emitBinary()).toString('base64')}'`) 147 | 148 | if (DEBUG) { 149 | await fs.writeFile(path.join(BUILD_PATH, `${name}.wat`), wasmModule.emitText()) 150 | } 151 | 152 | return memoryBase 153 | } 154 | 155 | // This function is the only way I find to import the memory and get __head_base from a STANDALONE_WASM file compiled by emscripten 156 | async function updateMemory (memoryBase, wasmModule) { 157 | wasmModule.addMemoryImport('mem', 'env', 'memory') 158 | wasmModule.removeExport('memory') 159 | 160 | let offset = memoryBase 161 | for (let i = 0; i < wasmModule.getNumMemorySegments(); i++) { 162 | offset += wasmModule.getMemorySegmentInfoByIndex(i).offset - offset 163 | } 164 | 165 | wasmModule.optimize() 166 | 167 | return offset + STACK_SIZE 168 | } 169 | -------------------------------------------------------------------------------- /sodium-modules.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "lib": [ 4 | "crypto_onetimeauth/poly1305/libsodium_la-onetimeauth_poly1305.o", 5 | "crypto_onetimeauth/poly1305/donna/libsodium_la-poly1305_donna.o" 6 | ], 7 | "name": "onetimeauth_poly1305", 8 | "functions": [ 9 | "crypto_onetimeauth_poly1305_final", 10 | "crypto_onetimeauth_poly1305_init", 11 | "crypto_onetimeauth_poly1305_update" 12 | ] 13 | }, 14 | { 15 | "lib": [ 16 | "crypto_core/hchacha20/libsodium_la-core_hchacha20.o" 17 | ], 18 | "name": "core_hchacha20", 19 | "functions": [ 20 | "crypto_core_hchacha20" 21 | ] 22 | }, 23 | { 24 | "lib": [ 25 | "crypto_stream/chacha20/libsodium_la-stream_chacha20.o", 26 | "crypto_stream/chacha20/ref/libsodium_la-chacha20_ref.o" 27 | ], 28 | "name": "stream_chacha20", 29 | "functions": [ 30 | "crypto_stream_chacha20_ietf", 31 | "crypto_stream_chacha20_ietf_ext", 32 | "crypto_stream_chacha20_ietf_ext_xor_ic", 33 | "crypto_stream_chacha20_ietf_xor_ic" 34 | ] 35 | }, 36 | { 37 | "lib": [ 38 | "crypto_aead/chacha20poly1305/sodium/libsodium_la-aead_chacha20poly1305.o" 39 | ], 40 | "name": "aead_chacha20poly1305", 41 | "functions": [ 42 | "crypto_aead_chacha20poly1305_ietf_decrypt", 43 | "crypto_aead_chacha20poly1305_ietf_encrypt" 44 | ], 45 | "constants": { 46 | "crypto_aead_chacha20poly1305_ietf_keybytes": "crypto_aead_chacha20poly1305_ietf_KEYBYTES", 47 | "crypto_aead_chacha20poly1305_ietf_npubbytes": "crypto_aead_chacha20poly1305_ietf_NPUBBYTES", 48 | "crypto_aead_chacha20poly1305_ietf_nsecbytes": "crypto_aead_chacha20poly1305_ietf_NSECBYTES", 49 | "crypto_aead_chacha20poly1305_ietf_abytes": "crypto_aead_chacha20poly1305_ietf_ABYTES" 50 | } 51 | }, 52 | { 53 | "lib": [ 54 | "crypto_aead/xchacha20poly1305/sodium/libsodium_la-aead_xchacha20poly1305.o" 55 | ], 56 | "name": "aead_xchacha20poly1305", 57 | "functions": [ 58 | "crypto_aead_xchacha20poly1305_ietf_decrypt", 59 | "crypto_aead_xchacha20poly1305_ietf_encrypt" 60 | ], 61 | "constants": { 62 | "crypto_aead_xchacha20poly1305_ietf_keybytes": "crypto_aead_xchacha20poly1305_ietf_KEYBYTES", 63 | "crypto_aead_xchacha20poly1305_ietf_npubbytes": "crypto_aead_xchacha20poly1305_ietf_NPUBBYTES", 64 | "crypto_aead_xchacha20poly1305_ietf_nsecbytes": "crypto_aead_xchacha20poly1305_ietf_NSECBYTES", 65 | "crypto_aead_xchacha20poly1305_ietf_abytes": "crypto_aead_xchacha20poly1305_ietf_ABYTES" 66 | } 67 | }, 68 | { 69 | "lib": [ 70 | "crypto_kx/libsodium_la-crypto_kx.o" 71 | ], 72 | "name": "crypto_kx", 73 | "functions": [ 74 | "crypto_kx_keypair", 75 | "crypto_kx_seed_keypair", 76 | "crypto_kx_client_session_keys", 77 | "crypto_kx_server_session_keys" 78 | ], 79 | "constants": { 80 | "crypto_kx_sessionkeybytes": "crypto_kx_SESSIONKEYBYTES", 81 | "crypto_kx_publickeybytes": "crypto_kx_PUBLICKEYBYTES", 82 | "crypto_kx_secretkeybytes": "crypto_kx_SECRETKEYBYTES", 83 | "crypto_kx_seedbytes": "crypto_kx_SEEDBYTES" 84 | } 85 | } 86 | ] 87 | -------------------------------------------------------------------------------- /tests/index.test.js: -------------------------------------------------------------------------------- 1 | const sodium = require('..') 2 | 3 | test('aead_chacha20poly1305', () => { 4 | const message = Buffer.from( 5 | '4c616469657320616e642047656e746c656d656e206f662074686520636c6173' + 6 | '73206f66202739393a204966204920636f756c64206f6666657220796f75206f' + 7 | '6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73' + 8 | '637265656e20776f756c642062652069742e', 9 | 'hex' 10 | ) 11 | const ad = Buffer.from('50515253c0c1c2c3c4c5c6c7', 'hex') 12 | const nonce = Buffer.from('404142434445464748494a4b4c4d4e4f5051525354555657', 'hex') 13 | const key = Buffer.from('808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f', 'hex') 14 | const cipher = Buffer.alloc(message.length + sodium.crypto_aead_chacha20poly1305_ietf_ABYTES) 15 | 16 | sodium.crypto_aead_chacha20poly1305_ietf_encrypt( 17 | cipher, 18 | message, 19 | ad, 20 | null, 21 | nonce, 22 | key 23 | ) 24 | 25 | const decrypted = Buffer.alloc(message.length) 26 | 27 | sodium.crypto_aead_chacha20poly1305_ietf_decrypt( 28 | decrypted, 29 | null, 30 | cipher, 31 | ad, 32 | nonce, 33 | key 34 | ) 35 | 36 | expect(message.equals(decrypted)).toBe(true) 37 | }) 38 | 39 | test('aead_xchacha20poly1305', () => { 40 | const message = Buffer.from( 41 | '4c616469657320616e642047656e746c656d656e206f662074686520636c6173' + 42 | '73206f66202739393a204966204920636f756c64206f6666657220796f75206f' + 43 | '6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73' + 44 | '637265656e20776f756c642062652069742e', 45 | 'hex' 46 | ) 47 | const ad = Buffer.from('50515253c0c1c2c3c4c5c6c7', 'hex') 48 | const nonce = Buffer.from('404142434445464748494a4b4c4d4e4f5051525354555657', 'hex') 49 | const key = Buffer.from('808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f', 'hex') 50 | const cipher = Buffer.alloc(message.length + sodium.crypto_aead_xchacha20poly1305_ietf_ABYTES) 51 | 52 | sodium.crypto_aead_xchacha20poly1305_ietf_encrypt( 53 | cipher, 54 | message, 55 | ad, 56 | null, 57 | nonce, 58 | key 59 | ) 60 | 61 | expect(cipher.toString('hex') === 'bd6d179d3e83d43b9576579493c0e939572a1700252bfaccbe' + 62 | 'd2902c21396cbb731c7f1b0b4aa6440bf3a82f4eda7e39ae64c6708c54c216cb96b72e1213b4522f8c9b' + 63 | 'a40db5d945b11b69b982c1bb9e3f3fac2bc369488f76b2383565d3fff921f9664c97637da9768812f615' + 64 | 'c68b13b52ec0875924c1c7987947deafd8780acf49').toBe(true) 65 | 66 | const decrypted = Buffer.alloc(message.length) 67 | 68 | sodium.crypto_aead_xchacha20poly1305_ietf_decrypt( 69 | decrypted, 70 | null, 71 | cipher, 72 | ad, 73 | nonce, 74 | key 75 | ) 76 | 77 | expect(message.equals(decrypted)).toBe(true) 78 | }) 79 | 80 | test('crypto_kx', () => { 81 | const clientPk = Buffer.alloc(sodium.crypto_kx_PUBLICKEYBYTES) 82 | const clientSk = Buffer.alloc(sodium.crypto_kx_SECRETKEYBYTES) 83 | const serverPk = Buffer.alloc(sodium.crypto_kx_PUBLICKEYBYTES) 84 | const serverSk = Buffer.alloc(sodium.crypto_kx_SECRETKEYBYTES) 85 | 86 | const serverRx = Buffer.alloc(sodium.crypto_kx_SESSIONKEYBYTES) 87 | const serverTx = Buffer.alloc(sodium.crypto_kx_SESSIONKEYBYTES) 88 | 89 | const clientRx = Buffer.alloc(sodium.crypto_kx_SESSIONKEYBYTES) 90 | const clientTx = Buffer.alloc(sodium.crypto_kx_SESSIONKEYBYTES) 91 | 92 | sodium.crypto_kx_keypair(serverPk, serverSk) 93 | sodium.crypto_kx_keypair(clientPk, clientSk) 94 | 95 | sodium.crypto_kx_client_session_keys(clientRx, clientTx, clientPk, clientSk, serverPk) 96 | sodium.crypto_kx_server_session_keys(serverRx, serverTx, serverPk, serverSk, clientPk) 97 | 98 | expect(clientRx.equals(serverTx)).toBe(true) 99 | expect(clientTx.equals(serverRx)).toBe(true) 100 | 101 | const pk = Buffer.alloc(sodium.crypto_kx_PUBLICKEYBYTES) 102 | const sk = Buffer.alloc(sodium.crypto_kx_SECRETKEYBYTES) 103 | const seed = Buffer.alloc(sodium.crypto_kx_SEEDBYTES, 'lo') 104 | 105 | sodium.crypto_kx_seed_keypair(pk, sk, seed) 106 | 107 | const eSk = '768475983073421d5b1676c4aabb24fdf17c3a5f19e6e9e9cdefbfeb45ceb153' 108 | const ePk = '0cd703bbd6b1d46dc431a1fc4f1f7724c64b1d4c471e8c17de4966c9e15bf85e' 109 | 110 | expect(pk.toString('hex')).toBe(ePk) 111 | expect(sk.toString('hex')).toBe(eSk) 112 | }) 113 | --------------------------------------------------------------------------------