org.logi.crypto.keys
Class BlowfishKey

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.keys.K
              |
              +--org.logi.crypto.keys.SymmetricKey
                    |
                    +--org.logi.crypto.keys.BlowfishKey
All Implemented Interfaces:
CipherKey, Key

public class BlowfishKey
extends SymmetricKey
implements CipherKey

This is the class for Blowfish keys. It is a feistel blockcipher with a 64-bit block size and variable key-size. It was designed by Bruce Schneier and is in the public domain. (This implementation is licensed in the same way as the rest of the logi.crypto package.)

This implementation was made from the description given in Schneier's book Applied Cryptography.

The CDS for a Blowfish key is BlowfishKey(key) with key a string of hexadecimal digits to create a specific key or BlowfishKey(?) for a random BlowfishKey object.

Author:
Logi Ragnarsson (logir@logi.org)

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Constructor Summary
BlowfishKey()
          Create a new random 448 bit Blowfish key.
BlowfishKey(byte[] key)
          Create a new Blowfish key with the key bits from key.
BlowfishKey(int n)
          Create a new random n-bit Blowfish key.
 
Method Summary
 int cipherBlockSize()
          The block-size for the Blowfish cipher is 8 bytes.
 void decrypt(byte[] source, int i, byte[] dest, int j)
          Decrypt one block of data.
 void encrypt(byte[] source, int i, byte[] dest, int j)
          Encrypt one block of data.
 boolean equals(java.lang.Object o)
          Return true iff the two keys are equivalent.
 java.lang.String getAlgorithm()
          The name of the algorithm is "Blowfish".
 byte[] getKey()
          Return the key-bits for this key as an array of bytes.
 int getSize()
          Return the size of this key.
static BlowfishKey parseCDS(java.lang.String key)
          If "BlowfishKey( key )" is a valid CDS for a BlowfishKey, then BlowfishKey.parseCDS(key) will return the described BlowfishKey object.
 int plainBlockSize()
          The block-size for the Blowfish cipher is 8 bytes.
 java.lang.String toString()
          Return a CDS for this key.
 
Methods inherited from class org.logi.crypto.keys.SymmetricKey
isPrivate, matches
 
Methods inherited from class org.logi.crypto.keys.K
getFingerprint, getFingerprint, hashCode, matchFingerprint, matchFingerprint
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, readBlock, readInt, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.logi.crypto.keys.Key
getFingerprint, getFingerprint, hashCode, isPrivate, matches, matchFingerprint, matchFingerprint
 

Constructor Detail

BlowfishKey

public BlowfishKey(int n)
Create a new random n-bit Blowfish key. The size will be rounded up to the next multiple of 8.

BlowfishKey

public BlowfishKey()
Create a new random 448 bit Blowfish key.

BlowfishKey

public BlowfishKey(byte[] key)
Create a new Blowfish key with the key bits from key.
Method Detail

parseCDS

public static BlowfishKey parseCDS(java.lang.String key)
                            throws InvalidCDSException
If "BlowfishKey( key )" is a valid CDS for a BlowfishKey, then BlowfishKey.parseCDS(key) will return the described BlowfishKey object.

A valid CDS can be created by calling the BlowfishKey.toString() method.

Throws:
InvalidCDSException - if the CDS is malformed.
See Also:
Crypto.fromString(String)

plainBlockSize

public int plainBlockSize()
The block-size for the Blowfish cipher is 8 bytes.
Specified by:
plainBlockSize in interface CipherKey

cipherBlockSize

public int cipherBlockSize()
The block-size for the Blowfish cipher is 8 bytes.
Specified by:
cipherBlockSize in interface CipherKey

getSize

public int getSize()
Return the size of this key.
Specified by:
getSize in interface Key

getAlgorithm

public java.lang.String getAlgorithm()
The name of the algorithm is "Blowfish".
Specified by:
getAlgorithm in interface Key

equals

public boolean equals(java.lang.Object o)
Return true iff the two keys are equivalent.
Overrides:
equals in class java.lang.Object

getKey

public byte[] getKey()
Return the key-bits for this key as an array of bytes.

toString

public java.lang.String toString()
Return a CDS for this key.
Overrides:
toString in class java.lang.Object
See Also:
Crypto.fromString(java.io.Reader)

encrypt

public void encrypt(byte[] source,
                    int i,
                    byte[] dest,
                    int j)
Encrypt one block of data. The plaintext is taken from source[i..i+7] and ciphertext is written to dest[j..j+7]
Specified by:
encrypt in interface CipherKey

decrypt

public void decrypt(byte[] source,
                    int i,
                    byte[] dest,
                    int j)
Decrypt one block of data. The encrypted data is taken from source[i..i+7] and plaintext is written to dest[j..j+7].
Specified by:
decrypt in interface CipherKey


Copyright 1997-2000 Logi Ragnarsson