net.ninthtest.crypto.provider.helix
Class HelixAlgorithmParameters

java.lang.Object
  extended by java.security.AlgorithmParametersSpi
      extended by net.ninthtest.crypto.provider.helix.HelixAlgorithmParameters

public final class HelixAlgorithmParameters
extends AlgorithmParametersSpi

Manages the algorithm parameters for Helix cryptographic operations.

Version:
1.0
Author:
Matthew Zipay (mattz@ninthtest.info)

Constructor Summary
HelixAlgorithmParameters()
          Creates a new HelixAlgorithmParameters and performs the provider self-integrity check.
 
Method Summary
protected  byte[] engineGetEncoded()
          Returns the parameters in their primary encoding format.
protected  byte[] engineGetEncoded(String format)
          Returns the parameters encoded in the specified format.
protected
<T extends AlgorithmParameterSpec>
T
engineGetParameterSpec(Class<T> paramSpec)
          Returns a (transparent) specification of this parameters object.
protected  void engineInit(AlgorithmParameterSpec paramSpec)
          Initializes this parameters object using the parameters specified in paramSpec.
protected  void engineInit(byte[] params)
          Imports the specified parameters and decodes them according to the primary decoding format for parameters.
protected  void engineInit(byte[] params, String format)
          Imports the parameters from params and decodes them according to the specified decoding format.
protected  String engineToString()
          Returns a formatted string describing the parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HelixAlgorithmParameters

public HelixAlgorithmParameters()
Creates a new HelixAlgorithmParameters and performs the provider self-integrity check.

Method Detail

engineInit

protected void engineInit(AlgorithmParameterSpec paramSpec)
                   throws InvalidParameterSpecException
Initializes this parameters object using the parameters specified in paramSpec.

Specified by:
engineInit in class AlgorithmParametersSpi
Parameters:
paramSpec - the algorithm parameter specification (must be a HelixParameterSpec)
Throws:
InvalidParameterSpecException - if paramSpec is null or not a HelixParameterSpec
See Also:
AlgorithmParametersSpi.engineInit(java.security.spec.AlgorithmParameterSpec)

engineInit

protected void engineInit(byte[] params)
                   throws IOException
Imports the specified parameters and decodes them according to the primary decoding format for parameters.

Helix parameters are only encoded in ASN.1/DER format. There are two valid ASN.1/DER encodings for Helix parameters, as specified below.

Nonce-only (18 bytes, expressed in hexadecimal below):

 04 10 xx xx xx xx xx xx
 xx xx xx xx xx xx xx xx
 xx xx
 

Nonce + MAC (38 bytes, expressed in hexadecimal below):

 30 24 04 10 xx xx xx xx
 xx xx xx xx xx xx xx xx
 xx xx xx xx 04 10 xx xx
 xx xx xx xx xx xx xx xx
 xx xx xx xx xx xx
 

Specified by:
engineInit in class AlgorithmParametersSpi
Parameters:
params - the ASN.1/DER-encoded parameters
Throws:
IOException - if params cannot be decoded according to the specifications above
See Also:
AlgorithmParametersSpi.engineInit(byte[])

engineInit

protected void engineInit(byte[] params,
                          String format)
                   throws IOException
Imports the parameters from params and decodes them according to the specified decoding format.

Helix algorithm parameters only recognize ASN.1 or DER encoding.

If format is non-null and not ASN.1 or DER, an attempt is made to decode params as ASN.1; if this attempt fails, an IOException is thrown.

If format is null, params is decoded assuming ASN.1.

Specified by:
engineInit in class AlgorithmParametersSpi
Parameters:
params - the encoded parameters
format - the name of the decoding format (should be "ASN.1" or "DER")
Throws:
IOException - if params cannot be decoded
See Also:
AlgorithmParametersSpi.engineInit(byte[], java.lang.String)

engineGetParameterSpec

protected <T extends AlgorithmParameterSpec> T engineGetParameterSpec(Class<T> paramSpec)
                                                           throws InvalidParameterSpecException
Returns a (transparent) specification of this parameters object.

Specified by:
engineGetParameterSpec in class AlgorithmParametersSpi
Parameters:
paramSpec - the specification class in which the parameters should be returned (must be HelixParameterSpec)
Returns:
the Helix parameter specification
Throws:
InvalidParameterSpecException - if paramSpec is null or not equal to the class of HelixParameterSpec
See Also:
AlgorithmParametersSpi.engineGetParameterSpec(java.lang.Class)

engineGetEncoded

protected byte[] engineGetEncoded()
                           throws IOException
Returns the parameters in their primary encoding format.

Helix parameters are only encoded in ASN.1/DER format. There are two valid ASN.1/DER encodings for Helix parameters, as specified below.

Nonce-only (18 bytes, expressed in hexadecimal below):

 04 10 xx xx xx xx xx xx
 xx xx xx xx xx xx xx xx
 xx xx
 

Nonce + MAC (38 bytes, expressed in hexadecimal below):

 30 24 04 10 xx xx xx xx
 xx xx xx xx xx xx xx xx
 xx xx xx xx 04 10 xx xx
 xx xx xx xx xx xx xx xx
 xx xx xx xx xx xx
 

Specified by:
engineGetEncoded in class AlgorithmParametersSpi
Returns:
the ASN.1/DER-encoded Helix parameters
Throws:
IOException - if an error occurs while encoding the Helix parameters
See Also:
AlgorithmParametersSpi.engineGetEncoded()

engineGetEncoded

protected byte[] engineGetEncoded(String format)
                           throws IOException
Returns the parameters encoded in the specified format.

Helix parameters are only encoded in ASN.1/DER format.

If format is non-null and not ASN.1 or DER, an IOException is thrown.

If format is null, params is encoded assuming ASN.1.

Specified by:
engineGetEncoded in class AlgorithmParametersSpi
Parameters:
format - the name of the encoding format (should be "ASN.1", "DER", or null)
Returns:
the ASN.1/DER-encoded Helix parameters
Throws:
IOException - if format is non-null and not "ASN.1" or "DER"; or if an error occurs while encoding the Helix parameters
See Also:
AlgorithmParametersSpi.engineGetEncoded(java.lang.String)

engineToString

protected String engineToString()
Returns a formatted string describing the parameters.

This method returns the appropriate PDU (protocol data unit) for the Helix parameters represented by this instance, according to the following ASN.1/DER type specification:

 HelixParameters DEFINITIONS ::= BEGIN
 
     HelixNonce ::= OCTETSTRING
 
     HelixNonceAndMac ::= SEQUENCE {
         nonce   OCTETSTRING,
         mac     OCTETSTRING
     }
 
 END
 

If this instance represents a Helix nonce only, the following PDU is returned:

 helixParameters HelixNonce ::= {"xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx"}
 

If this instance represents a Helix nonce and MAC, the following PDU is returned:

 helixParameters HelixNonceAndMac ::= {
     nonce   "xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx",
     mac     "xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx"
 }
 

All bytes represented in PDUs are in hexadecimal format. If this instance has not yet been initialized, this method will return the result of super.toString().

Specified by:
engineToString in class AlgorithmParametersSpi
Returns:
the appropriate PDU representation of this instance (as described above), or the result of super.toString() if this instance has not been initialized
See Also:
AlgorithmParametersSpi.engineToString()


Copyright © 2010-2014 Matthew Zipay. All Rights Reserved.