This page was last updated in February 2016 and is accurate for router version 0.9.24.

This document describes some data types common to all I2P protocols, like I2NP, I2CP, SSU, etc.

Integer

Description

Represents a non-negative integer.

Contents

1 to 8 bytes in network byte order representing an unsigned integer

Date

Description

The number of milliseconds since midnight on January 1, 1970 in the GMT timezone. If the number is 0, the date is undefined or null.

Contents

8 byte Integer

String

Description

Represents a UTF-8 encoded string.

Contents

1 or more bytes where the first byte is the number of bytes (not characters!) in the string and the remaining 0-255 bytes are the non-null terminated UTF-8 encoded character array. Length limit is 255 bytes (not characters). Length may be 0.

Boolean

Description

A boolean value, supporting null/unknown representation 0=false, 1=true, 2=unknown/null

Contents

1 byte Integer

Notes

Deprecated - unused

PublicKey

Description

This structure is used in ElGamal encryption, representing only the exponent, not the primes, which are constant and defined in the cryptography specification.

Contents

256 bytes

Javadoc

PrivateKey

Description

This structure is used in ElGamal decryption, representing only the exponent, not the primes which are constant and defined in the cryptography specification.

Contents

256 bytes

Javadoc

SessionKey

Description

This structure is used for AES256 encryption and decryption.

Contents

32 bytes

Javadoc

SigningPublicKey

Description

This structure is used for verifying signatures.

Contents

Key type and length are inferred from context or are specified in the Key Certificate of a Destination. The default type is DSA_SHA1. As of release 0.9.12, other types may be supported, depending on context.

TypeLength (bytes)SinceUsage
DSA_SHA1128 Legacy Router Identities and Destinations
ECDSA_SHA256_P256640.9.12Recent Destinations
ECDSA_SHA384_P384960.9.12Rarely used for Destinations
ECDSA_SHA512_P5211320.9.12Rarely used for Destinations
RSA_SHA256_20482560.9.12Offline signing, never used for Router Identities or Destinations
RSA_SHA384_30723840.9.12Offline signing, never used for Router Identities or Destinations
RSA_SHA512_40965120.9.12Offline signing, never used for Router Identities or Destinations
EdDSA_SHA512_Ed25519320.9.15Recent Router Identities and Destinations
EdDSA_SHA512_Ed25519ph320.9.25Offline signing, never used for Router Identities or Destinations

Notes

  • When a key is composed of two elements (for example points X,Y), it is serialized by padding each element to length/2 with leading zeros if necessary.
  • All types are Big Endian, except for EdDSA, which is stored and transmitted in a Little Endian format.

Javadoc

SigningPrivateKey

Description

This structure is used for creating signatures.

Contents

Key type and length are specified when created. The default type is DSA_SHA1. As of release 0.9.12, other types may be supported, depending on context.

TypeLength (bytes)SinceUsage
DSA_SHA120 Legacy Router Identities and Destinations
ECDSA_SHA256_P256320.9.12Recent Destinations
ECDSA_SHA384_P384480.9.12Rarely used for Destinations
ECDSA_SHA512_P521660.9.12Rarely used for Destinations
RSA_SHA256_20485120.9.12Offline signing, never used for Router Identities or Destinations
RSA_SHA384_30727680.9.12Offline signing, never used for Router Identities or Destinations
RSA_SHA512_409610240.9.12Offline signing, never used for Router Identities or Destinations
EdDSA_SHA512_Ed25519320.9.15Recent Router Identities and Destinations
EdDSA_SHA512_Ed25519ph320.9.25Offline signing, never used for Router Identities or Destinations

Notes

  • When a key is composed of two elements (for example points X,Y), it is serialized by padding each element to length/2 with leading zeros if necessary.
  • All types are Big Endian, except for EdDSA, which is stored and transmitted in a Little Endian format.

Javadoc

Signature

Description

This structure represents the signature of some data.

Contents

Signature type and length are inferred from the type of key used. The default type is DSA_SHA1. As of release 0.9.12, other types may be supported, depending on context.

TypeLength (bytes)SinceUsage
DSA_SHA140 Legacy Router Identities and Destinations
ECDSA_SHA256_P256640.9.12Recent Destinations
ECDSA_SHA384_P384960.9.12Rarely used for Destinations
ECDSA_SHA512_P5211320.9.12Rarely used for Destinations
RSA_SHA256_20482560.9.12Offline signing, never used for Router Identities or Destinations
RSA_SHA384_30723840.9.12Offline signing, never used for Router Identities or Destinations
RSA_SHA512_40965120.9.12Offline signing, never used for Router Identities or Destinations
EdDSA_SHA512_Ed25519640.9.15Recent Router Identities and Destinations
EdDSA_SHA512_Ed25519ph640.9.25Offline signing, never used for Router Identities or Destinations

Notes

  • When a signature is composed of two elements (for example values R,S), it is serialized by padding each element to length/2 with leading zeros if necessary.
  • All types are Big Endian, except for EdDSA, which is stored and transmitted in a Little Endian format.

Javadoc

Hash

Description

Represents the SHA256 of some data.

Contents

32 bytes

Javadoc

Session Tag

Description

A random number

Contents

32 bytes

Javadoc

TunnelId

Description

Defines an identifier that is unique to each router in a tunnel. A Tunnel ID is generally greater than zero; do not use a value of zero except in special cases.

Contents

4 byte Integer

Javadoc

Certificate

Description

A certificate is a container for various receipts or proof of works used throughout the I2P network.

Contents

1 byte Integer specifying certificate type, followed by a 2 byte Integer specifying the size of the certificate payload, then that many bytes.

+----+----+----+----+----+-// |type| length | payload +----+----+----+----+----+-//type::Integerlength->1bytecase0->NULLcase1->HASHCASHcase2->HIDDENcase3->SIGNEDcase4->MULTIPLEcase5->KEYlength::Integerlength->2bytespayload::datalength->$lengthbytes

Notes

  • For Router Identities, the Certificate is always NULL through version 0.9.15. As of 0.9.16, a Key Certificate may be used to specify the signing public key type. See below.
  • For Garlic Cloves, the Certificate is always NULL, no others are currently implemented.
  • For Garlic Messages, the Certificate is always NULL, no others are currently implemented.
  • For Destinations, the Certificate may be non-NULL. As of 0.9.12, a Key Certificate may be used to specify the signing public key type. See below.

Certificate Types

The following certificate types are defined:

TypeType CodePayload LengthTotal LengthNotes
Null003
HashCash1variesvaries Experimental, unused. Payload contains an ASCII colon-separated hashcash string.
Hidden203 Experimental, unused. Hidden routers generally do not announce that they are hidden.
Signed340 or 7243 or 75 Experimental, unused. Payload contains a 40-byte DSA signature, optionally followed by the 32-byte Hash of the signing Destination.
Multiple4variesvaries Experimental, unused. Payload contains multiple certificates.
Key54+7+ Since 0.9.12. See below for details.

Key Certificates

Key certificates were introduced in release 0.9.12. Prior to that release, all PublicKeys were 256-byte ElGamal keys, and all SigningPublicKeys were 128-byte DSA-SHA1 keys. A key certificate provides a mechanism to indicate the type of the PublicKey and SigningPublicKey in the Destination or RouterIdentity, and to package any key data in excess of the standard lengths.

By maintaining exactly 384 bytes before the certificate, and putting any excess key data inside the certificate, we maintain compatibility for any software that parses Destinations and Router Identities.

The key certificate payload contains:

DataLength
Signing Public Key Type (Integer) 2
Crypto Public Key Type (Integer) 2
Excess Signing Public Key Data0+
Excess Crypto Public Key Data0+

The defined Signing Key types are:

TypeType CodeTotal Public Key LengthSinceUsage
DSA_SHA101280.9.12Legacy Router Identities and Destinations, never explicitly set
ECDSA_SHA256_P2561640.9.12Recent Destinations
ECDSA_SHA384_P3842960.9.12Sometimes used for Destinations
ECDSA_SHA512_P52131320.9.12Sometimes used for Destinations
RSA_SHA256_204842560.9.12Offline only; never used in Key Certificates for Router Identities or Destinations
RSA_SHA384_307253840.9.12Offline only; never used in Key Certificates for Router Identities or Destinations
RSA_SHA512_409665120.9.12Offline only; never used in Key Certificates for Router Identities or Destinations
EdDSA_SHA512_Ed255197320.9.15Recent Router Identities and Destinations
EdDSA_SHA512_Ed25519ph8320.9.25Offline only; never used in Key Certificates for Router Identities or Destinations
reserved65280 - 65534Reserved for experimental use
reserved65535Reserved for future expansion

The defined Crypto Public Key types are:

TypeType CodeTotal Public Key LengthSinceUsage
ElGamal02560.9.12All Router Identities and Destinations
reserved65280 - 65534Reserved for experimental use
reserved65535Reserved for future expansion

When a Key Certificate is not present, the preceeding 384 bytes in the Destination or RouterIdentity are defined as the 256-byte ElGamal PublicKey followed by the 128-byte DSA-SHA1 SigningPublicKey. When a Key Certificate is present, the preceeding 384 bytes are redefined as follows:

  • Complete or first portion of Crypto Public Key
  • Random padding if the total lengths of the two keys are less than 384 bytes
  • Complete or first portion of Signing Public Key

The Crypto Public Key is aligned at the start and the Signing Public Key is aligned at the end. The padding (if any) is in the middle. The lengths and boundaries of the initial key data, the padding, and the excess key data portions in the certificates are not explicitly specified, but are derived from the lengths of the specified key types. If the total lengths of the Crypto and Signing Public Keys exceed 384 bytes, the remainder will be contained in the Key Certificate. If the Crypto Public Key length is not 256 bytes, the method for determining the boundary between the two keys is to be specified in a future revision of this document.

Example layouts using an ElGamal Crypto Public Key and the Signing Public Key type indicated:

Signing Key TypePadding LengthExcess Signing Key Data in Cert
DSA_SHA100
ECDSA_SHA256_P256640
ECDSA_SHA384_P384320
ECDSA_SHA512_P52104
RSA_SHA256_20480128
RSA_SHA384_30720256
RSA_SHA512_40960384
EdDSA_SHA512_Ed25519960
EdDSA_SHA512_Ed25519ph960

Javadoc

Mapping

Description

A set of key/value mappings or properties

Contents

A 2-byte size Integer followed by a series of String=String; pairs

+----+----+----+----+----+----+----+----+ | size |key_string(len+data) | = | +----+----+----+----+----+----+----+----+ | val_string(len+data) | ; | ... +----+----+----+----+----+----+----+size::Integerlength->2bytesTotalnumberofbytesthatfollowkey_string::StringAstring(onebytelengthfollowedbyUTF-8encodedcharacters)=::Asinglebytecontaining'='val_string::StringAstring(onebytelengthfollowedbyUTF-8encodedcharacters);::Asinglebytecontaining';'

Notes

  • The encoding isn't optimal - we either need the '=' and ';' characters, or the string lengths, but not both
  • Some documentation says that the strings may not include '=' or ';' but this encoding supports them
  • Strings are defined to be UTF-8 but in the current implementation, I2CP uses UTF-8 but I2NP does not. For example, UTF-8 strings in a RouterInfo options mapping in a I2NP Database Store Message will be corrupted.
  • The encoding allows duplicate keys, however in any usage where the mapping is signed, duplicates may cause a signature failure.
  • Mappings contained in I2NP messages (i.e. in a RouterAddress or RouterInfo) must be sorted by key so that the signature will be invariant. Duplicate keys are not allowed.
  • Mappings contained in an I2CP SessionConfig must be sorted by key so that the signature will be invariant. Duplicate keys are not allowed.
  • The sort method is defined as in Java String.compareTo(), using the Unicode value of the characters.
  • While it is application-dependent, keys and values are generally case-sensitive.
  • Key and value string length limits are 255 bytes (not characters) each, plus the length byte. Length byte may be 0.
  • Total length limit is 65535 bytes, plus the 2 byte size field, or 65537 total.

Javadoc

Common structure specification

KeysAndCert

Description

An encryption public key, a signing public key, and a certificate, used as either a RouterIdentity or a Destination.

Contents

PublicKey followed by SigningPublicKey and then a Certificate

+----+----+----+----+----+----+----+----+ | public_key | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | padding(optional) | ~~~~ | | +----+----+----+----+----+----+----+----+ | signing_key | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | certificate | +----+----+----+-//public_key::PublicKey(partialorfull)length->256bytesorasspecifiedinkeycertificatepadding::randomdatalength->0bytesorasspecifiedinkeycertificatepaddinglength + signing_keylength==128bytessigning__key::SigningPublicKey(partialorfull)length->128bytesorasspecifiedinkeycertificatepaddinglength + signing_keylength==128bytescertificate::Certificatelength->>=3bytestotallength:387+bytes

Notes

  • Do not assume that these are always 387 bytes! They are 387 bytes plus the certificate length specified at bytes 385-386, which may be non-zero.
  • As of release 0.9.12, if the certificate is a Key Certificate, the boundaries of the key fields may vary. See the Key Certificate section above for details.
  • The Crypto Public Key is aligned at the start and the Signing Public Key is aligned at the end. The padding (if any) is in the middle.

Javadoc

RouterIdentity

Description

Defines the way to uniquely identify a particular router

Contents

Identical to KeysAndCert.

Notes

  • The certificate for a RouterIdentity was always NULL until release 0.9.12.
  • Do not assume that these are always 387 bytes! They are 387 bytes plus the certificate length specified at bytes 385-386, which may be non-zero.
  • As of release 0.9.12, if the certificate is a Key Certificate, the boundaries of the key fields may vary. See the Key Certificate section above for details.
  • The Crypto Public Key is aligned at the start and the Signing Public Key is aligned at the end. The padding (if any) is in the middle.

Javadoc

Destination

Description

A Destination defines a particular endpoint to which messages can be directed for secure delivery.

Contents

Identical to KeysAndCert.

Notes

  • The public key of the destination was used for the old i2cp-to-i2cp encryption which was disabled in version 0.6, it is currently unused except for the IV for LeaseSet encryption, which is deprecated. The public key in the LeaseSet is used instead.
  • Do not assume that these are always 387 bytes! They are 387 bytes plus the certificate length specified at bytes 385-386, which may be non-zero.
  • As of release 0.9.12, if the certificate is a Key Certificate, the boundaries of the key fields may vary. See the Key Certificate section above for details.
  • The Crypto Public Key is aligned at the start and the Signing Public Key is aligned at the end. The padding (if any) is in the middle.

Javadoc

Lease

Description

Defines the authorization for a particular tunnel to receive messages targeting a Destination.

Contents

SHA256 Hash of the RouterIdentity of the gateway router, then the TunnelId, and finally an end Date

+----+----+----+----+----+----+----+----+ | tunnel_gw | + + | | + + | | + + | | +----+----+----+----+----+----+----+----+ | tunnel_id | end_date +----+----+----+----+----+----+----+----+ | +----+----+----+----+tunnel_gw::HashoftheRouterIdentityofthetunnelgatewaylength->32bytestunnel_id::TunnelIdlength->4bytesend_date::Datelength->8bytes

Notes

  • Total size: 44 bytes

Javadoc

LeaseSet

Description

Contains all of the currently authorized Leases for a particular Destination, the PublicKey to which garlic messages can be encrypted, and then the public key that can be used to revoke this particular version of the structure. The LeaseSet is one of the two structures stored in the network database( the other being RouterInfo), and is keyed under the SHA256 of the contained Destination.

Contents

Destination, followed by a PublicKey for encryption, then a SigningPublicKey which can be used to revoke this version of the LeaseSet, then a 1 byte Integer specifying how many Lease structures are in the set, followed by the actual Lease structures and finally a Signature of the previous bytes signed by the Destination'sSigningPrivateKey

+----+----+----+----+----+----+----+----+ | destination | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | encryption_key | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | signing_key | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ |num | Lease0 | +----+ + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | Lease1 | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | Lease($num-1) | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | signature | + + | | + + | | + + | | + + | | +----+----+----+----+----+----+----+----+ destination::Destinationlength->>=387bytesencryption_key::PublicKeylength->256bytessigning_key::SigningPublicKeylength->128bytesorasspecifiedindestination'skeycertificatenum::Integerlength->1byteNumberofleasestofollowvalue:0<=num<=16leases::[Lease]length->$num*44bytessignature::Signaturelength->40bytesorasspecifiedindestination'skeycertificate

Notes

  • The public key of the destination was used for the old i2cp-to-i2cp encryption which was disabled in version 0.6, it is currently unused.
  • The encryption key is used for end-to-end ElGamal/AES+SessionTag encryption. It is currently generated anew at every router startup, it is not persistent.
  • The signature may be verified using the signing public key of the destination.
  • The signing_key is currently unused. It was intended for LeaseSet revocation, which is unimplemented. It is currently generated anew at every router startup, it is not persistent. The signing key type is always the same as the destination's signing key type.
  • The earliest expiration of all the Leases is treated as the timestamp or version of the LeaseSet. Routers will generally not accept a store of a LeaseSet unless it is "newer" than the current one. Take care when publishing a new LeaseSet where the oldest Lease is the same as the oldest Lease in the previous LeaseSet. The publishing router should generally increment the expiration of the oldest Lease by at least 1 ms in that case.
  • Prior to release 0.9.7, when included in a DatabaseStore Message sent by the originating router, the router set all the published leases' expirations to the same value, that of the earliest lease. As of release 0.9.7, the router publishes the actual lease expiration for each lease. This is an implementation detail and not part of the structures specification.

Javadoc

RouterAddress

Description

This structure defines the means to contact a router through a transport protocol.

Contents

1 byte Integer defining the relative cost of using the address, where 0 is free and 255 is expensive, followed by the expiration Date after which the address should not be used, or if null, the address never expires. After that comes a String defining the transport protocol this router address uses. Finally there is a Mapping containing all of the transport specific options necessary to establish the connection, such as IP address, port number, email address, URL, etc.

+----+----+----+----+----+----+----+----+ |cost| expiration +----+----+----+----+----+----+----+----+ | transport_style | +----+----+----+----+-//-+----+----+----+ | | + + | options | ~~~~ | | +----+----+----+----+----+----+----+----+ cost::Integerlength->1bytecase0->freecase255->expensiveexpiration::Date(mustbeallzeros,seenotesbelow)length->8bytescasenull->neverexpirestransport_style::Stringlength->1-256bytesoptions::Mapping

Notes

  • Cost is typically 5 or 6 for SSU, and 10 or 11 for NTCP.
  • Expiration is currently unused, always null (all zeroes). As of release 0.9.3, the expiration is assumed zero and not stored, so any non-zero expiration will fail in the RouterInfo signature verification. Implementing expiration (or another use for these bytes) will be a backwards-incompatible change. Routers MUST set this field to all zeros. As of release 0.9.12, a non-zero expiration field is again recognized, however we must wait several releases to use this field, until the vast majority of the network recognizes it.
  • The following options, while not required, are standard and expected to be present in most router addresses: "host" (an IPv4 or IPv6 address or host name) and "port".

Javadoc

RouterInfo

Description

Defines all of the data that a router wants to publish for the network to see. The RouterInfo is one of two structures stored in the network database(the other being LeaseSet, and is keyed under the SHA256 of the contained RouterIdentity.

Contents

RouterIdentity followed by the Date, when the entry was published

+----+----+----+----+----+----+----+----+ | router_ident | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | published | +----+----+----+----+----+----+----+----+ |size| RouterAddress0 | +----+ + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | RouterAddress1 | + + | | ~~~~ | | +----+----+----+----+----+----+----+----+ | RouterAddress($size-1) | + + | | ~~~~ | | +----+----+----+----+-//-+----+----+----+ |psiz| options | +----+----+----+----+-//-+----+----+----+ | signature | + + | | + + | | + + | | + + | | +----+----+----+----+----+----+----+----+ router_ident::RouterIdentitylength->>=387bytespublished::Datelength->8bytessize::Integerlength->1byteThenumberofRouterAddressestofollow,0-255addresses::[RouterAddress]length->variespeer_size::Integerlength->1byteThenumberofpeerHashestofollow,0-255,unused,alwayszerovalue->0options::Mappingsignature::Signaturelength->40bytes

Notes

  • The peer_size Integer may be followed by a list of that many router hashes. This is currently unused. It was intended for a form of restricted routes, which is unimplemented.
  • The signature may be verified using the signing public key of the router_ident.
  • See the network database page for standard options that are expected to be present in all router infos.

Javadoc

Delivery Instructions

Tunnel Message Delivery Instructions are defined in the Tunnel Message Specification.

Garlic Message Delivery Instructions are defined in the I2NP Message Specification.