net.i2p.crypto

## Class AESEngine

- java.lang.Object
- - net.i2p.crypto.AESEngine

- Direct Known Subclasses:
    CryptixAESEngine

      public class AESEngine
      extends 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:
    `CryptixAESEngine`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected I2PAppContext` | `_context` I2P application context
    `protected Log` | `_log` Logger instance

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AESEngine(I2PAppContext ctx)` Constructor for subclasses.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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 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.
    `static 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _context

          protected final I2PAppContext _context

      I2P application context

    - #### _log

          protected final Log _log

      Logger instance

  - ### Constructor Detail

    - #### AESEngine

          protected AESEngine(I2PAppContext ctx)

      Constructor for subclasses.
      Parameters:
        `ctx` - I2P application context

  - ### Method Detail

    - #### 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

    - #### 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
        `inIndex` - starting index in payload
        `sessionKey` - private session key
        `rv` - output buffer
        `outIndex` - starting index in output

    - #### 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

    - #### 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` - unused
        `out` - output buffer
        `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:
        padding bytes

    - #### 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