crypto_stream: signature change needed to modularise

This commit is contained in:
Christophe Diederichs 2020-05-04 18:47:52 +02:00
parent 51f8fbc2d3
commit 942c2a6db0
2 changed files with 7 additions and 11 deletions

View File

@ -4,14 +4,15 @@ exports.crypto_stream_KEYBYTES = 32
exports.crypto_stream_NONCEBYTES = 24 exports.crypto_stream_NONCEBYTES = 24
exports.crypto_stream_PRIMITIVE = 'xsalsa20' exports.crypto_stream_PRIMITIVE = 'xsalsa20'
exports.crypto_stream = function (out, nonce, key) { exports.crypto_stream = function (c, cpos, clen, nonce, key) {
out.fill(0) c.fill(0)
exports.crypto_stream_xor(out, out, nonce, key) 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) var xor = xsalsa20(nonce, key)
xor.update(inp, out)
xor.update(m, c)
xor.final() xor.final()
} }

View File

@ -1,11 +1,8 @@
'use strict'; 'use strict';
var xsalsa20 = require('xsalsa20')
// Based on https://github.com/dchest/tweetnacl-js/blob/6dcbcaf5f5cbfd313f2dcfe763db35c828c8ff5b/nacl-fast.js. // Based on https://github.com/dchest/tweetnacl-js/blob/6dcbcaf5f5cbfd313f2dcfe763db35c828c8ff5b/nacl-fast.js.
var sodium = module.exports var sodium = module.exports
var cs = require('./crypto_stream')
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
// Public domain. // Public domain.
@ -1859,9 +1856,7 @@ function cleanup(arr) {
for (var i = 0; i < arr.length; i++) arr[i] = 0; for (var i = 0; i < arr.length; i++) arr[i] = 0;
} }
function check (buf, len) { forward(require('./crypto_stream'))
if (!buf || (len && buf.length < len)) throw new Error('Argument must be a buffer' + (len ? ' of length ' + len : ''))
}
function forward (submodule) { function forward (submodule) {
Object.keys(submodule).forEach(function (prop) { Object.keys(submodule).forEach(function (prop) {