java.lang.Object
net.i2p.crypto.AESEngine
- Direct Known Subclasses:
CryptixAESEngine
Abstract base class for AES cipher operations in I2P.
This class provides the interface and common functionality for AES encryption and decryption operations. The base implementation contains placeholder methods that log warnings when called. The actual AES implementation is provided by CryptixAESEngine which extends this class.
This design pattern allows for:
- Consistent API across different AES implementations
- Graceful fallback when AES is unavailable
- Easy swapping of underlying AES providers
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final I2PAppContextI2P application context.protected final LogLogger instance.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoiddecrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int length) Decrypt the data with the session key.voiddecrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int ivOffset, int length) Decrypt the data with the session key.voiddecryptBlock(byte[] payload, int inIndex, SessionKey sessionKey, byte[] rv, int outIndex) This just copies payload to rv, see extension for the real thing.voidencrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int length) Encrypt the payload with the session key.voidencrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int ivOffset, int length) Encrypt payload with session key.voidencryptBlock(byte[] payload, int inIndex, SessionKey sessionKey, byte[] out, int outIndex) This just copies payload to out, see extension for the real thing.static final byte[]getPadding(I2PAppContext context, int curSize, long minPaddedSize) Return random bytes for padding the data to a mod 16 size so that it is at least minPaddedSizestatic final intgetPaddingSize(int curSize, long minPaddedSize) Return size for padding the data to a mod 16 size so that it is at least minPaddedSizebyte[]safeDecrypt(byte[] payload, SessionKey sessionKey, byte[] iv) SeesafeEncrypt(byte[], SessionKey, byte[], int)for description.byte[]safeEncrypt(byte[] payload, SessionKey sessionKey, byte[] iv, int paddedSize) Encrypt SHA-256 Hash of IV, 4 byte length, and payload, with random padding up to paddedSize, rounded up to next multiple of 16.
Field Details
_log
Logger instance._context
I2P application context.
Constructor Details
AESEngine
Constructor for subclasses.- Parameters:
ctx- I2P application context
Method Details
encrypt
public void encrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int length) Encrypt the payload with the session key.- Parameters:
payload- data to be encryptedpayloadIndex- index into the payload to start encryptingout- where to store the resultoutIndex- where in out to start writingsessionKey- private esession key to encrypt toiv- IV for CBC, must be 16 byteslength- how much data to encrypt
encrypt
public void encrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int ivOffset, int length) Encrypt payload with session key. This just copies payload to out, see extension for the real thing.- Parameters:
payload- data to be encryptedpayloadIndex- index into payload to start encryptingout- where to store resultoutIndex- where in out to start writingsessionKey- private session key to encrypt toiv- IV for CBCivOffset- offset into IVlength- how much data to encrypt
safeEncrypt
Encrypt SHA-256 Hash of IV, 4 byte length, and payload, with random padding up to paddedSize, rounded up to next multiple of 16.- Parameters:
payload- data to be encryptedsessionKey- session key for encryptioniv- IV for CBC, must be 16 bytespaddedSize- minimum size of output- Returns:
- encrypted data or null on error Obsolete — prefer encrypt(byte[], int, byte[], int, SessionKey, byte[], int).
safeDecrypt
SeesafeEncrypt(byte[], SessionKey, byte[], int)for description. WARNING - no check for maximum length here, OOM DOS possible, fix it if you're going to use this.- Parameters:
payload- data to be decryptedsessionKey- session key for decryptioniv- IV for CBC, must be 16 bytes- Returns:
- decrypted data or null on error Obsolete — prefer decrypt(byte[], int, byte[], int, SessionKey, byte[], int).
decrypt
public void decrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int length) Decrypt the data with the session key.- Parameters:
payload- data to be decryptedpayloadIndex- index into the payload to start decryptingout- where to store the cleartextoutIndex- where in out to start writingsessionKey- private session key to decrypt toiv- IV for CBClength- how much data to decrypt
decrypt
public void decrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int ivOffset, int length) Decrypt the data with the session key. This just copies payload to out, see extension for the real thing.- Parameters:
payload- data to be decryptedpayloadIndex- index into the payload to start decryptingout- where to store the cleartextoutIndex- where in out to start writingsessionKey- private session key to decrypt toiv- IV for CBCivOffset- offset into IVlength- how much data to decrypt
encryptBlock
public void encryptBlock(byte[] payload, int inIndex, SessionKey sessionKey, byte[] out, int outIndex) This just copies payload to out, see extension for the real thing.- Parameters:
payload- data to encryptinIndex- starting index in payloadsessionKey- the private session key, unused because this base class only copiesout- buffer receiving the copy, filled fromoutIndexto its endoutIndex- starting index in output
decryptBlock
public void decryptBlock(byte[] payload, int inIndex, SessionKey sessionKey, byte[] rv, int outIndex) This just copies payload to rv, see extension for the real thing.- Parameters:
payload- encrypted data, copied through unchanged by this base classinIndex- starting index in payloadsessionKey- private session keyrv- buffer receiving the copy, filled fromoutIndexto its endoutIndex- starting index in output
getPadding
Return random bytes for padding the data to a mod 16 size so that it is at least minPaddedSizePublic for ElGamalAESEngine. Not a public API, not for external use.
- Parameters:
context- I2P application contextcurSize- current data sizeminPaddedSize- minimum padded size- Returns:
- random bytes to append, as many as
getPaddingSize(int, long)requires
getPaddingSize
public static final int getPaddingSize(int curSize, long minPaddedSize) Return size for padding the data to a mod 16 size so that it is at least minPaddedSizePublic for ElGamalAESEngine. Not a public API, not for external use.
- Parameters:
curSize- current data sizeminPaddedSize- minimum padded size- Returns:
- padding size required