ccs.crypt
Class NullCipher

java.lang.Object
  extended by ccs.crypt.Cipher
      extended by ccs.crypt.AbstractBlockCipher
          extended by ccs.crypt.NullCipher

public class NullCipher
extends AbstractBlockCipher

A Null Cipher. Its output is identical to its input, except that the "ciphertext" has an Adler32 checksum appended to it. Useful as a placeholder in situations where you might want encryption or you might not - use the same code in each, but make your Cipher a real Cipher for encryption and a NullCipher for no encryption.


Field Summary
 
Fields inherited from class ccs.crypt.AbstractBlockCipher
buffer
 
Fields inherited from class ccs.crypt.Cipher
passwd
 
Constructor Summary
NullCipher()
           
 
Method Summary
protected  void bufferDecrypt(int nblocks)
          Decrypt the number of blocks specified from the internal buffer, updating the MAC with the result.
protected  void bufferEncrypt(int nblocks)
          Encrypt the number of blocks specified from the internal buffer, updating the MAC with the result.
 int getBlockSizeExp()
          The logarithm to base 2 of the block size of the cipher in bytes.
protected  int getHeaderLength()
          The size of the header, without any self-delimitation info.
 CipherInputStream getInputStream(java.io.InputStream is, boolean isSelfDelimit)
          Returns a CipherInputStream that reads ciphertext from the underlying stream and provides plaintext.
protected  byte[] getMAC()
          Obtain the MAC for the stream.
protected  int getMACLength()
          The size of the MAC.
 CipherOutputStream getOutputStream(java.io.OutputStream os, long plainlen)
          Returns a CipherOutputStream that accepts plaintext and writes ciphertext to the underlying stream.
 byte[] getPasswd()
          returns the password, which is null.
protected  void getWhitening(byte[] buf)
          Produce and return 8 bytes (exactly) of "whitening".
 void setPasswd(byte[] pw)
          Sets the password, which is ignored completely.
 
Methods inherited from class ccs.crypt.AbstractBlockCipher
checkRegistered, getCiphertextLength, getPlaintextLength, getTrailerLength, register, unregister
 
Methods inherited from class ccs.crypt.Cipher
out
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NullCipher

public NullCipher()
Method Detail

setPasswd

public void setPasswd(byte[] pw)
Sets the password, which is ignored completely.

Overrides:
setPasswd in class Cipher
Parameters:
pw - The password to be neglected.

getPasswd

public byte[] getPasswd()
returns the password, which is null.

Overrides:
getPasswd in class Cipher
Returns:
null.

getOutputStream

public CipherOutputStream getOutputStream(java.io.OutputStream os,
                                          long plainlen)
                                   throws CipherException,
                                          java.io.IOException
Returns a CipherOutputStream that accepts plaintext and writes ciphertext to the underlying stream.

Specified by:
getOutputStream in class Cipher
Parameters:
os - The stream to write ciphertext to.
plainlen - The length of plaintext to be written. If known, this allows the length to be encrypted as part of the stream itself, and makes the ciphertext self-delimiting; where many ciphertexts are concatenated onto a stream, no boundary sequences are required in this mode, which is preferable. (Such sequences leak information.) In this case, you send exactly the amount of plaintext you specify, no more, no less. Supply -1 if you really don't know; in this case, you must delimit the ciphertext yourself.
Throws:
CipherException - if a cryptographic problem occurs.
java.io.IOException - if the CipherOutputStream could not be created for some reason.

getInputStream

public CipherInputStream getInputStream(java.io.InputStream is,
                                        boolean isSelfDelimit)
                                 throws CipherException,
                                        java.io.IOException
Returns a CipherInputStream that reads ciphertext from the underlying stream and provides plaintext.

Specified by:
getInputStream in class Cipher
Parameters:
is - The stream to read ciphertext from.
isSelfDelimit - Whether the ciphertext is self-delimiting, ie. it has its own length stored inside itself. If not, the ciphertext is assumed to extend to EOF.
Throws:
CipherException - if a cryptographic problem occurs.
java.io.IOException - if the CipherInputStream could not be created for some reason.

getWhitening

protected void getWhitening(byte[] buf)
Produce and return 8 bytes (exactly) of "whitening". This should be random-looking but reproducible material which does not depend directly on the key, and can be calculated from the ciphertext header alone. (For CBC-mode ciphers, this header is typically just the IV, and the whitening is typically based on a hash of that IV). This whitening is used in self-delimiting cpihertext streams to obscure the stream length data; actually encrypting it causes too many problems in the event that a user innocently gets the wrong password. Whitening is requested immediately after the header is written (encrypt) or read(decrypt).

Specified by:
getWhitening in class AbstractBlockCipher
Parameters:
buf - The buffer into the first 8 bytes of which the whitening should be placed.

bufferEncrypt

protected void bufferEncrypt(int nblocks)
Encrypt the number of blocks specified from the internal buffer, updating the MAC with the result.

Specified by:
bufferEncrypt in class AbstractBlockCipher

bufferDecrypt

protected void bufferDecrypt(int nblocks)
Decrypt the number of blocks specified from the internal buffer, updating the MAC with the result.

Specified by:
bufferDecrypt in class AbstractBlockCipher

getMAC

protected byte[] getMAC()
Obtain the MAC for the stream. This will only be called once for a given message.

Specified by:
getMAC in class AbstractBlockCipher

getBlockSizeExp

public int getBlockSizeExp()
The logarithm to base 2 of the block size of the cipher in bytes. Eg. a 64-bit block cipher should return 3.

Specified by:
getBlockSizeExp in class AbstractBlockCipher

getHeaderLength

protected int getHeaderLength()
Description copied from class: AbstractBlockCipher
The size of the header, without any self-delimitation info. Typically this header is just the IV (in CBC mode) and is easy to calculate the length of.

Specified by:
getHeaderLength in class AbstractBlockCipher

getMACLength

protected int getMACLength()
Description copied from class: AbstractBlockCipher
The size of the MAC. Typically this is a constant.

Specified by:
getMACLength in class AbstractBlockCipher