Permalink
Browse files

use xsalsa20 and support crypto_stream_instance

  • Loading branch information...
mafintosh committed Jun 28, 2017
1 parent 0f249a7 commit 6561ff99f1a36eee0e2c15d8e6e1ca73bfa03f32
Showing with 61 additions and 456 deletions.
  1. +33 −0 crypto_stream.js
  2. +24 −448 index.js
  3. +4 −8 package.json
View
@@ -0,0 +1,33 @@
var xsalsa20 = require('xsalsa20')
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_xor = function (out, inp, nonce, key) {
var xor = xsalsa20(nonce, key)
xor.update(inp, out)
xor.final()
}
exports.crypto_stream_xor_instance = function (nonce, key) {
return new XOR(nonce, key)
}
function XOR (nonce, key) {
this._instance = xsalsa20(nonce, key)
}
XOR.prototype.update = function (out, inp) {
this._instance.update(inp, out)
}
XOR.prototype.final = function () {
this._instance.finalize()
this._instance = null
}
Oops, something went wrong.

0 comments on commit 6561ff9

Please sign in to comment.