java.lang.Object
net.i2p.crypto.CryptixRijndael_Algorithm

public final class CryptixRijndael_Algorithmextends Object
Rijndael AES algorithm implementation. Supports 128, 192, and 256-bit keys with 128-bit block size.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int[]
    Table mapping an exponent to a field element.
    private static final int
    Block size of the cipher, in bytes.
    private static final int[]
    Table mapping a field element to its exponent.
    private static final byte[]
    The round constants.
    private static final byte[]
    The forward S-box.
    private static final int[][][]
    The row shift offsets, by key length.
    private static final byte[]
    The inverse S-box.
    private static final int[]
    Forward round table 1.
    private static final int[]
    Forward round table 2.
    private static final int[]
    Forward round table 3.
    private static final int[]
    Forward round table 4.
    private static final int[]
    Forward round table 5.
    private static final int[]
    Forward round table 6.
    private static final int[]
    Forward round table 7.
    private static final int[]
    Forward round table 8.
    private static final int[]
    Inverse round table 1.
    private static final int[]
    Inverse round table 2.
    private static final int[]
    Inverse round table 3.
    private static final int[]
    Inverse round table 4.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Utility class of static methods; not instantiable.
  • Method Summary

    Modifier and Type
    Method
    Description
    static final void
    blockDecrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey)
    Convenience method to decrypt exactly one block of plaintext, assuming Rijndael's default block size (128-bit).
    static final void
    blockDecrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey, int blockSize)
    Decrypt exactly one block of ciphertext.
    static final void
    blockEncrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey)
    Convenience method to encrypt exactly one block of plaintext, assuming Rijndael's default block size (128-bit).
    static final void
    blockEncrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey, int blockSize)
    Encrypt exactly one block of plaintext.
    static final int
    Default input block length for Rijndael.
    static final int
    getRounds(int keySize, int blockSize)
    Return The number of rounds for a given Rijndael's key and block sizes.
    static final Object
    makeKey(byte[] k)
    Convenience method to expand a user-supplied key material into a session key, assuming Rijndael's default block size (128-bit).
    static final Object
    makeKey(byte[] k, int blockSize)
    Expand a user-supplied key material into a session key.
    static final Object
    makeKey(byte[] k, int blockSize, CryptixAESKeyCache.KeyCacheEntry keyData)
    Expand a user-supplied key material into a session key.
    private static final int
    mul(int a, int b)
    Multiplies two elements in GF(2^8).
    private static final int
    mul4(int a, byte[] b)
    Multiplies an element by a four byte value.

    Methods inherited from class Object

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

    • _BLOCK_SIZE

      private static final int _BLOCK_SIZE
      Block size of the cipher, in bytes.
      See Also:
    • _alog

      private static final int[] _alog
      Table mapping an exponent to a field element.
    • _log

      private static final int[] _log
      Table mapping a field element to its exponent.
    • _S

      private static final byte[] _S
      The forward S-box.
    • _Si

      private static final byte[] _Si
      The inverse S-box.
    • _T1

      private static final int[] _T1
      Forward round table 1.
    • _T2

      private static final int[] _T2
      Forward round table 2.
    • _T3

      private static final int[] _T3
      Forward round table 3.
    • _T4

      private static final int[] _T4
      Forward round table 4.
    • _T5

      private static final int[] _T5
      Forward round table 5.
    • _T6

      private static final int[] _T6
      Forward round table 6.
    • _T7

      private static final int[] _T7
      Forward round table 7.
    • _T8

      private static final int[] _T8
      Forward round table 8.
    • _U1

      private static final int[] _U1
      Inverse round table 1.
    • _U2

      private static final int[] _U2
      Inverse round table 2.
    • _U3

      private static final int[] _U3
      Inverse round table 3.
    • _U4

      private static final int[] _U4
      Inverse round table 4.
    • _rcon

      private static final byte[] _rcon
      The round constants.
    • _shifts

      private static final int[][][] _shifts
      The row shift offsets, by key length.
  • Constructor Details

    • CryptixRijndael_Algorithm

      private CryptixRijndael_Algorithm()
      Utility class of static methods; not instantiable.
  • Method Details

    • mul

      private static final int mul(int a, int b)
      Multiplies two elements in GF(2^8).
      Parameters:
      a - the first element
      b - the second element
      Returns:
      the field product
    • mul4

      private static final int mul4(int a, byte[] b)
      Multiplies an element by a four byte value.
      Parameters:
      a - the element to multiply by
      b - the four bytes to multiply
      Returns:
      the packed product
    • makeKey

      public static final Object makeKey(byte[] k) throws InvalidKeyException
      Convenience method to expand a user-supplied key material into a session key, assuming Rijndael's default block size (128-bit).
      Parameters:
      k - The 128/192/256-bit user-key to use.
      Returns:
      an array of two int[][] containing { Ke, Kd }
      Throws:
      InvalidKeyException - If the key is invalid.
    • blockEncrypt

      public static final void blockEncrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey)
      Convenience method to encrypt exactly one block of plaintext, assuming Rijndael's default block size (128-bit).
      Parameters:
      in - The plaintext; must hold at least 16 bytes past inOffset.
      result - The resulting ciphertext.
      inOffset - Index of in from which to start considering data.
      outOffset - Index in result at which to start writing data.
      sessionKey - The session key to use for encryption. This is a CryptixAESKeyCache.KeyCacheEntry. We use the Ke field for encryption. The actual parameter type is opaque, changed in 0.9.31, and is subject to change again.
    • blockDecrypt

      public static final void blockDecrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey)
      Convenience method to decrypt exactly one block of plaintext, assuming Rijndael's default block size (128-bit).
      Parameters:
      in - The ciphertext; must hold at least 16 bytes past inOffset.
      result - The resulting ciphertext.
      inOffset - Index of in from which to start considering data.
      outOffset - Index in result at which to start writing data.
      sessionKey - The session key to use for decryption. This is a CryptixAESKeyCache.KeyCacheEntry. We use the Kd field, for decryption. The actual parameter type is opaque, changed in 0.9.31, and is subject to change again.
    • blockSize

      public static final int blockSize()
      Default input block length for Rijndael.
      Returns:
      The default length in bytes of the Algorithm input block.
    • makeKey

      public static final Object makeKey(byte[] k, int blockSize) throws InvalidKeyException
      Expand a user-supplied key material into a session key.
      Parameters:
      k - The 128/192/256-bit user-key to use.
      blockSize - The block size in bytes of this Rijndael, must be 16, 24, or 32.
      Returns:
      a CryptixAESKeyCache.KeyCacheEntry containing { Ke, Kd }. The actual return type is opaque, changed in 0.9.31, and is subject to change again.
      Throws:
      InvalidKeyException - If the key is invalid.
    • makeKey

      public static final Object makeKey(byte[] k, int blockSize, CryptixAESKeyCache.KeyCacheEntry keyData) throws InvalidKeyException
      Expand a user-supplied key material into a session key. Not for external use, not a public API.
      Parameters:
      k - The 128/192/256-bit user-key to use.
      blockSize - The block size in bytes of this Rijndael, must be 16, 24, or 32.
      keyData - a cached data structure to fill in, or null.
      Returns:
      a CryptixAESKeyCache.KeyCacheEntry containing { Ke, Kd }. If keyData is non-null, this is keyData. If keyData is null, this is newly allocated.
      Throws:
      InvalidKeyException - If the key is invalid.
    • blockEncrypt

      public static final void blockEncrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey, int blockSize)
      Encrypt exactly one block of plaintext.
      Parameters:
      in - The plaintext; must hold at least 16 bytes past inOffset.
      result - The resulting ciphertext.
      inOffset - Index of in from which to start considering data.
      outOffset - Index in result at which to start writing data.
      sessionKey - The session key to use for encryption. This is a CryptixAESKeyCache.KeyCacheEntry. We use the Ke field for encryption. The actual parameter type is opaque, changed in 0.9.31, and is subject to change again.
      blockSize - The block size in bytes of this Rijndael.
    • blockDecrypt

      public static final void blockDecrypt(byte[] in, byte[] result, int inOffset, int outOffset, Object sessionKey, int blockSize)
      Decrypt exactly one block of ciphertext.
      Parameters:
      in - The ciphertext; must hold at least 16 bytes past inOffset.
      result - The resulting ciphertext.
      inOffset - Index of in from which to start considering data.
      outOffset - Index in result at which to start writing data.
      sessionKey - The session key to use for decryption. This is a CryptixAESKeyCache.KeyCacheEntry. We use the Kd field, for decryption. The actual parameter type is opaque, changed in 0.9.31, and is subject to change again.
      blockSize - The block size in bytes of this Rijndael.
    • getRounds

      public static final int getRounds(int keySize, int blockSize)
      Return The number of rounds for a given Rijndael's key and block sizes.
      Parameters:
      keySize - The size of the user key material in bytes.
      blockSize - The desired block size in bytes.
      Returns:
      The number of rounds for a given Rijndael's key and block sizes.