I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
169-pq-crypto.rst 69.4 KiB
Newer Older
zzz's avatar
zzz committed
===================================
Post-Quantum Crypto Protocols
===================================
.. meta::
    :author: zzz
    :created: 2025-01-21
    :thread: http://zzz.i2p/topics/3294
zzz's avatar
zzz committed
    :lastupdated: 2025-03-11
zzz's avatar
zzz committed
    :status: Open
    :target: 0.9.80

.. contents::






Overview
========

While research and competition for suitable post-quantum (PQ)
zzz's avatar
zzz committed
cryptography have been proceeding for a decade, the choices
zzz's avatar
zzz committed
have not become clear until recently.

We started looking at the implications of PQ crypto
in 2022 [FORUM]_.

zzz's avatar
zzz committed
TLS standards added hybrid encryption support in the last two years and it now
is used for a significant portion of encrypted traffic on the internet
due to support in Chrome and Firefox [CLOUDFLARE]_.
zzz's avatar
zzz committed

NIST recently finalized and published the recommended algorithms
for post-quantum cryptography [NIST-PQ]_.
zzz's avatar
zzz committed
Several common cryptography libraries now support the NIST standards
or will be releasing support in the near future.
zzz's avatar
zzz committed

Both [CLOUDFLARE]_ and [NIST-PQ]_ recommend that migration start immediately.
See also the 2022 NSA PQ FAQ [NSA-PQ]_.
I2P should be a leader in security and cryptography.
Now is the time to implement the recommended algorithms.
Using our flexible crypto type and signature type system,
we will add types for hybrid crypto, and for PQ and hybrid signatures.


Goals
=====

- Select PQ-resistant algorithms
- Add PQ-only and hybrid algorithms to I2P protocols where appropriate
- Select best variants after implementation, testing, analysis, and research
- Add support incrementally and with backward compatibility


Non-Goals
=========

zzz's avatar
zzz committed
- Don't change one-way (Noise N) encryption protocols
zzz's avatar
zzz committed
- Don't move away from SHA256, not threatened near-term by PQ
zzz's avatar
zzz committed


Threat Model
============

- Routers at the OBEP or IBGW, possibly colluding,
  storing garlic messages for later decryption (forward secrecy)
- Network observers
  storing transport messages for later decryption (forward secrecy)
- Network participants forging signatures for RI, LS, streaming, datagrams,
  or other structures
zzz's avatar
zzz committed



Design
======

We will support the NIST FIPS 203 and 204 standards [FIPS203]_ [FIPS204]_
which are based on, but NOT compatible with,
CRYSTALS-Kyber and CRYSTALS-Dilithium (versions 3.1, 3, and older).



Key Exchange
-------------

We will support key exchange in the following protocols:

=======  ==========  ==============  ===============
Proto    Noise Type  Support PQ?     Support Hybrid?
=======  ==========  ==============  ===============
NTCP2       XK       no              yes
SSU2        XK       no              yes
Ratchet     IK       no              yes
TBM          N       no              no
NetDB        N       no              no
=======  ==========  ==============  ===============

PQ KEM provides ephemeral keys only, and does not directly support
static-key handshakes such as Noise XK and IK.
While there is some recent research [PQ-WIREGUARD]_ on adapting Wireguard (IK)
for pure PQ crypto, there are several open questions, and
this approach is unproven.

Noise N does not use a two-way key exchange and so it is not suitable
for hybrid encryption.

So we will support hybrid encryption only, for NTCP2, SSU2, and Ratchet.
We will define the three ML-KEM variants as in [FIPS203]_,
for 3 new encryption types total.
Hybrid types will only be defined in combination with X25519.

zzz's avatar
zzz committed
The new encryption types are:

zzz's avatar
zzz committed
================  ====
  Type            Code
================  ====
MLKEM512_X25519     5
MLKEM768_X25519     6
MLKEM1024_X25519    7
================  ====
zzz's avatar
zzz committed

zzz's avatar
zzz committed
Overhead will be substantial. Typical message 1 and 2 sizes (for XK and IK)
are currently around 100 bytes (before any additional payload).
This will increase by 8x to 15x depending on algorithm.


Signatures
-----------

We will support PQ and hybrid signatures in the following structures:

==========================  ==============  ===============
Type                        Support PQ?     Support Hybrid?
==========================  ==============  ===============
RouterInfo                  yes             yes
LeaseSet                    yes             yes
Streaming SYN/SYNACK/Close  yes             yes
Repliable Datagrams         yes             yes
zzz's avatar
zzz committed
Datagram2 (prop. 163)       yes             yes
zzz's avatar
zzz committed
I2CP create session msg     yes             yes
SU3 files                   yes             yes
X.509 certificates          yes             yes
Java keystores              yes             yes
==========================  ==============  ===============


So we will support both PQ-only and hybrid signatures.
We will define the three ML-DSA variants as in [FIPS204]_,
zzz's avatar
zzz committed
as well as three hybrid variants with Ed25519 prehash for SU3 files only,
for 9 new signature types total.
zzz's avatar
zzz committed
Hybrid types will only be defined in combination with Ed25519.
We will use the standard ML-DSA, NOT the pre-hash variants (HashML-DSA).

zzz's avatar
zzz committed
The new signature types are:

zzz's avatar
zzz committed
============================  ====
        Type                  Code
============================  ====
MLDSA44_EdDSA_SHA512_Ed25519   12
MLDSA65_EdDSA_SHA512_Ed25519   13
MLDSA87_EdDSA_SHA512_Ed25519   14
MLDSA44                        15
MLDSA65                        16
MLDSA87                        17
zzz's avatar
zzz committed
MLDSA44_Ed25519ph              18
MLDSA65_Ed25519ph              19
MLDSA87_Ed25519ph              20
zzz's avatar
zzz committed
============================  ====
zzz's avatar
zzz committed

zzz's avatar
zzz committed
X.509 certificates and other DER encodings will use the
composite structures and OIDs defined in [COMPOSITE-SIGS]_.

Overhead will be substantial. Typical Ed25519 destination and router identity
sizes are 391 bytes.
These will increase by 3.5x to 6.8x depending on algorithm.
Ed25519 signatures are 64 bytes.
These will increase by 38x to 76x depending on algorithm.
Typical signed RouterInfo, LeaseSet, repliable datagrams, and signed streaming messages are about 1KB.
These will increase by 3x to 8x depending on algorithm.

As the new destination and router identity types will not contain padding,
they will not be compressible. Sizes of destinations and router identities
that are gzipped in-transit will increase by 12x - 38x depending on algorithm.

TODO: Add RSA4096 hybrid types for su3?


zzz's avatar
zzz committed
Legal Combinations
------------------
zzz's avatar
zzz committed

For Destinations, the new signature types are supported with all encryption
zzz's avatar
zzz committed
types in the leaseset. Set the encryption type in the key certificate to NULL (255).
zzz's avatar
zzz committed

For RouterIdentities, ElGamal encryption type is deprecated.
The new signature types are supported with X25519 (type 4) encryption only.
The new encryption types will be indicated in the RouterAddresses.
The encryption type in the key certificate will continue to be type 4.



zzz's avatar
zzz committed
New Crypto Required
-------------------

- ML-KEM (formerly CRYSTALS-Kyber) [FIPS203]_
- ML-DSA (formerly CRYSTALS-Dilithium) [FIPS204]_
zzz's avatar
zzz committed
- SHA3-128 (formerly Keccak-256) [FIPS202]_ Used only for SHAKE128
zzz's avatar
zzz committed
- SHA3-256 (formerly Keccak-512) [FIPS202]_
- SHAKE128 and SHAKE256 (XOF extensions to SHA3-128 and SHA3-256) [FIPS202]_

zzz's avatar
zzz committed
Test vectors for SHA3-256, SHAKE128, and SHAKE256 are at [NIST-VECTORS]_.

zzz's avatar
zzz committed
Note that the Java bouncycastle library supports all the above.
zzz's avatar
zzz committed
C++ library support will be in OpenSSL 3.5 [OPENSSL]_.
zzz's avatar
zzz committed


Alternatives
-------------

We will not support [FIPS205]_ (Sphincs+), it is much much slower and bigger than ML-DSA.
We will not support the upcoming FIPS206 (Falcon), it is not yet standardized.
zzz's avatar
zzz committed
We will not support NTRU or other PQ candidates that were not standardized by NIST.
zzz's avatar
zzz committed


Specification
=============

Common Structures
-----------------

zzz's avatar
zzz committed
Update the sections and tables in the common structures document [COMMON]_ as follows:


zzz's avatar
zzz committed
PublicKey
zzz's avatar
zzz committed
````````````````
zzz's avatar
zzz committed

zzz's avatar
zzz committed
The new Public Key types are:

zzz's avatar
zzz committed
================    ================= ======  =====
  Type              Public Key Length Since   Usage
================    ================= ======  =====
MLKEM512_X25519               32      0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM768_X25519               32      0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM1024_X25519              32      0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM512                     800      0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
MLKEM768                    1184      0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
MLKEM1024                   1568      0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
zzz's avatar
zzz committed
MLKEM512_CT                  768      0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
MLKEM768_CT                 1088      0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
MLKEM1024_CT                1568      0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
zzz's avatar
zzz committed
NULL                           0      0.9.xx  See proposal 169, for destinations with PQ sig types only, not for RIs or Leasesets
zzz's avatar
zzz committed
================    ================= ======  =====

Hybrid public keys are the X25519 key.
KEM public keys are the ephemeral PQ key sent from Alice to Bob.
Byte order defined in [FIPS203]_.
zzz's avatar
zzz committed

zzz's avatar
zzz committed
MLKEM*_CT keys are not really public keys, they are the "ciphertext" sent from Bob to Alice in the Noise handshake.
They are listed here for completeness.


zzz's avatar
zzz committed

PrivateKey
zzz's avatar
zzz committed
````````````````
zzz's avatar
zzz committed

zzz's avatar
zzz committed
The new Private Key types are:

zzz's avatar
zzz committed
================    ================== ======  =====
  Type              Private Key Length Since   Usage
================    ================== ======  =====
MLKEM512_X25519               32       0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM768_X25519               32       0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM1024_X25519              32       0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM512                    1632       0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
MLKEM768                    2400       0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
MLKEM1024                   3168       0.9.xx  See proposal 169, for handshakes only, not for Leasesets, RIs or Destinations
================    ================== ======  =====

Hybrid private keys are the X25519 key followed by the PQ key.
KEM private keys are the ciphertext sent from Bob to Alice.
Byte order defined in [FIPS203]_.
zzz's avatar
zzz committed




SigningPublicKey
zzz's avatar
zzz committed
````````````````
zzz's avatar
zzz committed

zzz's avatar
zzz committed
The new Signing Public Key types are:
zzz's avatar
zzz committed

============================   ==============  ======  =====
         Type                  Length (bytes)  Since   Usage
============================   ==============  ======  =====
MLDSA44_EdDSA_SHA512_Ed25519         1344      0.9.xx  See proposal 169
MLDSA65_EdDSA_SHA512_Ed25519         1984      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA87_EdDSA_SHA512_Ed25519         2624      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA44                              1312      0.9.xx  See proposal 169
MLDSA65                              1952      0.9.xx  See proposal 169
MLDSA87                              2592      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA44_Ed25519ph                    1344      0.9.xx  Only for SU3 files, not for netdb structures
MLDSA65_Ed25519ph                    1984      0.9.xx  Only for SU3 files, not for netdb structures
MLDSA87_Ed25519ph                    2624      0.9.xx  Only for SU3 files, not for netdb structures
zzz's avatar
zzz committed
============================   ==============  ======  =====

Hybrid signing public keys are the Ed25519 key followed by the PQ key.
Byte order defined in [FIPS204]_.
zzz's avatar
zzz committed


SigningPrivateKey
`````````````````

zzz's avatar
zzz committed
The new Signing Private Key types are:

zzz's avatar
zzz committed
============================   ==============  ======  =====
         Type                  Length (bytes)  Since   Usage
============================   ==============  ======  =====
MLDSA44_EdDSA_SHA512_Ed25519         2592      0.9.xx  See proposal 169
MLDSA65_EdDSA_SHA512_Ed25519         4064      0.9.xx  See proposal 169
MLDSA87_EdDSA_SHA512_Ed25519         4928      0.9.xx  See proposal 169
MLDSA44                              2560      0.9.xx  See proposal 169
MLDSA65                              4032      0.9.xx  See proposal 169
MLDSA87                              4896      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA44_Ed25519ph                    2592      0.9.xx  Only for SU3 files, not for netdb structuresSee proposal 169
MLDSA65_Ed25519ph                    4064      0.9.xx  Only for SU3 files, not for netdb structuresSee proposal 169
MLDSA87_Ed25519ph                    4928      0.9.xx  Only for SU3 files, not for netdb structuresSee proposal 169
zzz's avatar
zzz committed
============================   ==============  ======  =====

Hybrid signing private keys are the Ed25519 key followed by the PQ key.
Byte order defined in [FIPS204]_.
zzz's avatar
zzz committed


Signature
``````````
zzz's avatar
zzz committed

The new Signature types are:

zzz's avatar
zzz committed
============================   ==============  ======  =====
         Type                  Length (bytes)  Since   Usage
============================   ==============  ======  =====
MLDSA44_EdDSA_SHA512_Ed25519         2484      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA65_EdDSA_SHA512_Ed25519         3373      0.9.xx  See proposal 169
MLDSA87_EdDSA_SHA512_Ed25519         4691      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA44                              2420      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA65                              3309      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA87                              4627      0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA44_Ed25519ph                    2484      0.9.xx  Only for SU3 files, not for netdb structuresSee proposal 169
MLDSA65_Ed25519ph                    3373      0.9.xx  Only for SU3 files, not for netdb structuresSee proposal 169
MLDSA87_Ed25519ph                    4691      0.9.xx  Only for SU3 files, not for netdb structuresSee proposal 169
zzz's avatar
zzz committed
============================   ==============  ======  =====

Hybrid signatures are the Ed25519 signature followed by the PQ signature.
Hybrid signatures are verified by verifying both signatures, and failing
if either one fails.
Byte order defined in [FIPS204]_.
zzz's avatar
zzz committed



Key Certificates
````````````````

zzz's avatar
zzz committed
The new Signing Public Key types are:
zzz's avatar
zzz committed

============================  ===========  =======================  ======  =====
        Type                  Type Code    Total Public Key Length  Since   Usage
============================  ===========  =======================  ======  =====
zzz's avatar
zzz committed
MLDSA44_EdDSA_SHA512_Ed25519      12                 1344           0.9.xx  See proposal 169
MLDSA65_EdDSA_SHA512_Ed25519      13                 1984           0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA87_EdDSA_SHA512_Ed25519      14                 2624           0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA44                           15                 1312           0.9.xx  See proposal 169
MLDSA65                           16                 1952           0.9.xx  See proposal 169
MLDSA87                           17                 2592           0.9.xx  See proposal 169
zzz's avatar
zzz committed
MLDSA44_Ed25519ph                 18                  n/a           0.9.xx  Only for SU3 files
MLDSA65_Ed25519ph                 19                  n/a           0.9.xx  Only for SU3 files
MLDSA87_Ed25519ph                 20                  n/a           0.9.xx  Only for SU3 files
zzz's avatar
zzz committed
============================  ===========  =======================  ======  =====



zzz's avatar
zzz committed
The new Crypto Public Key types are:
zzz's avatar
zzz committed

================    ===========  ======================= ======  =====
  Type              Type Code    Total Public Key Length Since   Usage
================    ===========  ======================= ======  =====
MLKEM512_X25519          5                 32            0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM768_X25519          6                 32            0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
MLKEM1024_X25519         7                 32            0.9.xx  See proposal 169, for Leasesets only, not for RIs or Destinations
zzz's avatar
zzz committed
NULL                   255                  0            0.9.xx  See proposal 169
zzz's avatar
zzz committed
================    ===========  ======================= ======  =====


Hybrid key types are NEVER included in key certificates; only in leasesets.

zzz's avatar
zzz committed
For destinations with Hybrid or PQ signature types,
zzz's avatar
zzz committed
use NULL (type 255) for the encryption type,
zzz's avatar
zzz committed
but there is no crypto key, and the
zzz's avatar
zzz committed
entire 384-byte main section is for the signing key.


Destination sizes
``````````````````

Here are lengths for the new Destination types.
zzz's avatar
zzz committed
Enc type for all is NULL (type 255) and the encryption key length is treated as 0.
zzz's avatar
zzz committed
The entire 384-byte section is used for the first part of the signing public key.
zzz's avatar
zzz committed
NOTE: This is different than the spec for the ECDSA_SHA512_P521
and the RSA signature types, where we maintained the 256-byte ElGamal
key in the destination even though it was unused.

zzz's avatar
zzz committed
No padding.
Total length is 7 + total key length.
Key certificate length is 4 + excess key length.

Example 1319-byte destination byte stream for MLDSA44:

skey[0:383] 5 (932 >> 8) (932 & 0xff) 00 12 00 255 skey[384:1311]



============================  ===========  =======================  ======  ======  =====
        Type                  Type Code    Total Public Key Length  Main    Excess  Total Dest Length
============================  ===========  =======================  ======  ======  =====
MLDSA44_EdDSA_SHA512_Ed25519      12                 1344           384      960    1351
MLDSA65_EdDSA_SHA512_Ed25519      13                 1984           384     1600    1991
zzz's avatar
zzz committed
MLDSA87_EdDSA_SHA512_Ed25519      14                 2624           384     2240    2631
zzz's avatar
zzz committed
MLDSA44                           15                 1312           384      928    1319
MLDSA65                           16                 1952           384     1568    1959
MLDSA87                           17                 2592           384     2208    2599
============================  ===========  =======================  ======  ======  =====



RouterIdent sizes
``````````````````

Here are lengths for the new Destination types.
zzz's avatar
zzz committed
Enc type for all is X25519 (type 4).
zzz's avatar
zzz committed
The entire 352-byte section after the X28819 public key is used for the first part of the signing public key.
No padding.
Total length is 39 + total key length.
Key certificate length is 4 + excess key length.

Example 1351-byte router identity byte stream for MLDSA44:

enckey[0:31] skey[0:351] 5 (960 >> 8) (960 & 0xff) 00 12 00 4 skey[352:1311]



============================  ===========  =======================  ======  ======  =====
        Type                  Type Code    Total Public Key Length  Main    Excess  Total RouterIdent Length
============================  ===========  =======================  ======  ======  =====
MLDSA44_EdDSA_SHA512_Ed25519      12                 1344           352      992    1383
MLDSA65_EdDSA_SHA512_Ed25519      13                 1984           352     1632    2023
zzz's avatar
zzz committed
MLDSA87_EdDSA_SHA512_Ed25519      14                 2624           352     2272    2663
zzz's avatar
zzz committed
MLDSA44                           15                 1312           352      960    1351
MLDSA65                           16                 1952           352     1600    1991
MLDSA87                           17                 2592           352     2240    2631
============================  ===========  =======================  ======  ======  =====



Handshake Patterns
------------------

Handshakes use [Noise]_ handshake patterns.

The following letter mapping is used:

- e = one-time ephemeral key
- s = static key
- p = message payload
- e1 = one-time ephemeral PQ key, sent from Alice to Bob
- ekem1 = the KEM ciphertext, sent from Bob to Alice

zzz's avatar
zzz committed
The following modifications to XK and IK for hybrid forward secrecy (hfs) are
zzz's avatar
zzz committed
as specified in [Noise-Hybrid]_ section 5:
zzz's avatar
zzz committed

.. raw:: html

  {% highlight lang='dataspec' %}

XK:                       XKhfs:
  <- s                      <- s
  ...                       ...
  -> e, es, p               -> e, es, e1, p
  <- e, ee, p               <- e, ee, ekem1, p
  -> s, se                  -> s, se
  <- p                      <- p
  p ->                      p ->


  IK:                       IKhfs:
  <- s                      <- s
  ...                       ...
  -> e, es, s, ss, p       -> e, es, e1, s, ss, p
  <- tag, e, ee, se, p     <- tag, e, ee, ekem1, se, p
  <- p                     <- p
  p ->                     p ->

zzz's avatar
zzz committed
  e1 and ekem1 are encrypted. See pattern definitions below.
zzz's avatar
zzz committed
  NOTE: e1 and ekem1 are different sizes (unlike X25519)
zzz's avatar
zzz committed

{% endhighlight %}

zzz's avatar
zzz committed
The e1 pattern is defined as follows, as specified in [Noise-Hybrid]_ section 4:
zzz's avatar
zzz committed

.. raw:: html

  {% highlight lang='dataspec' %}

For Alice:
  (encap_key, decap_key) = PQ_KEYGEN()

  // EncryptAndHash(encap_key)
  ciphertext = ENCRYPT(k, n, encap_key, ad)
  MixHash(ciphertext)

  For Bob:

  // DecryptAndHash(ciphertext)
  encap_key = DECRYPT(k, n, ciphertext, ad)
  MixHash(ciphertext)


{% endhighlight %}


zzz's avatar
zzz committed
The ekem1 pattern is defined as follows, as specified in [Noise-Hybrid]_ section 4:
zzz's avatar
zzz committed

.. raw:: html

  {% highlight lang='dataspec' %}

For Bob:

  (kem_ciphertext, kem_shared_key) = ENCAPS(encap_key)

  // EncryptAndHash(kem_ciphertext)
  ciphertext = ENCRYPT(k, n, kem_ciphertext, ad)
  MixHash(ciphertext)

  // MixKey
  MixKey(kem_shared_key)


  For Alice:

  // DecryptAndHash(ciphertext)
  kem_ciphertext = DECRYPT(k, n, ciphertext, ad)
  MixHash(ciphertext)

  // MixKey
  kem_shared_key = DECAPS(kem_ciphertext, decap_key)
  MixKey(kem_shared_key)


{% endhighlight %}

zzz's avatar
zzz committed



Noise Handshake KDF
---------------------

zzz's avatar
zzz committed
This section applies to both IK and XK protocols.

zzz's avatar
zzz committed
The hybrid handshake is defined in [Noise-Hybrid]_.
The first message, from Alice to Bob, contains e1, the encapsulation key, before the message payload.
This is treated as an additional static key; call EncryptAndHash() on it (as Alice)
or DecryptAndHash() (as Bob).
Then process the message payload as usual.

The second message, from Bob to Alice, contains ekem1, the ciphertext, before the message payload.
This is treated as an additional static key; call EncryptAndHash() on it (as Bob)
or DecryptAndHash() (as Alice).
Then, calculate the kem_shared_key and call MixKey(kem_shared_key).
Then process the message payload as usual.

zzz's avatar
zzz committed

zzz's avatar
zzz committed
Defined ML-KEM Operations
`````````````````````````

We define the following functions corresponding to the cryptographic building blocks used
as defined in [FIPS203]_.

zzz's avatar
zzz committed
(encap_key, decap_key) = PQ_KEYGEN()
zzz's avatar
zzz committed
    Alice creates the encapsulation and decapsulation keys
    The encapsulation key is sent in message 1.
    encap_key and decap_key sizes vary based on ML-KEM variant.

zzz's avatar
zzz committed
(ciphertext, kem_shared_key) = ENCAPS(encap_key)
zzz's avatar
zzz committed
    Bob calculates the ciphertext and shared key,
    using the ciphertext received in message 1.
    The ciphertext is sent in message 2.
    ciphertext size varies based on ML-KEM variant.
    The kem_shared_key is always 32 bytes.

kem_shared_key = DECAPS(ciphertext, decap_key)
    Alice calculates the shared key,
    using the ciphertext received in message 2.
    The kem_shared_key is always 32 bytes.

Note that both the encap_key and the ciphertext are encrypted inside ChaCha/Poly
blocks in the Noise handshake messages 1 and 2.
They will be decrypted as part of the handshake process.

zzz's avatar
zzz committed
The kem_shared_key is mixed into the chaining key with MixHash().
zzz's avatar
zzz committed
See below for details.


Alice KDF for Message 1
`````````````````````````

zzz's avatar
zzz committed
For XK: After the 'es' message pattern and before the payload, add:

OR

For IK: After the 'es' message pattern and before the 's' message pattern, add:

zzz's avatar
zzz committed
.. raw:: html

  {% highlight lang='text' %}
zzz's avatar
zzz committed
This is the "e1" message pattern:
zzz's avatar
zzz committed
  (encap_key, decap_key) = PQ_KEYGEN()
zzz's avatar
zzz committed

  // AEAD parameters
  k = keydata[32:63]
  n = 0
  ad = h
zzz's avatar
zzz committed
  ciphertext = ENCRYPT(k, n, encap_key, ad)

  // MixHash(ciphertext)
  h = SHA256(h || ciphertext)

zzz's avatar
zzz committed

  End of "e1" message pattern.
zzz's avatar
zzz committed

zzz's avatar
zzz committed
{% endhighlight %}


Bob KDF for Message 1
`````````````````````````

For XK: After the 'es' message pattern and before the payload, add:

OR

For IK: After the 'es' message pattern and before the 's' message pattern, add:

zzz's avatar
zzz committed
.. raw:: html

  {% highlight lang='text' %}
zzz's avatar
zzz committed
This is the "e1" message pattern:

  // AEAD parameters
  k = keydata[32:63]
  n = 0
  ad = h
zzz's avatar
zzz committed
  encap_key = DECRYPT(k, n, encap_key_section, ad)

  // MixHash(encap_key_section)
  h = SHA256(h || encap_key_section)
zzz's avatar
zzz committed

  End of "e1" message pattern.

{% endhighlight %}
zzz's avatar
zzz committed


Bob KDF for Message 2
`````````````````````````

zzz's avatar
zzz committed
For XK: After the 'ee' message pattern and before the payload, add:

OR

For IK: After the 'ee' message pattern and before the 'se' message pattern, add:

zzz's avatar
zzz committed
.. raw:: html

  {% highlight lang='text' %}
zzz's avatar
zzz committed
This is the "ekem1" message pattern:

zzz's avatar
zzz committed
  (kem_ciphertext, kem_shared_key) = ENCAPS(encap_key)

  // AEAD parameters
  k = keydata[32:63]
  n = 0
  ad = h
  ciphertext = ENCRYPT(k, n, kem_ciphertext, ad)

zzz's avatar
zzz committed
  // MixHash(ciphertext)
  h = SHA256(h || ciphertext)

  // MixKey(kem_shared_key)
  keydata = HKDF(chainKey, kem_shared_key, "", 64)
  chainKey = keydata[0:31]

  End of "ekem1" message pattern.

{% endhighlight %}
zzz's avatar
zzz committed


Alice KDF for Message 2
`````````````````````````

zzz's avatar
zzz committed
After the 'ee' message pattern (and before the 'ss' message pattern for IK), add:
zzz's avatar
zzz committed

zzz's avatar
zzz committed
.. raw:: html

  {% highlight lang='text' %}
zzz's avatar
zzz committed
This is the "ekem1" message pattern:
zzz's avatar
zzz committed

zzz's avatar
zzz committed
  // AEAD parameters
  k = keydata[32:63]
  n = 0
  ad = h
  kem_ciphertext = DECRYPT(k, n, kem_ciphertext_section, ad)
zzz's avatar
zzz committed

zzz's avatar
zzz committed
  // MixHash(kem_ciphertext_section)
  h = SHA256(h || kem_ciphertext_section)
zzz's avatar
zzz committed

  // MixKey(kem_shared_key)
zzz's avatar
zzz committed
  kem_shared_key = DECAPS(kem_ciphertext, decap_key)
zzz's avatar
zzz committed
  keydata = HKDF(chainKey, kem_shared_key, "", 64)
  chainKey = keydata[0:31]

  End of "ekem1" message pattern.
zzz's avatar
zzz committed

zzz's avatar
zzz committed
{% endhighlight %}
zzz's avatar
zzz committed


zzz's avatar
zzz committed
Alice/Bob KDF for split()
`````````````````````````
unchanged
zzz's avatar
zzz committed


zzz's avatar
zzz committed

Ratchet
---------

zzz's avatar
zzz committed
Update the ECIES-Ratchet specification [ECIES]_ as follows:


Noise identifiers
`````````````````
zzz's avatar
zzz committed

- "Noise_IKhfselg2_25519+MLKEM512_ChaChaPoly_SHA256"
- "Noise_IKhfselg2_25519+MLKEM768_ChaChaPoly_SHA256"
- "Noise_IKhfselg2_25519+MLKEM1024_ChaChaPoly_SHA256"

zzz's avatar
zzz committed


1b) New session format (with binding)
`````````````````````````````````````

zzz's avatar
zzz committed
Changes: Current ratchet contained the static key in the first ChaCha section,
and the payload in the second section.
With ML-KEM, there are now three sections.
The first section contains the encrypted PQ public key.
The second section contains the static key.
The third section contains the payload.
zzz's avatar
zzz committed
Encrypted format:

.. raw:: html

  {% highlight lang='dataspec' %}
+----+----+----+----+----+----+----+----+
  |                                       |
  +                                       +
  |   New Session Ephemeral Public Key    |
  +             32 bytes                  +
  |     Encoded with Elligator2           |
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
  |                                       |
zzz's avatar
zzz committed
  +           ML-KEM encap_key            +
zzz's avatar
zzz committed
  |       ChaCha20 encrypted data         |
zzz's avatar
zzz committed
  +      (see table below for length)     +
zzz's avatar
zzz committed
  |                                       |
zzz's avatar
zzz committed
  ~                                       ~
  |                                       |
  +----+----+----+----+----+----+----+----+
  |  Poly1305 Message Authentication Code |
  +    (MAC) for encap_key Section        +
  |             16 bytes                  |
  +----+----+----+----+----+----+----+----+
  |                                       |
  +           X25519 Static Key           +
  |       ChaCha20 encrypted data         |
  +             32 bytes                  +
  |                                       |
zzz's avatar
zzz committed
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
  |  Poly1305 Message Authentication Code |
  +    (MAC) for Static Key Section       +
  |             16 bytes                  |
  +----+----+----+----+----+----+----+----+
  |                                       |
  +            Payload Section            +
  |       ChaCha20 encrypted data         |
  ~                                       ~
  |                                       |
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
  |  Poly1305 Message Authentication Code |
  +         (MAC) for Payload Section     +
  |             16 bytes                  |
  +----+----+----+----+----+----+----+----+


zzz's avatar
zzz committed
{% endhighlight %}

Decrypted format:

.. raw:: html
zzz's avatar
zzz committed

  {% highlight lang='dataspec' %}
zzz's avatar
zzz committed
Payload Part 1:

  +----+----+----+----+----+----+----+----+
  |                                       |
zzz's avatar
zzz committed
  +       ML-KEM encap_key                +
zzz's avatar
zzz committed
  |                                       |
  +      (see table below for length)     +
  |                                       |
  ~                                       ~
  |                                       |
zzz's avatar
zzz committed
  +----+----+----+----+----+----+----+----+

  Payload Part 2:

zzz's avatar
zzz committed
  +----+----+----+----+----+----+----+----+
  |                                       |
  +       X25519 Static Key               +
  |                                       |
  +      (32 bytes)                       +
  |                                       |
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
zzz's avatar
zzz committed

zzz's avatar
zzz committed
  Payload Part 3:
zzz's avatar
zzz committed

  +----+----+----+----+----+----+----+----+
  |                                       |
  +            Payload Section            +
  |                                       |
  ~                                       ~
  |                                       |
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
zzz's avatar
zzz committed

{% endhighlight %}

zzz's avatar
zzz committed
Sizes:

================    =========  =====  =========  =============  =============  ==========  =======
  Type              Type Code  X len  Msg 1 len  Msg 1 Enc len  Msg 1 Dec len  PQ key len  pl len
================    =========  =====  =========  =============  =============  ==========  =======
X25519                   4       32     96+pl        64+pl             pl           --       pl
zzz's avatar
zzz committed
MLKEM512_X25519          5       32    912+pl       880+pl         800+pl          800       pl
MLKEM768_X25519          6       32   1296+pl      1360+pl        1184+pl         1184       pl
MLKEM1024_X25519         7       32   1680+pl      1648+pl        1568+pl         1568       pl
zzz's avatar
zzz committed
================    =========  =====  =========  =============  =============  ==========  =======

zzz's avatar
zzz committed

1g) New Session Reply format
````````````````````````````

zzz's avatar
zzz committed
Changes: Current ratchet has an empty payload for the first ChaCha section,
and the payload in the second section.
With ML-KEM, there are now three sections.
The first section contains the encrypted PQ ciphertext.
The second section has an empty payload.
The third section contains the payload.
zzz's avatar
zzz committed


Encrypted format:

zzz's avatar
zzz committed
.. raw:: html

  {% highlight lang='dataspec' %}
+----+----+----+----+----+----+----+----+
  |       Session Tag   8 bytes           |
  +----+----+----+----+----+----+----+----+
  |                                       |
  +        Ephemeral Public Key           +
  |                                       |
  +            32 bytes                   +
  |     Encoded with Elligator2           |
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
zzz's avatar
zzz committed
  |                                       |
  +                                       +
zzz's avatar
zzz committed
  | ChaCha20 encrypted ML-KEM ciphertext  |
zzz's avatar
zzz committed
  +      (see table below for length)     +
  ~                                       ~
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
zzz's avatar
zzz committed
  |  Poly1305 Message Authentication Code |
zzz's avatar
zzz committed
  +  (MAC) for ciphertext Section         +
  |             16 bytes                  |
  +----+----+----+----+----+----+----+----+
  |  Poly1305 Message Authentication Code |
  +  (MAC) for key Section (no data)      +
zzz's avatar
zzz committed
  |             16 bytes                  |
  +----+----+----+----+----+----+----+----+
  |                                       |
  +            Payload Section            +
  |       ChaCha20 encrypted data         |
  ~                                       ~
  |                                       |
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+
  |  Poly1305 Message Authentication Code |
  +         (MAC) for Payload Section     +
  |             16 bytes                  |
  +----+----+----+----+----+----+----+----+


{% endhighlight %}

zzz's avatar
zzz committed
Decrypted format:

.. raw:: html
zzz's avatar
zzz committed

  {% highlight lang='dataspec' %}
zzz's avatar
zzz committed
Payload Part 1:


  +----+----+----+----+----+----+----+----+
  |                                       |
  +       ML-KEM ciphertext               +
  |                                       |
  +      (see table below for length)     +
  |                                       |
  ~                                       ~
  |                                       |
  +----+----+----+----+----+----+----+----+

  Payload Part 2:

zzz's avatar
zzz committed
  empty

  Payload Part 3:

zzz's avatar
zzz committed
  +----+----+----+----+----+----+----+----+
  |                                       |
  +            Payload Section            +
  |                                       |
  ~                                       ~
  |                                       |
  +                                       +
  |                                       |
  +----+----+----+----+----+----+----+----+

{% endhighlight %}

Sizes:

================    =========  =====  =========  =============  =============  ==========  =======
  Type              Type Code  Y len  Msg 2 len  Msg 2 Enc len  Msg 2 Dec len  PQ CT len   opt len
================    =========  =====  =========  =============  =============  ==========  =======
X25519                   4       32     72+pl        32+pl             pl           --       pl
zzz's avatar
zzz committed
MLKEM512_X25519          5       32    856+pl       816+pl         768+pl          768       pl
MLKEM768_X25519          6       32   1176+pl      1136+pl        1088+pl         1088       pl
MLKEM1024_X25519         7       32   1656+pl      1616+pl        1568+pl         1568       pl
zzz's avatar
zzz committed
================    =========  =====  =========  =============  =============  ==========  =======

zzz's avatar
zzz committed

zzz's avatar
zzz committed


NTCP2
------

zzz's avatar
zzz committed
Update the NTCP2 specification [NTCP2]_ as follows:


Noise identifiers
`````````````````
zzz's avatar
zzz committed

- "Noise_XKhfsaesobfse+hs2+hs3_25519+MLKEM512_ChaChaPoly_SHA256"
- "Noise_XKhfsaesobfse+hs2+hs3_25519+MLKEM768_ChaChaPoly_SHA256"
- "Noise_XKhfsaesobfse+hs2+hs3_25519+MLKEM1024_ChaChaPoly_SHA256"

zzz's avatar
zzz committed

1) SessionRequest
``````````````````

zzz's avatar
zzz committed
Changes: Current NTCP2 contains only the options in the ChaCha section.
With ML-KEM, the ChaCha section will also contain the encrypted PQ public key.

zzz's avatar
zzz committed