Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Sep 12, 2024
1 parent b7793e2 commit c84e70a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down

0 comments on commit c84e70a

Please sign in to comment.