Cumulus4j API
(1.0.0)

org.cumulus4j.crypto.internal.symmetric
Class BufferedBlockCipherImpl

java.lang.Object
  extended by org.cumulus4j.crypto.AbstractCipher
      extended by org.cumulus4j.crypto.internal.symmetric.BufferedBlockCipherImpl
All Implemented Interfaces:
Cipher

public class BufferedBlockCipherImpl
extends AbstractCipher

Author:
Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de

Constructor Summary
BufferedBlockCipherImpl(String transformation, BufferedBlockCipher delegate)
           
 
Method Summary
 void _init(CipherOperationMode mode, CipherParameters parameters)
           
 int doFinal(byte[] out, int outOff)
          Process the last block in the buffer.
 int getInputBlockSize()
          Get the input block size for this cipher (in bytes).
 int getIVSize()
          Get the required size of the IV (in bytes).
 int getOutputBlockSize()
          Get the output block size for this cipher (in bytes).
 int getOutputSize(int length)
          Return the size of the output buffer required for an update plus a doFinal with an input of length bytes.
 int getUpdateOutputSize(int len)
          Return the size of the output buffer required for an update of an input of length bytes.
 void reset()
          Reset this cipher.
 int update(byte[] in, int inOff, int len, byte[] out, int outOff)
           Update this cipher with multiple bytes.
 int update(byte in, byte[] out, int outOff)
           Update this cipher with a single byte.
 
Methods inherited from class org.cumulus4j.crypto.AbstractCipher
doFinal, getMode, getParameters, getTransformation, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedBlockCipherImpl

public BufferedBlockCipherImpl(String transformation,
                               BufferedBlockCipher delegate)
Method Detail

_init

public void _init(CipherOperationMode mode,
                  CipherParameters parameters)
           throws IllegalArgumentException
Specified by:
_init in class AbstractCipher
Throws:
IllegalArgumentException

getInputBlockSize

public int getInputBlockSize()
Description copied from interface: Cipher
Get the input block size for this cipher (in bytes). If this is a symmetric cipher, this equals Cipher.getOutputBlockSize().

Returns:
the input block size for this cipher in bytes.

getOutputBlockSize

public int getOutputBlockSize()
Description copied from interface: Cipher
Get the output block size for this cipher (in bytes). If this is a symmetric cipher, this equals Cipher.getInputBlockSize().

Returns:
the output block size for this cipher in bytes.

reset

public void reset()
Description copied from interface: Cipher
Reset this cipher. After resetting, the state is the same as if it was just freshly initialised.


getUpdateOutputSize

public int getUpdateOutputSize(int len)
Description copied from interface: Cipher
Return the size of the output buffer required for an update of an input of length bytes.

Parameters:
len - the size of the input (in bytes) that is to be passed to Cipher.update(byte[], int, int, byte[], int).
Returns:
the required length of the output buffer in bytes.

getOutputSize

public int getOutputSize(int length)
Description copied from interface: Cipher
Return the size of the output buffer required for an update plus a doFinal with an input of length bytes.

Parameters:
length - the size of the input (in bytes) that is to be passed to Cipher.update(byte[], int, int, byte[], int).
Returns:
the required length of the output buffer in bytes.

update

public int update(byte in,
                  byte[] out,
                  int outOff)
           throws DataLengthException,
                  IllegalStateException,
                  CryptoException
Description copied from interface: Cipher

Update this cipher with a single byte. This is synonymous to calling Cipher.update(byte[], int, int, byte[], int) with an in byte array of length 1 and inOff = 0 and inLen = 1.

Note that data might still be unprocessed in this cipher when this method returns. That is because many ciphers work with blocks and keep a block unprocessed until it is filled up. Call Cipher.doFinal(byte[], int) after you finished updating this cipher (i.e. all input was passed completely).

Parameters:
in - the input to be encrypted or decrypted (or a part of the input).
out - the buffer receiving the output (data is written into this byte-array). Must not be null.
outOff - the array-index in out at which to start writing. Must be >=0.
Returns:
the number of bytes written into out.
Throws:
DataLengthException - if the buffer out is insufficient.
IllegalStateException - if this cipher has not yet been initialised.
CryptoException - if there is a cryptographic error happening while processing the input. For example when decrypting a padding might be wrong or an authenticating block mode (like GCM) might recognize that the ciphertext has been manipulated/corrupted.
See Also:
Cipher.update(byte[], int, int, byte[], int), Cipher.doFinal(byte[], int)

update

public int update(byte[] in,
                  int inOff,
                  int len,
                  byte[] out,
                  int outOff)
           throws DataLengthException,
                  IllegalStateException,
                  CryptoException
Description copied from interface: Cipher

Update this cipher with multiple bytes.

Note that data might still be unprocessed in this cipher when this method returns. That is because many ciphers work with blocks and keep a block unprocessed until it is filled up. Call Cipher.doFinal(byte[], int) after you finished updating this cipher (i.e. all input was passed completely).

Parameters:
in - the input to be encrypted or decrypted (or a part of the input). Must not be null.
inOff - the array-index in in at which to start reading. Must be >=0.
len - the number of bytes that should be read from in.
out - the buffer receiving the output (data is written into this byte-array). Must not be null.
outOff - the array-index in out at which to start writing. Must be >=0.
Returns:
the number of bytes written into out.
Throws:
DataLengthException - if the buffer out is insufficient or if inOff + inLen exceeds the input byte array.
IllegalStateException - if this cipher has not yet been initialised.
CryptoException - if there is a cryptographic error happening while processing the input. For example when decrypting a padding might be wrong or an authenticating block mode (like GCM) might recognize that the ciphertext has been manipulated/corrupted.
See Also:
Cipher.update(byte, byte[], int), Cipher.doFinal(byte[], int)

doFinal

public int doFinal(byte[] out,
                   int outOff)
            throws DataLengthException,
                   IllegalStateException,
                   CryptoException
Description copied from interface: Cipher
Process the last block in the buffer. After this call, no unprocessed data is left in this cipher and it is Cipher.reset() implicitly.

Parameters:
out - the buffer receiving the output (data is written into this byte-array). Must not be null.
outOff - the array-index in out at which to start writing. Must be >=0.
Returns:
the number of bytes written into out.
Throws:
DataLengthException - if the buffer out is insufficient or if inOff + inLen exceeds the input byte array.
IllegalStateException - if this cipher has not yet been initialised.
CryptoException - if there is a cryptographic error happening while processing the input. For example when decrypting a padding might be wrong or an authenticating block mode (like GCM) might recognize that the ciphertext has been manipulated/corrupted.
See Also:
Cipher.update(byte, byte[], int), Cipher.update(byte[], int, int, byte[], int), Cipher.doFinal(byte[])

getIVSize

public int getIVSize()
Description copied from interface: Cipher
Get the required size of the IV (in bytes). If a cipher supports multiple sizes, this is the optimal (most secure) IV size. If the cipher supports no IV, this is 0.

Returns:
the required size of the IV.

Cumulus4j API
(1.0.0)

Copyright © 2012 NightLabs Consulting GmbH. All Rights Reserved.