java.lang.Object
net.i2p.crypto.AESEngine
Direct Known Subclasses:
CryptixAESEngine

public class AESEngineextends Object
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

    Fields
    Modifier and Type
    Field
    Description
    protected final I2PAppContext
    I2P application context.
    protected final Log
    Logger instance.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for subclasses.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    decrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int length)
    Decrypt the data with the session key.
    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.
    void
    decryptBlock(byte[] payload, int inIndex, SessionKey sessionKey, byte[] rv, int outIndex)
    This just copies payload to rv, see extension for the real thing.
    void
    encrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int length)
    Encrypt the payload with the session key.
    void
    encrypt(byte[] payload, int payloadIndex, byte[] out, int outIndex, SessionKey sessionKey, byte[] iv, int ivOffset, int length)
    Encrypt payload with session key.
    void
    encryptBlock(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 minPaddedSize
    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 minPaddedSize
    byte[]
    safeDecrypt(byte[] payload, SessionKey sessionKey, byte[] iv)
    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.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _log

      protected final Log _log
      Logger instance.
    • _context

      protected final I2PAppContext _context
      I2P application context.
  • Constructor Details

    • AESEngine

      protected AESEngine(I2PAppContext ctx)
      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 encrypted
      payloadIndex - index into the payload to start encrypting
      out - where to store the result
      outIndex - where in out to start writing
      sessionKey - private esession key to encrypt to
      iv - IV for CBC, must be 16 bytes
      length - 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 encrypted
      payloadIndex - index into payload to start encrypting
      out - where to store result
      outIndex - where in out to start writing
      sessionKey - private session key to encrypt to
      iv - IV for CBC
      ivOffset - offset into IV
      length - how much data to encrypt
    • safeEncrypt

      public 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.
      Parameters:
      payload - data to be encrypted
      sessionKey - session key for encryption
      iv - IV for CBC, must be 16 bytes
      paddedSize - minimum size of output
      Returns:
      encrypted data or null on error Obsolete — prefer encrypt(byte[], int, byte[], int, SessionKey, byte[], int).
    • safeDecrypt

      public byte[] safeDecrypt(byte[] payload, SessionKey sessionKey, byte[] iv)
      See safeEncrypt(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 decrypted
      sessionKey - session key for decryption
      iv - 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 decrypted
      payloadIndex - index into the payload to start decrypting
      out - where to store the cleartext
      outIndex - where in out to start writing
      sessionKey - private session key to decrypt to
      iv - IV for CBC
      length - 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 decrypted
      payloadIndex - index into the payload to start decrypting
      out - where to store the cleartext
      outIndex - where in out to start writing
      sessionKey - private session key to decrypt to
      iv - IV for CBC
      ivOffset - offset into IV
      length - 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 encrypt
      inIndex - starting index in payload
      sessionKey - the private session key, unused because this base class only copies
      out - buffer receiving the copy, filled from outIndex to its end
      outIndex - 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 class
      inIndex - starting index in payload
      sessionKey - private session key
      rv - buffer receiving the copy, filled from outIndex to its end
      outIndex - starting index in output
    • getPadding

      public 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 minPaddedSize

      Public for ElGamalAESEngine. Not a public API, not for external use.

      Parameters:
      context - I2P application context
      curSize - current data size
      minPaddedSize - 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 minPaddedSize

      Public for ElGamalAESEngine. Not a public API, not for external use.

      Parameters:
      curSize - current data size
      minPaddedSize - minimum padded size
      Returns:
      padding size required