From b4b58c62a6cd81775009ca09bedee055c92f072e Mon Sep 17 00:00:00 2001 From: Theron Spiegl Date: Sun, 22 Nov 2020 14:55:13 -0600 Subject: [PATCH] lint, typo --- crypto_secretstream.js | 48 ++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/crypto_secretstream.js b/crypto_secretstream.js index 38a70f7..b51165d 100644 --- a/crypto_secretstream.js +++ b/crypto_secretstream.js @@ -112,15 +112,15 @@ function crypto_secretstream_xchacha20poly1305_init_push (state, out, k) { // return 0; // } -function crypto_secretstream_xchacha20poly1305_init_pull(state, _in, k) { +function crypto_secretstream_xchacha20poly1305_init_pull (state, _in, k) { assert(state instanceof crypto_secretstream_xchacha20poly1305_state, 'state not instance of crypto_secretstream_xchacha20poly1305_state') - assert(_in instanceof Uint8Array && out.length === crypto_secretstream_xchacha20poly1305_HEADERBYTES, + assert(_in instanceof Uint8Array && _in.length === crypto_secretstream_xchacha20poly1305_HEADERBYTES, '_in not byte array of length crypto_secretstream_xchacha20poly1305_HEADERBYTES') assert(k instanceof Uint8Array && k.length === crypto_secretstream_xchacha20poly1305_KEYBYTES, 'k not byte array of length crypto_secretstream_xchacha20poly1305_KEYBYTES') - crypto_core_hchacha20(state.k, _in, k, null); - _crypto_secretstream_xchacha20poly1305_counter_reset(state); + crypto_core_hchacha20(state.k, _in, k, null) + _crypto_secretstream_xchacha20poly1305_counter_reset(state) for (let i = 0; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) { state.nonce[i + crypto_secretstream_xchacha20poly1305_COUNTERBYTES] = _in[i + crypto_core_hchacha20_INPUTBYTES] @@ -129,7 +129,6 @@ function crypto_secretstream_xchacha20poly1305_init_pull(state, _in, k) { return 0 } - // void // crypto_secretstream_xchacha20poly1305_rekey // (crypto_secretstream_xchacha20poly1305_state *state) @@ -157,28 +156,28 @@ function crypto_secretstream_xchacha20poly1305_init_pull(state, _in, k) { // } // _crypto_secretstream_xchacha20poly1305_counter_reset(state); // } -function crypto_secretstream_xchacha20poly1305_rekey(state) { +function crypto_secretstream_xchacha20poly1305_rekey (state) { assert(state instanceof crypto_secretstream_xchacha20poly1305_state, 'state not instance of crypto_secretstream_xchacha20poly1305_state') const new_key_and_inonce = new Uint8Array( crypto_stream_chacha20_ietf_KEYBYTES + crypto_secretstream_xchacha20poly1305_INONCEBYTES) - let i - for (i = 0; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) { - new_key_and_inonce[i] = state.k[i] - } - for (i = 0; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) { - new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] = - state.nonce[crypto_secretstream_xchacha20poly1305_COUNTERBYTES + i] - } - crypto_stream_chacha20_ietf_xor(new_key_and_inonce, new_key_and_inonce, state.nonce, state.k) - for (i = 0; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) { - state.k[i] = new_key_and_inonce[i]; - } - for (i = 0; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) { - state.nonce[crypto_secretstream_xchacha20poly1305_COUNTERBYTES + i] = - new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] - } - _crypto_secretstream_xchacha20poly1305_counter_reset(state) + let i + for (i = 0; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) { + new_key_and_inonce[i] = state.k[i] + } + for (i = 0; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) { + new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] = + state.nonce[crypto_secretstream_xchacha20poly1305_COUNTERBYTES + i] + } + crypto_stream_chacha20_ietf_xor(new_key_and_inonce, new_key_and_inonce, state.nonce, state.k) + for (i = 0; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) { + state.k[i] = new_key_and_inonce[i] + } + for (i = 0; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) { + state.nonce[crypto_secretstream_xchacha20poly1305_COUNTERBYTES + i] = + new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] + } + _crypto_secretstream_xchacha20poly1305_counter_reset(state) } // int @@ -388,10 +387,9 @@ function crypto_secretstream_xchacha20poly1305_rekey(state) { // return crypto_secretstream_xchacha20poly1305_TAG_FINAL; // } - module.exports = { crypto_secretstream_xchacha20poly1305_keygen, crypto_secretstream_xchacha20poly1305_init_push, crypto_secretstream_xchacha20poly1305_init_pull, - crypto_secretstream_xchacha20poly1305_rekey, + crypto_secretstream_xchacha20poly1305_rekey }