1.12.4: ML-DSA empty context, HKDF mode ignored, ephemeral ML-KEM keys
Chris Burdess
dog at gnu.org
Fri Nov 27 21:30:44 CET 2026
Hello,
I use libgcrypt in quickstep, a TLS, DTLS and QUIC library that is being
considered for the GNU project. I have three points on 1.12.4. I
reproduced them with that release, using the two attached programs, on
macOS 27.0.1 (Apple M4) and on Ubuntu 24.04.5 (aarch64, kernel 6.19.7,
gcc 13.3.0, in a container in a VM on the same machine).
1. ML-DSA with an empty context (backport request)
With (data (raw) (value ...)), and either no label or an empty one, both
gcry_pk_sign and gcry_pk_verify return "Invalid data" (gcry-repro.c).
The empty context is the FIPS 204 default, and it's what TLS uses. I
work around this by forming M' myself and passing the no-prefix flag.
master appears to fix this in b161a19729f4 (sign) and 57d00b4121e6
(verify), GnuPG-bug-id 8517. As of 2026-11-26 neither seems to be on
LIBGCRYPT-1.12-BRANCH. I read these on the GitHub mirror but have not
built master. Could they be cherry-picked for the next 1.12 release?
2. The HKDF mode parameter is ignored
gcry_kdf_open with GCRY_KDF_HKDF accepts a second parameter and stores
it as the mode, but hkdf_compute and hkdf_final never read it, so both
extract and expand always run. Modes 0 and 1 give identical output
(gcry-repro.c). cipher/kdf.c has the comment "MODE: support extract
only, expand only: FIXME", which is still there on master.
The TLS 1.3 key schedule needs Extract and Expand separately, so I
currently build HKDF on HMAC. Would you accept extract-only and
expand-only modes? Until they exist, I suggest rejecting a non-zero
mode with GPG_ERR_INV_VALUE, so that a caller can't receive full HKDF
output while expecting something else.
3. Generating short-lived ML-KEM keys
gcry_kem_keypair draws the ML-KEM coins at GCRY_VERY_STRONG_RANDOM,
which suits long-term keys. In a TLS key exchange the key lasts for one
handshake. ML-KEM-768, three passes of 1000 keys each (kem-bench.c), in
ms/key:
macOS Linux
gcry_kem_keypair about 3.1 about 2.2
gcry_kem_genkey, GCRY_STRONG_RANDOM coins about 0.024 about 0.031
The second row includes drawing the coins. 1.12.3 already moved the
encapsulation coins and the ML-DSA signature nonce to strong random. Is
gcry_kem_genkey with caller-supplied coins the intended way to make
ephemeral keys? If so, I think that's worth documenting. If not, would
you accept a way to ask for GCRY_STRONG_RANDOM, leaving the default as
it is?
Thanks,
Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcry-repro.c
Type: text/x-csrc
Size: 2811 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gcrypt-devel/attachments/20261127/21b07694/attachment-0002.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kem-bench.c
Type: text/x-csrc
Size: 1737 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gcrypt-devel/attachments/20261127/21b07694/attachment-0003.c>
More information about the Gcrypt-devel
mailing list