org.ssonet.mechanisms.integrity
Class AbstractIntegrityMechanism

java.lang.Object
  |
  +--org.ssonet.mechanisms.integrity.AbstractIntegrityMechanism
All Implemented Interfaces:
IOStream, Mechanism
Direct Known Subclasses:
DESedeMac, DESMac, IDEAMac, MD2HMac, MD4HMac, MD5HMac, RC2Mac, RC5Mac, RipeMD128HMac, RipeMD160HMac, SHA1HMac, SkipjackMac, TigerHMac

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


Field Summary
protected  boolean debug
           
protected  boolean EOF
           
protected  org.ssonet.util.ByteFIFO inBuffer
           
protected static int INBUFFER_SIZE
           
protected  org.ssonet.io.IOStream ioStream
           
protected  java.lang.String keyGeneratorAlgorithmName
           
protected  int[] keyLengths
           
protected  javax.crypto.Mac macIn
           
protected  javax.crypto.Mac macOut
           
protected  java.lang.String mechanismName
           
protected  byte[] messageBuffer
           
protected  java.lang.String[] modes
           
protected  org.ssonet.mechanisms.MechanismConfiguration negotiatedMechConf
           
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
AbstractIntegrityMechanism()
           
 
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)
          This method must be overriden in mechanisms, which need special algorithm parameters
 org.ssonet.mechanisms.MechanismConfiguration getConfiguration()
           
 org.ssonet.mechanisms.MechanismConfiguration getDefaultConfiguration()
           
 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)
          Applies the mac testing algorithm to the given buffer.
 byte[] testEncrypt(byte[] buffer)
          Applies the MAC algorithm to the given buffer.
 void write(byte[] buffer)
          writes an array of bytes to the IOStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected boolean debug

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

keyGeneratorAlgorithmName

protected java.lang.String keyGeneratorAlgorithmName

ioStream

protected org.ssonet.io.IOStream ioStream

macIn

protected javax.crypto.Mac macIn

macOut

protected javax.crypto.Mac macOut

negotiatedMechConf

protected org.ssonet.mechanisms.MechanismConfiguration negotiatedMechConf

inBuffer

protected org.ssonet.util.ByteFIFO inBuffer

INBUFFER_SIZE

protected static int INBUFFER_SIZE

messageBuffer

protected byte[] messageBuffer

EOF

protected boolean EOF

readException

protected java.io.IOException readException

validBytesToRead

protected int validBytesToRead

readMode

protected int readMode

readBlockNumber

protected int readBlockNumber

writeBlockNumber

protected int writeBlockNumber
Constructor Detail

AbstractIntegrityMechanism

public AbstractIntegrityMechanism()
Method Detail

available

public int available()
Specified by:
available in interface IOStream
Returns:
the number of bits available from the IOStream 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)
Applies the MAC algorithm to the given buffer.

Specified by:
testEncrypt in interface Mechanism
Parameters:
buffer - the buffer to apply the MAC algorithm to
Returns:
the output of the algorithm

testDecrypt

public byte[] testDecrypt(byte[] buffer)
Applies the mac testing algorithm to the given buffer.

Specified by:
testDecrypt in interface Mechanism
Parameters:
buffer - the buffer holding the data with MACs
Returns:
the buffer holding the data without the MACs, or null, if the MAC was invalid.

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
writes an array of bytes to the IOStream.

Specified by:
write in interface IOStream
Parameters:
buffer - the buffer holding the data to write
Returns:
IOException if an IO-error occures during sending.
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)
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()
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.