Skip to content

Commit

Permalink
Simplify ChaCha20 interface
Browse files Browse the repository at this point in the history
The nonce can just be opaque bytes.

The block counter is tricky, as noted in the issue.  The "obvious"
choice is little-endian, as that is consistent with the philosophy of
the designer (as I understand it), but that is not anything more than a
guess.

Absent strong evidence that big-endian is a better choice, I'm going to
err on the side of not making a substantive change here.  But I think
that we need a consensus call to support that viewpoint.

Closes #2171.
  • Loading branch information
martinthomson committed Aug 26, 2019
1 parent 4ef3e0d commit 55ec704
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions draft-ietf-quic-tls.md
Expand Up @@ -1049,16 +1049,16 @@ function as defined in Section 2.4 of {{!CHACHA}}. This uses a 256-bit key and
16 bytes sampled from the packet protection output.

The first 4 bytes of the sampled ciphertext are interpreted as a 32-bit number
in little-endian order and are used as the block count. The remaining 12 bytes
are interpreted as three concatenated 32-bit numbers in little-endian order and
used as the nonce.
in little-endian order and are used as the block count; a ChaCha20
implementation might instead take the 4 bytes as an opaque sequence of bytes.
The remaining 12 bytes are used as the nonce.

The encryption mask is produced by invoking ChaCha20 to protect 5 zero bytes. In
pseudocode:

~~~
counter = DecodeLE(sample[0..3])
nonce = DecodeLE(sample[4..7], sample[8..11], sample[12..15])
nonce = sample[4....15]
mask = ChaCha20(hp_key, counter, nonce, {0,0,0,0,0})
~~~

Expand Down

2 comments on commit 55ec704

@mikkelfj
Copy link
Contributor

Choose a reason for hiding this comment

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

So you say this is beyond what is specified here, with test vectors?

https://tools.ietf.org/id/draft-agl-tls-chacha20poly1305-03.html

@martinthomson
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. That (now RFC 8439, as cited in this spec), specifies block counters as a number. It doesn't specify how that number might be derived from a sequence of bytes.

Please sign in to comment.