From b6fe5fde1cedc52133b21a6d4479ac1c0cb55e1f Mon Sep 17 00:00:00 2001 From: Theron Spiegl Date: Sun, 22 Nov 2020 21:30:18 -0600 Subject: [PATCH] working on understanding poly1305 initialization --- crypto_secretstream.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crypto_secretstream.js b/crypto_secretstream.js index b51165d..7b034d2 100644 --- a/crypto_secretstream.js +++ b/crypto_secretstream.js @@ -1,7 +1,7 @@ /* eslint-disable camelcase */ const { assert } = require('nanoassert') const { randombytes_buf } = require('./randombytes') -const { crypto_stream_chacha20_ietf_KEYBYTES, crypto_stream_chacha20_ietf_NONCEBYTES, crypto_stream_chacha20_ietf_xor } = require('./crypto_stream_chacha20') +const { crypto_stream_chacha20_ietf, crypto_stream_chacha20_ietf_xor, crypto_stream_chacha20_ietf_KEYBYTES, crypto_stream_chacha20_ietf_NONCEBYTES, } = require('./crypto_stream_chacha20') const { crypto_core_hchacha20, crypto_core_hchacha20_INPUTBYTES } = require('./crypto_core_hchacha20') const crypto_secretstream_xchacha20poly1305_COUNTERBYTES = 4 @@ -15,6 +15,17 @@ const crypto_secretstream_xchacha20poly1305_KEYBYTES = crypto_aead_xchacha20poly const crypto_aead_xchacha20poly1305_ietf_NPUBBYTES = 24 const crypto_secretstream_xchacha20poly1305_HEADERBYTES = crypto_aead_xchacha20poly1305_ietf_NPUBBYTES +// #define crypto_aead_xchacha20poly1305_ietf_ABYTES 16U +const crypto_aead_xchacha20poly1305_ietf_ABYTES = 16 +// #define crypto_secretstream_xchacha20poly1305_ABYTES \ +// (1U + crypto_aead_xchacha20poly1305_ietf_ABYTES) +const crypto_secretstream_xchacha20poly1305_ABYTES = 1 + crypto_aead_xchacha20poly1305_ietf_ABYTES + +// #define crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX \ +// SODIUM_MIN(SODIUM_SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES, \ +// (64ULL * ((1ULL << 32) - 2ULL))) +const crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX = Number.MAX_SAFE_INTEGER + // #define STATE_COUNTER(STATE) ((STATE)->nonce) // #define STATE_INONCE(STATE) ((STATE)->nonce + \ // crypto_secretstream_xchacha20poly1305_COUNTERBYTES) @@ -248,6 +259,19 @@ function crypto_secretstream_xchacha20poly1305_rekey (state) { // } // return 0; // } +function crypto_secretstream_xchacha20poly1305_push (state, out, m, ad, tag) { + // assert(out instanceof Uint8Array && out.length === outlen, "out is not byte array of length outlen") + // assert(m instanceof Uint8Array && m.length === mlen, "m is not byte array of length mlen") + // assert(ad instanceof Uint8Array && ad.length === adlen, "ad is not byte array of length adlen") + + const block = new Uint8Array(64) + const slen = new Uint8Array(8) + + assert(crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX + <= crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX) + + crypto_stream_chacha20_ietf(block, state.nonce, state.k) +} // int // crypto_secretstream_xchacha20poly1305_pull