Blackbird
Class Twofish

java.lang.Object
  extended by Blackbird.Twofish
All Implemented Interfaces:
EncryptionEntity

public final class Twofish
extends java.lang.Object
implements EncryptionEntity

Twofish is an AES candidate algorithm. It is a balanced 128-bit Feistel cipher, consisting of 16 rounds. In each round, a 64-bit S-box value is computed from 64 bits of the block, and this value is xored into the other half of the block. The two half-blocks are then exchanged, and the next round begins. Before the first round, all input bits are xored with key- dependent "whitening" subkeys, and after the final round the output bits are xored with other key-dependent whitening subkeys; these subkeys are not used anywhere else in the algorithm.

Twofish was submitted by Bruce Schneier, Doug Whiting, John Kelsey, Chris Hall and David Wagner.

Reference:

  1. TWOFISH2.C -- Optimized C API calls for TWOFISH AES submission, Version 1.00, April 1998, by Doug Whiting.

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

See:
http://www.cryptix.org/LICENSE.TXT Cryptix General License Copyright (c) 1995-2005 The Cryptix Foundation Limited. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE CRYPTIX FOUNDATION LIMITED AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CRYPTIX FOUNDATION LIMITED OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Revision: $


Field Summary
static int PW_SIZE
           
static java.lang.String strClassID
           
 
Fields inherited from interface Blackbird.EncryptionEntity
strBBCodeSelect, strFlatSelect, strHTMLSelect
 
Constructor Summary
Twofish(int i)
           
 
Method Summary
static byte[] blockDecrypt(byte[] in, int inOffset, java.lang.Object sessionKey)
          Decrypt exactly one block of ciphertext.
static byte[] blockEncrypt(byte[] in, int inOffset, java.lang.Object sessionKey)
          Encrypt exactly one block of plaintext.
static int blockSize()
           
static void buildInitVector()
          buildInitVector - builds the initialization vector internally from the password after it is set.
static byte[] copyOf(byte[] original, int newLength)
           
static byte[] copyOfRange(byte[] original, int from, int to)
           
 java.lang.String decrypt(java.lang.String strArgList)
          This is the upper level decrypt call for Twofish, called by the applet which is initiated by the anonymous JavaScript call from this class.
static byte[] decryptCBCStream(byte[] in)
          This is the public version of the stream decrypt, whereas the key is internal and private and this class is therefore called into when these parameters are set.
static byte[] encryptCBCStream(byte[] in)
          Public version for calling encryption in the private version, after one way setting for key creations are done.
 java.lang.String getClassID()
          Return the class identification string.
 int getIndex()
           
 java.lang.String getJavaScriptCode()
           
 java.awt.MenuItem[] getMenuItems()
          Return an array of menu items needed by the applet to build the right-click menu.
 int getOPCode(java.lang.String s)
          Opcode is returned depending on the string used to query this class.
 void killPanel()
          This is invoked by the panels themeselves to dispose when no longer needed.
 void killPWPanel()
          Twofish has a seperate password entry panel that needs its own executioner.
static void makeKey()
           
 java.lang.String parseID(java.lang.String arglist)
          parseID is used by those entities that need to single out an Identifier string needed by a using class to find out "who" created the encryption entry.
static boolean self_test()
          A basic symmetric encryption/decryption test.
 void setFrameTarget(int i)
          setFrameTarget is used to set a variable that is concated in the Javascript generation function that is set pertaining to the "position" the applet resides in the DOM.
 void setID(java.lang.String sid)
          Utility function for setting internal User Identifier.
 boolean setPasswordExternally(java.lang.String p)
          Twofish can be used by other classes for encrypting and decrypting.
 void showEncryptionControlPanel(int i, java.awt.Image iconImage, java.lang.Object o)
          This is called by menu actions in the Applet.
 boolean testRuntime()
           
 boolean usesPWIVector()
          Some Encryption entities use passwords or initialization vectors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PW_SIZE

public static final int PW_SIZE
See Also:
Constant Field Values

strClassID

public static final java.lang.String strClassID
See Also:
Constant Field Values
Constructor Detail

Twofish

public Twofish(int i)
Method Detail

buildInitVector

public static void buildInitVector()
buildInitVector - builds the initialization vector internally from the password after it is set.


makeKey

public static void makeKey()
                    throws java.security.InvalidKeyException
Throws:
java.security.InvalidKeyException

blockEncrypt

public static byte[] blockEncrypt(byte[] in,
                                  int inOffset,
                                  java.lang.Object sessionKey)
Encrypt exactly one block of plaintext.

Parameters:
in - The plaintext.
inOffset - Index of in from which to start considering data.
sessionKey - The session key to use for encryption.
Returns:
The ciphertext generated from a plaintext using the session key.

blockDecrypt

public static byte[] blockDecrypt(byte[] in,
                                  int inOffset,
                                  java.lang.Object sessionKey)
Decrypt exactly one block of ciphertext.

Parameters:
in - The ciphertext.
inOffset - Index of in from which to start considering data.
sessionKey - The session key to use for decryption.
Returns:
The plaintext generated from a ciphertext using the session key.

encryptCBCStream

public static byte[] encryptCBCStream(byte[] in)
Public version for calling encryption in the private version, after one way setting for key creations are done.

Parameters:
in -
Returns:

decryptCBCStream

public static byte[] decryptCBCStream(byte[] in)
This is the public version of the stream decrypt, whereas the key is internal and private and this class is therefore called into when these parameters are set.

Parameters:
in -
Returns:

copyOfRange

public static byte[] copyOfRange(byte[] original,
                                 int from,
                                 int to)
Parameters:
original -
from -
to -
Returns:

copyOf

public static byte[] copyOf(byte[] original,
                            int newLength)
Parameters:
original -
newLength -
Returns:

self_test

public static boolean self_test()
A basic symmetric encryption/decryption test.


blockSize

public static int blockSize()
Returns:
The length in bytes of the Algorithm input block.

getJavaScriptCode

public java.lang.String getJavaScriptCode()
Specified by:
getJavaScriptCode in interface EncryptionEntity

killPanel

public void killPanel()
This is invoked by the panels themeselves to dispose when no longer needed.

Specified by:
killPanel in interface EncryptionEntity

killPWPanel

public void killPWPanel()
Twofish has a seperate password entry panel that needs its own executioner.


showEncryptionControlPanel

public void showEncryptionControlPanel(int i,
                                       java.awt.Image iconImage,
                                       java.lang.Object o)
This is called by menu actions in the Applet. There are two Panels for Twofish - one for the password alone in those cases where there is incoming data on the webpage to decrypt. The other panel is for creating encryptd messages.

Specified by:
showEncryptionControlPanel in interface EncryptionEntity
Parameters:
i -
iconImage -
o -

getMenuItems

public java.awt.MenuItem[] getMenuItems()
Return an array of menu items needed by the applet to build the right-click menu.

Specified by:
getMenuItems in interface EncryptionEntity
Returns:

getOPCode

public int getOPCode(java.lang.String s)
Opcode is returned depending on the string used to query this class.

Specified by:
getOPCode in interface EncryptionEntity
Parameters:
s -
Returns:

getIndex

public int getIndex()
Specified by:
getIndex in interface EncryptionEntity

testRuntime

public boolean testRuntime()
Specified by:
testRuntime in interface EncryptionEntity

setPasswordExternally

public boolean setPasswordExternally(java.lang.String p)
Twofish can be used by other classes for encrypting and decrypting. In some cases it may not be practical to call on the password entry panel by itself to set the password in here.

Specified by:
setPasswordExternally in interface EncryptionEntity
Parameters:
p -
Returns:

decrypt

public java.lang.String decrypt(java.lang.String strArgList)
This is the upper level decrypt call for Twofish, called by the applet which is initiated by the anonymous JavaScript call from this class.

Specified by:
decrypt in interface EncryptionEntity
Parameters:
strArgList -
Returns:

setFrameTarget

public void setFrameTarget(int i)
setFrameTarget is used to set a variable that is concated in the Javascript generation function that is set pertaining to the "position" the applet resides in the DOM. What is meant by "Frame Target" is the name of the frame, derived from the frames Name parameter that the applet must invoke Javascript callback results into.

Specified by:
setFrameTarget in interface EncryptionEntity
Parameters:
i -

getClassID

public java.lang.String getClassID()
Return the class identification string.

Specified by:
getClassID in interface EncryptionEntity
Returns:

usesPWIVector

public boolean usesPWIVector()
Some Encryption entities use passwords or initialization vectors. Using programs may need to know that in some cases.

Specified by:
usesPWIVector in interface EncryptionEntity
Returns:

parseID

public java.lang.String parseID(java.lang.String arglist)
parseID is used by those entities that need to single out an Identifier string needed by a using class to find out "who" created the encryption entry. This is not needed by those classes that need not single out an encryption entry for a particuler initialization vector or password. Different classes that use this might have this Identifier is different parts of comma-delimited listing.

Specified by:
parseID in interface EncryptionEntity
Parameters:
arglist -
Returns:

setID

public void setID(java.lang.String sid)
Utility function for setting internal User Identifier.

Specified by:
setID in interface EncryptionEntity
Parameters:
StrID -