Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Cryptix V3.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## cryptix.provider.cipher
Class Blowfish

    java.lang.Object
      |
      +--xjava.security.IJCE_Traceable
            |
            +--xjava.security.Cipher
                  |
                  +--cryptix.provider.cipher.Blowfish

public final class Blowfish
extends Cipher
implements SymmetricCipher

This class implements the Blowfish block cipher.

Blowfish was designed by Bruce Schneier. The algorithm is in the public domain.

References:

1. Bruce Schneier, "Section 14.3 Blowfish," Applied Cryptography, 2nd edition, John Wiley & Sons, 1996

2. Bruce Schneier, "Description of a New Variable-Length Key, 64-Bit Cipher (Blowfish)," Fast Software Encryption Cambridge Security Workshop Proceedings, Springer-Verlag, 1004, pp 191-204.

Copyright © 1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.8 $

Since:
  Cryptix 2.2
Author:
  Systemics Ltd, David Hopwood, Raif S. Naffah

Fields inherited from class xjava.security.Cipher
`DECRYPT, ENCRYPT, UNINITIALIZED`

Constructor Summary
`Blowfish()` Constructs a Blowfish cipher object, in the UNINITIALIZED state.

Method Summary
`java.lang.Object` | `clone()` Always throws a CloneNotSupportedException (cloning of ciphers is not supported for security reasons).
`protected int` | `engineBlockSize()` SPI: Returns the length of an input block, in bytes.
`protected java.lang.Object` | `engineGetParameter(java.lang.String param)` SPI: Gets the value of the specified algorithm parameter.
`protected void` | `engineInitDecrypt(java.security.Key key)` SPI: Initializes this cipher for decryption, using the specified key.
`protected void` | `engineInitEncrypt(java.security.Key key)` SPI: Initializes this cipher for encryption, using the specified key.
`protected void` | `engineSetParameter(java.lang.String param, java.lang.Object value)` SPI: Sets the specified algorithm parameter to the specified value.
`protected int` | `engineUpdate(byte[] in, int inOffset, int inLen, byte[] out, int outOffset)` SPI: This is the main engine method for updating data.
`protected void` | `finalize()` Cleans up resources used by this instance, if necessary.
`static LinkStatus` | `getLinkStatus()` Gets an object representing the native linking status of this class.
`int` | `getRounds()` Returns the currently set number of rounds for this instance.
`static void` | `main(java.lang.String[] args)` Entry point for very basic `self_test`.
`void` | `setRounds(int r)` Sets the number of rounds for this cipher.

Methods inherited from class xjava.security.Cipher
`blockSize, crypt, crypt, crypt, doFinal, doFinal, doFinal, doFinal, engineCiphertextBlockSize, engineCrypt, engineInBufferSize, engineOutBufferSize, enginePlaintextBlockSize, engineSetPaddingScheme, getAlgorithm, getAlgorithms, getAlgorithms, getCiphertextBlockSize, getInputBlockSize, getInstance, getInstance, getInstance, getMode, getOutputBlockSize, getPadding, getPaddingScheme, getParameter, getPlaintextBlockSize, getProvider, getState, inBufferSize, inBufferSizeFinal, initDecrypt, initEncrypt, isPaddingBlockCipher, outBufferSize, outBufferSizeFinal, setParameter, toString, update, update, update, update`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Blowfish

    public Blowfish()

  Constructs a Blowfish cipher object, in the UNINITIALIZED state. This calls the Cipher constructor with implBuffering false, implPadding false and the provider set to "Cryptix".

  We define a "rounds" property to allow running the algorithm in a number of rounds different than the default value; i.e. 16. Note however that there is not enough defined initial data for any number of rounds other than 16 for the time being.

  Throws:
    CryptixException - if a CRC check fails on the initial values of the S and P boxes.

Method Detail

### getLinkStatus

    public static LinkStatus getLinkStatus()

  Gets an object representing the native linking status of this class.

### finalize

    protected final void finalize()

  Cleans up resources used by this instance, if necessary.
  Overrides:
    finalize in class java.lang.Object

### clone

    public final java.lang.Object clone()
                                 throws java.lang.CloneNotSupportedException

  Always throws a CloneNotSupportedException (cloning of ciphers is not supported for security reasons).
  Overrides:
    clone in class Cipher
  Tags copied from class: Cipher
  Throws:
    java.lang.CloneNotSupportedException - if the cipher is not cloneable.

### engineBlockSize

    protected int engineBlockSize()

  SPI: Returns the length of an input block, in bytes.
  Overrides:
    engineBlockSize in class Cipher
  Returns:
    the length in bytes of an input block for this cipher.

### engineInitEncrypt

    protected void engineInitEncrypt(java.security.Key key)
                              throws java.security.InvalidKeyException,
                                     CryptixException

  SPI: Initializes this cipher for encryption, using the specified key.
  Overrides:
    engineInitEncrypt in class Cipher
  Parameters:
    `key` - the key to use for encryption.
  Throws:
    java.security.InvalidKeyException - when one of the following occurs:
    - key.getEncoded() == null;
    - The encoded byte array form of the key is zero-length;
    - The length of the user key data array is out of the permissible limits.
    CryptixException - if any one of the two self-tests fail. The two self-tests are as follows:
    1. encrypt 0 ten times using the initial S and P boxes values. Check the result against a known value. If equal decrypt the result 10 times and compare it to 0;
    2. complete the key expansion process and use the newly formed key to encrypt 10 times 0; decrypt the result 10 times and compare.

### engineInitDecrypt

    protected void engineInitDecrypt(java.security.Key key)
                              throws java.security.InvalidKeyException,
                                     CryptixException

  SPI: Initializes this cipher for decryption, using the specified key.
  Overrides:
    engineInitDecrypt in class Cipher
  Parameters:
    `key` - the key to use for decryption.
  Throws:
    java.security.InvalidKeyException - when one of the following occurs:
    - key.getEncoded() == null;
    - The encoded byte array form of the key is zero-length;
    - The length of the user key data array is out of the permissible limits.
    CryptixException - if any one of the two self-tests fail. The two self-tests are as follows:
    1. encrypt 0 ten times using the initial S and P boxes values. Check the result against a known value. If equal decrypt the result 10 times and compare it to 0;
    2. complete the key expansion process and use the newly formed key to encrypt 10 times 0; decrypt the result 10 times and compare.

### engineUpdate

    protected int engineUpdate(byte[] in,
                               int inOffset,
                               int inLen,
                               byte[] out,
                               int outOffset)

  SPI: This is the main engine method for updating data.

  in and out may be the same array, and the input and output regions may overlap.

  Overrides:
    engineUpdate in class Cipher
  Parameters:
    `in` - the input data.
    `inOffset` - the offset into in specifying where the data starts.
    `inLen` - the length of the subarray.
    `out` - the output array.
    `outOffset` - the offset indicating where to start writing into the out array.
  Returns:
    the number of bytes written.
  Throws:
    CryptixException - if the native library is being used, and it reports an error.

### engineSetParameter

    protected void engineSetParameter(java.lang.String param,
                                      java.lang.Object value)
                               throws java.security.InvalidParameterException,
                                      InvalidParameterTypeException

  SPI: Sets the specified algorithm parameter to the specified value.

  Blowfish has a single parameter, "rounds", which specifies the number of rounds for this instance as a decimal String.

  Overrides:
    engineSetParameter in class Cipher
  Parameters:
    `param` - the string name of the parameter.
    `value` - the parameter value.
  Throws:
    java.security.InvalidParameterException - if param is an invalid parameter for this cipher implementation, the parameter is already set and cannot be set again, a security exception occurs, and so on.
    InvalidParameterTypeException - if value is of the wrong type.

### engineGetParameter

    protected java.lang.Object engineGetParameter(java.lang.String param)

  SPI: Gets the value of the specified algorithm parameter.

  Blowfish has a single parameter, "rounds", which specifies the number of rounds for this instance as a decimal String.

  Overrides:
    engineGetParameter in class Cipher
  Parameters:
    `param` - the string name of the parameter.
  Returns:
    the object that represents the parameter value, or null if there is none.

### setRounds

    public void setRounds(int r)

  Sets the number of rounds for this cipher. Allowed only when this cipher is in the UNINITIALIZED state; otherwise an exception is thrown.

  If the specified number is invalid, an IllegalArgumentException is thrown.

  Note that there is not enough defined initial data for any number of rounds other than 16 for the time being.

  Parameters:
    `r` - the desired number of rounds for this cipher.
  Throws:
    java.lang.IllegalArgumentException - if the given number of rounds is not supported.

### getRounds

    public int getRounds()

  Returns the currently set number of rounds for this instance.
  Returns:
    the number of rounds.

### main

    public static void main(java.lang.String[] args)

  Entry point for very basic `self_test`.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Cryptix V3.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) 1995-2000 The Cryptix Foundation Ltd. All rights reserved.