Skip to content

Commit

Permalink
aes, chacha, salsa: adjust comments
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Sep 9, 2024
1 parent ceaeb80 commit 1d356ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/aes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,10 @@ function computeTag(

/**
* GCM: Galois/Counter Mode.
* Good, modern version of CTR, parallel, with MAC.
* Modern, parallel version of CTR, with MAC.
* Be careful: MACs can be forged.
* Unsafe to use random nonces under the same key, due to collision chance.
* As for nonce size, prefer 12-byte, instead of 8-byte.
*/
export const gcm = wrapCipher(
{ blockSize: 16, nonceLength: 12, tagLength: 16 },
Expand Down
7 changes: 4 additions & 3 deletions src/chacha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,17 @@ export const _poly1305_aead =

/**
* ChaCha20-Poly1305 from RFC 8439.
* With 12-byte nonce, it's not safe to use fill it with random (CSPRNG), due to collision chance.
* Unsafe to use random nonces under the same key, due to collision chance.
* Prefer XChaCha instead.
*/
export const chacha20poly1305 = /* @__PURE__ */ wrapCipher(
{ blockSize: 64, nonceLength: 12, tagLength: 16 },
_poly1305_aead(chacha20)
);
/**
* XChaCha20-Poly1305 extended-nonce chacha.
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha
* With 24-byte nonce, it's safe to use fill it with random (CSPRNG).
* Can be safely used with random nonces (CSPRNG).
* [IRTF draft](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha).
*/
export const xchacha20poly1305 = /* @__PURE__ */ wrapCipher(
{ blockSize: 64, nonceLength: 24, tagLength: 16 },
Expand Down
7 changes: 4 additions & 3 deletions src/salsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export function hsalsa(

/**
* Salsa20 from original paper.
* With 12-byte nonce, it's not safe to use fill it with random (CSPRNG), due to collision chance.
* Unsafe to use random nonces under the same key, due to collision chance.
* Prefer XSalsa instead.
*/
export const salsa20 = /* @__PURE__ */ createCipher(salsaCore, {
allowShortKeys: true,
Expand All @@ -105,7 +106,7 @@ export const salsa20 = /* @__PURE__ */ createCipher(salsaCore, {

/**
* xsalsa20 eXtended-nonce salsa.
* With 24-byte nonce, it's safe to use fill it with random (CSPRNG).
* Can be safely used with random 24-byte nonces (CSPRNG).
*/
export const xsalsa20 = /* @__PURE__ */ createCipher(salsaCore, {
counterRight: true,
Expand All @@ -114,7 +115,7 @@ export const xsalsa20 = /* @__PURE__ */ createCipher(salsaCore, {

/**
* xsalsa20-poly1305 eXtended-nonce salsa.
* With 24-byte nonce, it's safe to use fill it with random (CSPRNG).
* Can be safely used with random 24-byte nonces (CSPRNG).
* Also known as secretbox from libsodium / nacl.
*/
export const xsalsa20poly1305 = /* @__PURE__ */ wrapCipher(
Expand Down

0 comments on commit 1d356ca

Please sign in to comment.