diff --git a/crypto_stream.js b/crypto_stream.js index a7e11ee..a130dab 100644 --- a/crypto_stream.js +++ b/crypto_stream.js @@ -4,14 +4,15 @@ exports.crypto_stream_KEYBYTES = 32 exports.crypto_stream_NONCEBYTES = 24 exports.crypto_stream_PRIMITIVE = 'xsalsa20' -exports.crypto_stream = function (out, nonce, key) { - out.fill(0) - exports.crypto_stream_xor(out, out, nonce, key) +exports.crypto_stream = function (c, cpos, clen, nonce, key) { + c.fill(0) + exports.crypto_stream_xor(c, 0, c, 0, 0, nonce, key) } -exports.crypto_stream_xor = function (out, inp, nonce, key) { +exports.crypto_stream_xor = function (c, cpos, m, mpos, clen, nonce, key) { var xor = xsalsa20(nonce, key) - xor.update(inp, out) + + xor.update(m, c) xor.final() } diff --git a/index.js b/index.js index c7b26de..785c4fb 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,8 @@ 'use strict'; -var xsalsa20 = require('xsalsa20') - // Based on https://github.com/dchest/tweetnacl-js/blob/6dcbcaf5f5cbfd313f2dcfe763db35c828c8ff5b/nacl-fast.js. var sodium = module.exports -var cs = require('./crypto_stream') // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. // Public domain. @@ -1859,9 +1856,7 @@ function cleanup(arr) { for (var i = 0; i < arr.length; i++) arr[i] = 0; } -function check (buf, len) { - if (!buf || (len && buf.length < len)) throw new Error('Argument must be a buffer' + (len ? ' of length ' + len : '')) -} +forward(require('./crypto_stream')) function forward (submodule) { Object.keys(submodule).forEach(function (prop) {