Comments (4)
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.
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.
Yes, even the libsodium crypto_aead
API has only one version.
from libsodium.
Thank you for clearing it up for me!
from libsodium.
Related Issues (20)
- Why soname change from 23 to 26 HOT 1
- [UB] memcpy could be called on null dst pointer in function escrypt_r HOT 2
- Shouldn't crypto_pwdhash_PRIMITIVE be 'argon2id' ? HOT 1
- LATEST.tar.gz.sig is missing HOT 1
- Request to add amalgamation build HOT 2
- Compilation issues
- Build tries to use AVX on i386 when no support for them available HOT 9
- 64 bytes for the hash in `crypto_box_curve25519xsalsa20poly1305_seed_keypair(..)`? HOT 1
- Sodium.Core Nuget package version 1.3.4 is not getting installed in .Net 4.8 project HOT 1
- Support for Windows Arm64
- Zig build for windows platform issue HOT 1
- FreeBSD: aarch64 build fails HOT 6
- 1.0.19 mistagged? HOT 4
- `crypto_kdf_hkdf_sha{256,512}_extract_final` use `sizeof` on a pointer (in code which currently is actually not buggy)
- Several calls to `fe25519_abs` trigger `memcpy` undefined behavior
- is hashtocurve (rfc9380) implemented (especially for ristretto255?)
- Assert failure observed on box_seal test HOT 1
- Intentional segfault never occurs in tests sodium_utils{23} HOT 7
- Random assert failure in onetimeauth test HOT 1
- Documentation on crypto_secretstream API HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsodium.