de.fhg.igd.crypto
Class RC2Parameters

java.lang.Object
  extended by java.security.AlgorithmParametersSpi
      extended by de.fhg.igd.crypto.RC2Parameters

public class RC2Parameters
extends AlgorithmParametersSpi

This class represents a RC2 Parameters as defined in RFC 2311 and RFC 2268. This structure is identified by the OID of the RC2-CBC algorithm, which is

{iso(1) member-body(2) us(840) rsadsi(113549) encryptionAlgorithm(3) 2}

RFC 2311 defines three effective key lengths and the according version numbers. These lengths are 40, 64, and 128, the parameter version values are 160, 120, and 58 respectively.

This class supports the full range of effective key lengths as specified by Ron Rivest in RFC 2268. In this RFC, Mr. Rivest specifies a permutation mapping from effective key lengths to version numbers. The map defines a one-to-one correspondence. Why he defined this is beyond my understanding. It complicates parameter encoding and decoding considerably, and it does not seem to serve any purpose byond that. Anyway, it is fully supported.

Encoding and decoding according to RFC 2311 and RFC 2268 is supported (ASN.1/DER). If the effective key length is 32 then the parameters are encoded as an OCTET STRING. Other effective key lengths lead to the encoding of the full SEQUENCE containing the version as well as the IV.

Version:
"$Id: RC2Parameters.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth

Field Summary
protected static byte[] c10
          The encoding with ekb == 32.
protected static byte[] c15
          The encoding with version < 128 && ekb != 32.
protected static byte[] c16
          The encoding with version > 127.
protected  int ekb_
          The number of effective key bits.
protected static byte[] ekb2v_
          Maps effective key lengths between 0 and 255 to the appropriate version number as specified in RFC2311.
protected  byte[] iv_
          The initialisation vector (IV), consisting of 8 bytes.
protected static byte[] v2ekb_
          Maps version numbers between 0 and 255 to the appropriate effective key lengths as specified in RFC2311.
protected  int version_
          The parameter version.
 
Constructor Summary
RC2Parameters()
           
 
Method Summary
 byte[] engineGetEncoded()
           
 byte[] engineGetEncoded(String format)
          This method returns the ASN.1/DER encoded parameter structure as defined in the S/MIME standard.
 AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
           
 void engineInit(AlgorithmParameterSpec paramSpec)
          This method accepts an RC2ParameterSpec.
 void engineInit(byte[] encoded)
          This method expects DER encoded RC2Parameters as defined in the S/MIME standard.
 void engineInit(byte[] params, String format)
          This method ignores the format string and attempts to decode according to ASN.1/DER and the parameter structure defined in the S/MIME standard.
 String engineToString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ekb2v_

protected static final byte[] ekb2v_
Maps effective key lengths between 0 and 255 to the appropriate version number as specified in RFC2311.


v2ekb_

protected static final byte[] v2ekb_
Maps version numbers between 0 and 255 to the appropriate effective key lengths as specified in RFC2311.


c16

protected static final byte[] c16
The encoding with version > 127.


c15

protected static final byte[] c15
The encoding with version < 128 && ekb != 32.


c10

protected static final byte[] c10
The encoding with ekb == 32.


iv_

protected byte[] iv_
The initialisation vector (IV), consisting of 8 bytes.


ekb_

protected int ekb_
The number of effective key bits.


version_

protected int version_
The parameter version.

Constructor Detail

RC2Parameters

public RC2Parameters()
Method Detail

engineInit

public void engineInit(AlgorithmParameterSpec paramSpec)
                throws InvalidParameterSpecException
This method accepts an RC2ParameterSpec. Other specs cause an exception being thrown. Three different effective key lengths are defined in S/MIME, 40, 64, and 128. If the parameter spec defines a different effective key length then an exception is thrown.

The RC2ParameterSpec may return a null as the IV. In that case, the IV is set to zeroes. Hence, this parameter class will always define an IV, as will any parameter specs derived from it. The IV will always have exactly 8 bytes as defined in RFC2311. Should the spec return a longer or shorter IV then this IV will be either padded with zeroes or it is truncated. This is to work around a bug in the ABA provider until it is fixed.

Specified by:
engineInit in class AlgorithmParametersSpi
Parameters:
paramSpec - The RC2ParameterSpec with the IV and effective key length in bits.
Throws:
InvalidParameterSpecException - if the spec is of the wrong class or the key size is non-standard.

engineInit

public void engineInit(byte[] encoded)
                throws IOException
This method expects DER encoded RC2Parameters as defined in the S/MIME standard. In case of a bad encoding an IOException is thrown.

Specified by:
engineInit in class AlgorithmParametersSpi
Parameters:
encoded - The encoded algorithm parameters.
Throws:
IOException - in case of a bad encoding.

engineInit

public void engineInit(byte[] params,
                       String format)
                throws IOException
This method ignores the format string and attempts to decode according to ASN.1/DER and the parameter structure defined in the S/MIME standard.

Specified by:
engineInit in class AlgorithmParametersSpi
Throws:
IOException

engineGetParameterSpec

public AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
                                              throws InvalidParameterSpecException
Specified by:
engineGetParameterSpec in class AlgorithmParametersSpi
Throws:
InvalidParameterSpecException

engineGetEncoded

public byte[] engineGetEncoded()
                        throws IOException
Specified by:
engineGetEncoded in class AlgorithmParametersSpi
Throws:
IOException

engineGetEncoded

public byte[] engineGetEncoded(String format)
                        throws IOException
This method returns the ASN.1/DER encoded parameter structure as defined in the S/MIME standard. The format string is ignored since no standardised names exist for different encoding formats.

Specified by:
engineGetEncoded in class AlgorithmParametersSpi
Parameters:
format - The name of the encoding format; this parameter is ignored.
Returns:
The ASN.1/DER encoded S/MIME RC2Parameters.
Throws:
IOException

engineToString

public String engineToString()
Specified by:
engineToString in class AlgorithmParametersSpi


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.