From c84e70af550871ea077204f6d609069bd380e0a3 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 12 Sep 2024 23:16:02 +0000 Subject: [PATCH] readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a277dee..3a969a5 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,8 @@ const data_ = chacha.decrypt(ciphertext); #### Reuse array for input and output -This allows re-use Uint8Array between encryption/decryption calls (works if all plaintext or ciphertext are same size). +To avoid additional allocations, Uint8Array can be reused +between encryption and decryption calls. > [!NOTE] > Some ciphers don't support unaligned (`byteOffset % 4 !== 0`) Uint8Array as @@ -198,11 +199,11 @@ import { randomBytes } from '@noble/ciphers/webcrypto'; const key = randomBytes(32); const nonce = randomBytes(12); - const inputLength = 12; const tagLength = 16; + const buf = new Uint8Array(inputLength + tagLength); -const _data = utf8ToBytes('hello, noble'); +const _data = utf8ToBytes('hello, noble'); // length == 12 buf.set(_data, 0); // first inputLength bytes const _start = buf.subarray(0, inputLength);