java.lang.Object
net.i2p.data.i2np.BuildResponseRecord

public class BuildResponseRecordextends Object
Class that creates an encrypted tunnel build message record.

The reply record is the same size as the request record (528 bytes).

When decrypted:

Bytes 0-31 contain the hash of bytes 32-527
Bytes 32-526 contain random data.
Byte 527 contains the reply.
  • Constructor Details

    • BuildResponseRecord

      private BuildResponseRecord()
      Utility class - prevent instantiation.
  • Method Details

    • create

      public static EncryptedBuildRecord create(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyIV, long responseMessageId)
      Creates a new AES-encrypted response record. Create a new encrypted response. AES only for ElGamal routers.
      Parameters:
      ctx - the application context
      status - the response 0-255
      replyKey - the session key for reply encryption
      replyIV - 16 bytes IV
      responseMessageId - unused except for debugging
      Returns:
      a 528-byte response record
    • create

      public static EncryptedBuildRecord create(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyAD, Properties options)
      Creates a new ChaCha/Poly-encrypted response record (long format). Create a new encrypted response (long record). ChaCha/Poly only for ECIES routers.
      Parameters:
      ctx - the application context
      status - the response 0-255
      replyKey - the session key for reply encryption
      replyAD - 32 bytes associated data
      options - 511 bytes max when serialized
      Returns:
      a 528-byte response record
      Throws:
      IllegalArgumentException - if options too big or on encryption failure
    • createShort

      public static ShortEncryptedBuildRecord createShort(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyAD, Properties options, int slot)
      Creates a new ChaCha/Poly-encrypted response record (short format). Create a new encrypted response (short record). ChaCha/Poly only for ECIES routers.
      Parameters:
      ctx - the application context
      status - the response 0-255
      replyKey - the session key for reply encryption
      replyAD - 32 bytes associated data
      options - 116 bytes max when serialized
      slot - the slot number, 0-7
      Returns:
      a 218-byte response record
      Throws:
      IllegalArgumentException - if options too big or on encryption failure
    • encryptAEADBlock

      private static final boolean encryptAEADBlock(byte[] ad, byte[] data, SessionKey key)
      Encrypts a standard record using ChaCha/Poly. Encrypts in place. Handles standard (528) byte records only.
      Parameters:
      ad - non-null associated data (32 bytes)
      data - 528 bytes, data will be encrypted in place
      key - the session key for encryption
      Returns:
      true on success, false on encryption failure
      Throws:
      IllegalArgumentException - if data length is incorrect
    • decrypt

      public static boolean decrypt(EncryptedBuildRecord rec, SessionKey key, byte[] ad)
      Decrypts a standard ChaCha/Poly-encrypted record. ChaCha/Poly only for ECIES routers. Handles standard (528) byte records only. Decrypts in place. Status will be rec.getData()[511]. Properties will be at rec.getData()[0].
      Parameters:
      rec - 528 bytes, data will be decrypted in place
      key - the session key for decryption
      ad - non-null associated data (32 bytes)
      Returns:
      true on success, false on decryption failure
      Throws:
      IllegalArgumentException - if record length is incorrect
    • encryptAEADBlock

      private static final boolean encryptAEADBlock(byte[] ad, byte[] data, SessionKey key, int nonce)
      Encrypts a short record using ChaCha/Poly. Encrypts in place. Handles short (218) byte records only.
      Parameters:
      ad - non-null associated data (32 bytes)
      data - 218 bytes, data will be encrypted in place
      key - the session key for encryption
      nonce - the slot number, 0-7
      Returns:
      true on success, false on encryption failure
      Throws:
      IllegalArgumentException - if data length or nonce is invalid
    • decrypt

      public static boolean decrypt(EncryptedBuildRecord rec, SessionKey key, byte[] ad, int nonce)
      Decrypts a short ChaCha/Poly-encrypted record. ChaCha/Poly only for ECIES routers. Handles short (218) byte records only. Decrypts in place. Status will be rec.getData()[201]. Properties will be at rec.getData()[0].
      Parameters:
      rec - 218 bytes, data will be decrypted in place
      key - the session key for decryption
      ad - non-null associated data (32 bytes)
      nonce - the slot number, 0-7
      Returns:
      true on success, false on decryption failure
      Throws:
      IllegalArgumentException - if record length or nonce is invalid