java.lang.Object
net.i2p.data.i2np.BuildResponseRecord
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 Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic EncryptedBuildRecordcreate(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyIV, long responseMessageId) Creates a new AES-encrypted response record.static EncryptedBuildRecordcreate(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyAD, Properties options) Creates a new ChaCha/Poly-encrypted response record (long format).static ShortEncryptedBuildRecordcreateShort(I2PAppContext ctx, int status, SessionKey replyKey, byte[] replyAD, Properties options, int slot) Creates a new ChaCha/Poly-encrypted response record (short format).static booleandecrypt(EncryptedBuildRecord rec, SessionKey key, byte[] ad) Decrypts a standard ChaCha/Poly-encrypted record.static booleandecrypt(EncryptedBuildRecord rec, SessionKey key, byte[] ad, int nonce) Decrypts a short ChaCha/Poly-encrypted record.private static final booleanencryptAEADBlock(byte[] ad, byte[] data, SessionKey key) Encrypts a standard record using ChaCha/Poly.private static final booleanencryptAEADBlock(byte[] ad, byte[] data, SessionKey key, int nonce) Encrypts a short record using ChaCha/Poly.
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 contextstatus- the response 0-255replyKey- the session key for reply encryptionreplyIV- 16 bytes IVresponseMessageId- 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 contextstatus- the response 0-255replyKey- the session key for reply encryptionreplyAD- 32 bytes associated dataoptions- 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 contextstatus- the response 0-255replyKey- the session key for reply encryptionreplyAD- 32 bytes associated dataoptions- 116 bytes max when serializedslot- the slot number, 0-7- Returns:
- a 218-byte response record
- Throws:
IllegalArgumentException- if options too big or on encryption failure
encryptAEADBlock
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 placekey- the session key for encryption- Returns:
- true on success, false on encryption failure
- Throws:
IllegalArgumentException- if data length is incorrect
decrypt
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 placekey- the session key for decryptionad- non-null associated data (32 bytes)- Returns:
- true on success, false on decryption failure
- Throws:
IllegalArgumentException- if record length is incorrect
encryptAEADBlock
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 placekey- the session key for encryptionnonce- the slot number, 0-7- Returns:
- true on success, false on encryption failure
- Throws:
IllegalArgumentException- if data length or nonce is invalid
decrypt
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 placekey- the session key for decryptionad- 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