{% extends "_layout.html" %} {% block title %}Low-level Cryptography Details{% endblock %} {% block content %}

Updated November 2013, current as of router version 0.9.9

This page specifies the low-level details of the cryptography in I2P.

There are a handful of cryptographic algorithms in use within I2P, but we have reduced them to a bare minimum to deal with our needs - one symmetric algorithm one asymmetric algorithm, one signing algorithm, and one hashing algorithm. However, we do combine them in some particular ways to provide message integrity (rather than relying on a MAC). In addition, as much as we hate doing anything new in regards to cryptography, we can't seem to find a reference discussing (or even naming) the technique used in ElGamal/AES+SessionTag (but we're sure others have done it).

ElGamal encryption

ElGamal is used for asymmetric encryption. ElGamal is used in several places in I2P:

We use common primes for 2048 ElGamal encryption and decryption, as given by IETF RFC-3526. We currently only use ElGamal to encrypt the IV and session key in a single block, followed by the AES encrypted payload using that key and IV.

The unencrypted ElGamal contains:

   +----+----+----+----+----+----+----+----+
   |nonz|           H(data)                |
   +----+                                  +
   |                                       |
   +                                       +
   |                                       |
   +                                       +
   |                                       |
   +    +----+----+----+----+----+----+----+
   |    |  data...
   +----+----+----+--//                   

The H(data) is the SHA256 of the data that is encrypted in the ElGamal block, and is preceded by a nonzero byte. This byte could be random, but as implemented it is always 0xFF. It could possibly be used for flags in the future. The data encrypted in the block may be up to 222 bytes long. As the encrypted data may contain a substantial number of zeros if the cleartext is smaller than 222 bytes, it is recommended that higher layers pad the cleartext to 222 bytes with random data. Total length: typically 255 bytes.

The encrypted ElGamal contains:

   +----+----+----+----+----+----+----+----+
   |  zero padding...       |              |
   +----+----+----+--// ----+              +
   |                                       |
   +                                       +
   |       ElG encrypted part 1            |
   ~                                       ~
   |                                       |
   +    +----+----+----+----+----+----+----+
   |    |   zero padding...      |         |
   +----+----+----+----+--// ----+         +
   |                                       |
   +                                       +
   |       ElG encrypted part 2            |
   ~                                       ~
   |                                       |
   +         +----+----+----+----+----+----+
   |         +
   +----+----+

Each encrypted part is prepended with zeros to a size of exactly 257 bytes. Total length: 514 bytes. In typical usage, higher layers pad the cleartext data to 222 bytes, resulting in an unencrypted block of 255 bytes. This is encoded as two 256-byte encrypted parts, and there is a single byte of zero padding before each part at this layer.

See the ElGamal code.

The shared prime is the [Oakley prime for 2048 bit keys]

 2^2048 - 2^1984 - 1 + 2^64 * { [2^1918 pi] + 124476 }
or as a hexadecimal value:
 FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
 29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
 EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
 E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
 EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D
 C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F
 83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D
 670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B
 E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9
 DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510
 15728E5A 8AACAA68 FFFFFFFF FFFFFFFF

Using 2 as the generator.

Short Exponent

While the standard exponent size is 2048 bits (256 bytes) and the I2P PrivateKey is a full 256 bytes, we use the short exponent size of 226 bits (28.25 bytes). This should be safe for use with the Oakley primes, per On Diffie-Hellman Key Agreement with Short Exponents - van Oorschot, Weiner at EuroCrypt 96, and crypto++'s benchmarks. Benchmarks originally at this link, now dead, rescued from the wayback machine, dated Apr 23, 2008.

Also, Koshiba & Kurosawa: Short Exponent Diffie-Hellman Problems (PKC 2004, LNCS 2947, pp. 173-186) (full text on google books) apparently supports this, according to this sci.crypt thread. The remainder of the PrivateKey is padded with zeroes.

Obsolescence

The vulnerability of the network to an ElGamal attack and the impact of transitioning to a longer bit length is to be studied. It may be quite difficult to make any change backward-compatible.

AES

AES is used for symmetric encryption, in several cases:

We use AES with 256 bit keys and 128 bit blocks in CBC mode. The padding used is specified in IETF RFC-2313 (PKCS#5 1.5, section 8.1 (for block type 02)). In this case, padding exists of pseudorandomly generated octets to match 16 byte blocks. Specifically, see [the CBC code] and the Cryptix AES [implementation], as well as the padding, found in the ElGamalAESEngine.getPadding function.

Obsolescence

The vulnerability of the network to an AES attack and the impact of transitioning to a longer bit length is to be studied. It may be quite difficult to make any change backward-compatible.

References

DSA

Signatures are generated and verified with 1024 bit DSA (L=1024, N=160), as implemented in [DSAEngine]. DSA was chosen because it is much faster for signatures than ElGamal.

The DSA constants

SEED

160 bit

 86108236b8526e296e923a4015b4282845b572cc

Counter

 33

DSA prime (p)

1024 bit

 9C05B2AA 960D9B97 B8931963 C9CC9E8C 3026E9B8 ED92FAD0
 A69CC886 D5BF8015 FCADAE31 A0AD18FA B3F01B00 A358DE23
 7655C496 4AFAA2B3 37E96AD3 16B9FB1C C564B5AE C5B69A9F
 F6C3E454 8707FEF8 503D91DD 8602E867 E6D35D22 35C1869C
 E2479C3B 9D5401DE 04E0727F B33D6511 285D4CF2 9538D9E3
 B6051F5B 22CC1C93

DSA quotient (q)

 A5DFC28F EF4CA1E2 86744CD8 EED9D29D 684046B7

DSA generator (g)

1024 bit

 0C1F4D27 D40093B4 29E962D7 223824E0 BBC47E7C 832A3923
 6FC683AF 84889581 075FF908 2ED32353 D4374D73 01CDA1D2
 3C431F46 98599DDA 02451824 FF369752 593647CC 3DDC197D
 E985E43D 136CDCFC 6BD5409C D2F45082 1142A5E6 F8EB1C3A
 B5D0484B 8129FCF1 7BCE4F7F 33321C3C B3DBB14A 905E7B2B
 3E93BE47 08CBCC82

The Signing Public Key is 1024 bits. The Signing Private Key is 160 bits.

Obsolescence

NIST 800-57 recommends a minimum of (L=2048, N=224) for usage beyond 2010. This may be mitigated somewhat by the "cryptoperiod", or lifespan of a given key.

The prime number was chosen in 2003, and the person that chose the number (TheCrypto) is currently no longer an I2P developer. As such, we do not know if the prime chosen is a 'strong prime'. If a larger prime is chosen for future purposes, this should be a strong prime, and we will document the construction process.

The vulnerability of the network to a DSA attack and the impact of transitioning to longer keys is to be studied. It may be quite difficult to make any change backward-compatible.

References

SHA256

Hashes within I2P are plain old SHA256, as implemented in [SHA256Generator]

Obsolescence

The vulnerability of the network to a SHA-256 attack and the impact of transitioning to a longer hash is to be studied. It may be quite difficult to make any change backward-compatible.

References

Transports

At the lowest protocol layer, point-to-point inter-router communication is protected by the transport layer security. Both transports use 256 byte (2048 bit) Diffie-Hellman key exchange using the same shared prime and generator as specified above for ElGamal, followed by symmetric AES encryption as described above. This provides perfect forward secrecy on the transport links.

NTCP connections

NTCP connections are negotiated with a 2048 Diffie-Hellman implementation, using the router's identity to proceed with a station to station agreement, followed by some encrypted protocol specific fields, with all subsequent data encrypted with AES (as above). The primary reason to do the DH negotiation instead of using ElGamalAES+SessionTag is that it provides '(perfect) forward secrecy', while ElGamalAES+SessionTag does not.

In order to migrate to a more standardized implementation (TLS/SSL or even SSH), the following issues must be addressed:

  1. can we somehow reestablish sessions securely (ala session tags) or do we need to do full negotiation each time?
  2. can we simplify/avoid the x509 or other certificate formats and use our own RouterInfo structure (which contains the ElGamal and DSA keys)?

See the NTCP specification for details.

UDP connections

SSU (the UDP transport) encrypts each packet with AES256/CBC with both an explicit IV and MAC (HMAC-MD5-128) after agreeing upon an ephemeral session key through a 2048 bit Diffie-Hellman exchange, station-to-station authentication with the other router's DSA key, plus each network message has their own hash for local integrity checking.

See the SSU specification for details.

WARNING - I2P's HMAC-MD5-128 used in SSU is apparently non-standard. Apparently, an early version of SSU used HMAC-SHA256, and then it was switched to MD5-128 for performance reasons, but left the 32-byte buffer size intact. See HMACGenerator.java and the 2005-07-05 status notes for details.

References

{% endblock %}