Skip to content

Fix counter and nonce handling in DTLS 1.3 ChaCha20 - #250

Merged
mmaehren merged 2 commits into
tls-attacker:mainfrom
JoTurk:jo/fix-chacha20
Oct 19, 2026
Merged

mmaehren merged 2 commits into
tls-attacker:mainfrom
JoTurk:jo/fix-chacha20

Conversation

@JoTurk

@JoTurk JoTurk commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Hello, while we're adding TLS-Anvil to pion/dtls' interop we found two issues in the chacha20 implementation.

  1. counter and nonce sizes are reversed they should be 4-byte for counter and 12-byte for nonce per RFC 9147, Section 4.2.3.

the first 4 bytes of the ciphertext as the block counter and the next 12 bytes as the nonce

  1. ChaCha20 counter byte order is bigint big-endian, instead of 32-bit integer per RFC 8439, Section 2.3.

A 32-bit block count parameter, treated as a 32-bit little-endian integer.

let me know if I should split the fixes into separate PRs or squash them into a single commit. I can also add a regression test if needed (my Java isn't the best though).

Correct the reversed size constants to use a 4-byte counter and a
12-byte nonce.
This follows RFC 9147, Section 4.2.3.

> the first 4 bytes of the ciphertext as the block counter and the
> next 12 bytes as the nonce
Decode the sampled block counter as a little-endian 32-bit integer
instead of using BigInteger's big-endian interpretation.
This follows RFC 8439, Section 2.3.

> A 32-bit block count parameter, treated as a 32-bit little-endian
> integer.
@JoTurk JoTurk changed the title Fix chacha20 Fix DTLS 1.3 ChaCha20 record number generation Oct 14, 2026
@JoTurk JoTurk changed the title Fix DTLS 1.3 ChaCha20 record number generation Fix TLS 1.3 ChaCha20 record number generation Oct 14, 2026
@JoTurk JoTurk changed the title Fix TLS 1.3 ChaCha20 record number generation Fix counter and nonce handling in DTLS 1.3 ChaCha20 Oct 14, 2026

@mmaehren mmaehren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@mmaehren
mmaehren merged commit 9a0dc6f into tls-attacker:main Oct 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants