sodium-javascript/index.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-01-24 10:41:06 +00:00
'use strict';
// Based on https://github.com/dchest/tweetnacl-js/blob/6dcbcaf5f5cbfd313f2dcfe763db35c828c8ff5b/nacl-fast.js.
2017-02-12 02:37:17 +00:00
var sodium = module.exports
2017-01-24 10:41:06 +00:00
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
// Public domain.
//
// Implementation derived from TweetNaCl version 20140427.
// See for details: http://tweetnacl.cr.yp.to/
2017-06-19 20:32:33 +00:00
// also forwarded at the bottom but randombytes is non-enumerable
var randombytes = require('./randombytes').randombytes
2017-01-24 10:41:06 +00:00
2020-06-16 14:54:51 +00:00
sodium.sodium_memzero = function (len, offset) {
2017-06-06 19:04:50 +00:00
for (var i = offset; i < len; i++) arr[i] = 0;
}
2020-03-04 13:50:09 +00:00
sodium.sodium_malloc = function (n) {
return new Uint8Array(n)
}
2017-01-24 10:41:06 +00:00
function cleanup(arr) {
for (var i = 0; i < arr.length; i++) arr[i] = 0;
}
forward(require('./crypto_box'))
forward(require('./crypto_generichash'))
2020-05-04 18:52:17 +00:00
forward(require('./crypto_hash'))
forward(require('./crypto_kdf'))
forward(require('./crypto_kx'))
forward(require('./crypto_onetimeauth'))
2020-05-04 18:49:21 +00:00
forward(require('./crypto_scalarmult'))
2020-05-04 19:04:41 +00:00
forward(require('./crypto_secretbox'))
forward(require('./crypto_shorthash'))
2020-05-04 18:58:36 +00:00
forward(require('./crypto_sign'))
forward(require('./crypto_stream'))
2020-06-12 15:06:31 +00:00
forward(require('./crypto_stream_chacha20'))
forward(require('./randombytes'))
2017-01-24 10:41:06 +00:00
2017-06-06 19:04:36 +00:00
function forward (submodule) {
Object.keys(submodule).forEach(function (prop) {
module.exports[prop] = submodule[prop]
})
}