Git Product home page Git Product logo

Comments (4)

jedisct1 avatar jedisct1 commented on May 28, 2024

The constant looks correct.

ChaCha has 16 bytes to share between the nonce and the counter.

For the needs of TLS, the IETF version uses 12 bytes for the nonce, 4 for the counter:

NNNNNNNNNNNNCCCC

The original version uses 8 bytes for the nonce, 8 for the counter.

NNNNNNNNCCCCCCCC

Now, XChaCha uses a 24 byte nonce. 16 bytes of it are going to be the sub-key, and there are 8 bytes left for the actual sub-nonce. So we have 8 bytes left for the counter.

nnnnnnnnCCCCCCCC

If an implementation only supports 4 bytes counters and requires 12 bytes for the nonce, it's still possible to build XChaCha in a compatible way until 2^32 blocks:

nnnnnnnn0000CCCC

32 bits would always be zero, so usage would be limited to the IETF limits. That limit would be very artificial.
But if you need to reuse a library that only supports 4 byte counters, and implement XChaCha by only adding HChaCha, you will indeed have that limit.

libsodium supports 8 bytes counters so doesn't have that limit. Internally, it's called crypto_stream_chacha20_ietf_ext, as the authenticator is computed as with ChaCha20-iETF, but we allow the counter to be 8 bytes.

from libsodium.

ivmaykov avatar ivmaykov commented on May 28, 2024

Hmm I see. So it sounds like for XChaCha20-Poly1305, there is effectively no difference between the IETF and non-IETF variants (or maybe another way to think about it is, there is no such thing as non-IETF XChaCha20-Poly1305?), since both of them use 8 bytes of nonce and 8 bytes of counter after the HChaCha20 step?

from libsodium.

jedisct1 avatar jedisct1 commented on May 28, 2024

Yes, even the libsodium crypto_aead API has only one version.

from libsodium.

ivmaykov avatar ivmaykov commented on May 28, 2024

Thank you for clearing it up for me!

from libsodium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.