siphash24-stream
SipHash24 sign and verify streams powered by a seedable keystream.
Get it!
npm install --save siphash24-stream
Usage
Create both signing and verifying streams by supplying a variable-length symmetric key that is used for seeding an internal keystream.
Run node ./usage.js
:
var crypto =var stream =var sip =var DELIMITER = Buffervar NSA = Buffervar shared = '419' // shared secret, symmetric keyvar opts = algo: 'alea' delimiter: DELIMITER // default optionsvar alice = sip // alice signsvar bob = sip // bob verifiesvar thru = // some sort of socket{console}alice // alice writes, bob readsthrubobbobalicethru // being interceptedalice
Note that only legit msg packs pass thru the verifying end, in this case bob
.
API
var sign = sip.createSigningStream(init[, opts])
Create a transform stream that signs all its throughput with a SipHash24 mac. init
is the seed for a random byte generator used as key stream.
Options default to:
algo: 'alea'delimiter: Buffer
opts.algo
indicates the algorithm to use for the internal random number generator. Check out seedrandom
for a list of supported algorithms. opts.delimiter
is the message delimiter, must be a buffer.
var verify = sip.createVerifyingStream(init[, opts])
Create a transform stream that verifies all its throughput against a SipHash24 mac. Bad chunks are rejected and not passed on, not pushed any further, but emitted with the dropping
event.
var { sign, verify } = sip.createSipHash24Streams(init[, opts])
Create a SipHash24 sign and verify stream duplet.
verify.on('dropping', ondropping)
Emitted with every chunk that will not be pushed further. Use this if you wish to check dropouts. Calling back like ondropping(chunk)
.