org.ssonet.mechanisms.confidentiality
Class AbstractConfidentialityMechanism

java.lang.Object
  |
  +--org.ssonet.mechanisms.confidentiality.AbstractConfidentialityMechanism
All Implemented Interfaces:
IOStream, Mechanism
Direct Known Subclasses:
Blowfish, CAST5, CAST6, DES, DESede, IDEA, RC2, RC4, RC5, RC5_64, RC6, Rijndael, Serpent, Skipjack, Twofish

public class AbstractConfidentialityMechanism
extends java.lang.Object
implements IOStream, Mechanism

The abstract base class for all cipher algorithms used in SSONET.


Field Summary
protected  javax.crypto.Cipher cipherIn
           
protected  javax.crypto.Cipher cipherOut
           
protected  boolean EOF
           
protected  org.ssonet.util.ByteFIFO inBuffer
           
protected static int INBUFFER_SIZE
           
protected  org.ssonet.io.IOStream ioStream
           
protected  int[] keyLengths
           
protected  java.lang.String mechanismName
           
protected  byte[] messageBuffer
           
protected  java.lang.String[] modes
           
protected  org.ssonet.mechanisms.MechanismConfiguration negotiatedMechConf
          the name of the Mechanism used to get the Mechanism from the Crypto-Provider.
protected  java.lang.String[] providers
           
protected  int readBlockNumber
           
protected  java.io.IOException readException
           
protected  int readMode
           
protected  int[] rounds
           
protected  int validBytesToRead
           
protected  java.lang.String[] variants
           
protected  int writeBlockNumber
           
 
Fields inherited from interface org.ssonet.net.Mechanism
KEYLENGTH, MODES, PROVIDERLIST, ROUNDS, VARIANTS
 
Constructor Summary
AbstractConfidentialityMechanism()
           
 
Method Summary
 int available()
           
 void closeIn()
          Closes the input part of the ioStream.
 void closeOut()
          Closes the output part of the ioStream.
protected  java.security.spec.AlgorithmParameterSpec getAlgorithmParameterSpec(org.ssonet.mechanisms.MechanismConfiguration mechConf)
          returns a general algorithmParameterSpec with an IV (initialization vector).
 org.ssonet.mechanisms.MechanismConfiguration getConfiguration()
           
 org.ssonet.mechanisms.MechanismConfiguration getDefaultConfiguration()
          Return the basic default configuration for a cipher algorithm.
 int[] getKeyLengths()
           
 java.lang.String[] getModes()
           
 java.lang.String getName()
           
 java.lang.String[] getProviders()
           
 int[] getRounds()
           
 java.lang.String[] getVariants()
           
 void init(org.ssonet.io.IOStream ioStream, int securityGoal, org.ssonet.mechanisms.MechanismConfiguration ownMechanismConfiguration)
          Initialize without key exchange
 void init(org.ssonet.io.IOStream ioStream, int securityGoal, org.ssonet.mechanisms.MechanismConfiguration ownMechanismConfiguration, org.ssonet.mechanisms.MechanismConfiguration partnerMechanismConfiguration, org.ssonet.net.KeyExchange keyExchange)
          Initialize with key exchange
protected  void initIOStream()
          Initializes the data fields needed for the IOStream to work.
protected  org.ssonet.mechanisms.MechanismConfiguration negotiateMechConf(org.ssonet.mechanisms.MechanismConfiguration ownMechanismConfiguration, org.ssonet.mechanisms.MechanismConfiguration partnerMechanismConfiguration)
          This Method negotiates between two mechanismConfigurations.
 int read(byte[] buffer)
          reads an array of bytes from the IOStream
 byte[] testDecrypt(byte[] buffer)
          Decrypt buffer and return the decrypted data
 byte[] testEncrypt(byte[] buffer)
          Encrypt buffer and return the encrypted data
 void write(byte[] buffer)
          Encrypts an array of bytes and writes it to the IOStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mechanismName

protected java.lang.String mechanismName

keyLengths

protected int[] keyLengths

modes

protected java.lang.String[] modes

providers

protected java.lang.String[] providers

rounds

protected int[] rounds

variants

protected java.lang.String[] variants

ioStream

protected org.ssonet.io.IOStream ioStream

cipherIn

protected javax.crypto.Cipher cipherIn

cipherOut

protected javax.crypto.Cipher cipherOut

negotiatedMechConf

protected org.ssonet.mechanisms.MechanismConfiguration negotiatedMechConf
the name of the Mechanism used to get the Mechanism from the Crypto-Provider. Each Confidentiality Mechanism must provide such a name. This name can differ from the class name of the Mechanism class.


inBuffer

protected org.ssonet.util.ByteFIFO inBuffer

INBUFFER_SIZE

protected static int INBUFFER_SIZE

EOF

protected boolean EOF

readException

protected java.io.IOException readException

messageBuffer

protected byte[] messageBuffer

validBytesToRead

protected int validBytesToRead

readMode

protected int readMode

readBlockNumber

protected int readBlockNumber

writeBlockNumber

protected int writeBlockNumber
Constructor Detail

AbstractConfidentialityMechanism

public AbstractConfidentialityMechanism()
Method Detail

available

public int available()
Specified by:
available in interface IOStream
Returns:
the number of bytes currently available from the inputstream without blocking.

closeIn

public void closeIn()
             throws java.io.IOException
Closes the input part of the ioStream.

Specified by:
closeIn in interface IOStream
java.io.IOException

closeOut

public void closeOut()
              throws java.io.IOException
Closes the output part of the ioStream.

Specified by:
closeOut in interface IOStream
java.io.IOException

testEncrypt

public byte[] testEncrypt(byte[] buffer)
Encrypt buffer and return the encrypted data

Specified by:
testEncrypt in interface Mechanism
Parameters:
buffer - date to crypt
Returns:
encrypted buffer data

testDecrypt

public byte[] testDecrypt(byte[] buffer)
Decrypt buffer and return the decrypted data

Specified by:
testDecrypt in interface Mechanism
Parameters:
buffer - date to crypt
Returns:
decrypted buffer data

read

public int read(byte[] buffer)
         throws java.io.IOException
reads an array of bytes from the IOStream

Specified by:
read in interface IOStream
Parameters:
buffer - the buffer to be filled during the read operation
Returns:
the number of bytes read, or -1 if EOF is reached
Throws:
java.io.IOException - if an error occures while reading from the IOStream

write

public void write(byte[] buffer)
           throws java.io.IOException
Encrypts an array of bytes and writes it to the IOStream.

Specified by:
write in interface IOStream
Parameters:
buffer - the buffer holding the bytes to write to the stream
Throws:
java.io.IOException - if an error occures while writing to the stream

getAlgorithmParameterSpec

protected java.security.spec.AlgorithmParameterSpec getAlgorithmParameterSpec(org.ssonet.mechanisms.MechanismConfiguration mechConf)
returns a general algorithmParameterSpec with an IV (initialization vector). This method must be overriden in mechanisms, which need special algorithm parameters


init

public void init(org.ssonet.io.IOStream ioStream,
                 int securityGoal,
                 org.ssonet.mechanisms.MechanismConfiguration ownMechanismConfiguration)
Initialize without key exchange

Specified by:
init in interface Mechanism
Parameters:
ioStream - mechanism IOStream
securityGoal - the security goal, for which the algorithm is used
ownMechanismConfiguration - own mechanism configuration

negotiateMechConf

protected org.ssonet.mechanisms.MechanismConfiguration negotiateMechConf(org.ssonet.mechanisms.MechanismConfiguration ownMechanismConfiguration,
                                                                         org.ssonet.mechanisms.MechanismConfiguration partnerMechanismConfiguration)
                                                                  throws ParameterNotCompatibleException
This Method negotiates between two mechanismConfigurations. It negotiates the MODE and, if set, the key length. This method must be overidden by mechanism classes, which need to negotiate other mechanism parameters

ParameterNotCompatibleException

init

public void init(org.ssonet.io.IOStream ioStream,
                 int securityGoal,
                 org.ssonet.mechanisms.MechanismConfiguration ownMechanismConfiguration,
                 org.ssonet.mechanisms.MechanismConfiguration partnerMechanismConfiguration,
                 org.ssonet.net.KeyExchange keyExchange)
          throws java.lang.Exception
Initialize with key exchange

Specified by:
init in interface Mechanism
Parameters:
ioStream - mechanism IOStream
securityGoal - the security goal, for which the algorithm is used
ownMechanismConfiguration - own mechanism configuration
partnerMechanismConfiguration - partner mechanism configuration
keyExchange - prepared key exchange protocol
Throws:
java.lang.Exception - if initialization fails

initIOStream

protected void initIOStream()
Initializes the data fields needed for the IOStream to work. Thist method must be called by mechanisms extending this class in their initialization methods.


getDefaultConfiguration

public org.ssonet.mechanisms.MechanismConfiguration getDefaultConfiguration()
Return the basic default configuration for a cipher algorithm. An algorithm, which needs another default configuration, must override this method. The Configuration consists of Cipher Modes (ECB, OFB, ....) and the Provider

Specified by:
getDefaultConfiguration in interface Mechanism
Returns:
a default configuration setting for the mechanism.

getConfiguration

public org.ssonet.mechanisms.MechanismConfiguration getConfiguration()
Specified by:
getConfiguration in interface Mechanism
Returns:
the mechanism configuration of this mechanism after it was initialized by one of the init methods, or null if the mechanism was not allready initialized.

getModes

public java.lang.String[] getModes()
Specified by:
getModes in interface Mechanism
Returns:
valid operation modes of the mechanism.

getProviders

public java.lang.String[] getProviders()
Specified by:
getProviders in interface Mechanism
Returns:
valid crypto providers for the mechanism

getVariants

public java.lang.String[] getVariants()
Specified by:
getVariants in interface Mechanism
Returns:
valid variants for the mechanism

getKeyLengths

public int[] getKeyLengths()
Specified by:
getKeyLengths in interface Mechanism
Returns:
valid keylengths for the mechanism

getRounds

public int[] getRounds()
Specified by:
getRounds in interface Mechanism
Returns:
valid rounds for the mechanism

getName

public java.lang.String getName()
Specified by:
getName in interface Mechanism
Returns:
name of the mechanism


Copyright © 2003 DRIM Team. All Rights Reserved.