iaik.pkcs.pkcs1
Class MGF1

java.lang.Object
  |
  +--iaik.pkcs.pkcs1.MaskGenerationAlgorithmSpi
        |
        +--iaik.pkcs.pkcs1.MaskGenerationAlgorithm
              |
              +--iaik.pkcs.pkcs1.MGF1
All Implemented Interfaces:
Cloneable

public class MGF1
extends MaskGenerationAlgorithm
implements Cloneable

This class implements the PKCS#1v2.1 mask generation algorithm MGF1 as used by by the RSASSA-PSS signature scheme and the RSAES-OAEP encryption scheme.

An application wishing to use some specific mask generation function, first tries to get an engine instance for the MGF1 mask generation algorithm:

 MaskGenerationAlgorithm mgf = MaskGenerationAlgorithm.getInstance("MGF1", "IAIK");
 
After supplying the engine with parameters (if required), method has to be called to "mask" the input data by XORing it with the mask generated from some seed by using the mask generation algorithm. Since MGF1 is based on a hash algorithm the hash algorithm may be supplied as MGF1ParameterSpec:
 AlgorithmID hashAlgID = ...;
 MGF1ParameterSpec paramSpec = new MGF1ParameterSpec(hashAlgID);
 // optionally set the hash engine to be used:
 MessageDigest hashEngine = ...;
 paramSpec.setHashEngine(hashEngine);
 // set the parameters
 mgf.setParameters(paramSpec);
 // mask the data
 byte[] data = ...;
 byte[] dataOff = ...;
 byte[] seed = ...;
 int seedOff = ...;
 int seedLen = ...;
 int maskLen = ...;
 mgf.mask(seed, seedOff, seedLen, maskLen, data, dataOff);
 

Version:
File Revision 17
See Also:
MaskGenerationAlgorithm, MGF1ParameterSpec, MGF1Parameters

Field Summary
static ObjectID OID
          The ASN.1 object identifier (1.2.840.113549.1.1.8) for the MGF1 mask generation algorithm.
 
Constructor Summary
MGF1()
          Default constructor.
MGF1(AlgorithmID hashAlgorithm, MessageDigest hashEngine)
          Creates a MGF1 object for given hash algorithm and hash engine.
 
Method Summary
 Object clone()
          Returns a clone of this Object.
protected  AlgorithmParameters engineGetParameters()
          Returns the parameter (hash algorithm) used by this insatance of MGF1 object.
protected  void engineMask(byte[] mgfSeed, int mgfSeedOff, int mgfSeedLen, int maskLen, byte[] dst, int dstOff)
          Uses the mask generation function to generate maskLen bytes from the supplied seed mgfSeed[mgfSeedOff:mgfSeedLen] and XORs the result with dst[off:maskLen].
protected  void engineReset()
          Resets this engine to the state before engineMask has been called.
protected  void engineSetParameters(AlgorithmParameters params)
          Sets the parameter (hash algorithm) for the MGF1 algorithm.
protected  void engineSetParameters(AlgorithmParameterSpec paramSpec)
          Sets the parameter (hash algorithm) for the MGF1 algorithm.
 ObjectID getOID()
          Gets the ASN.1 object identifier (1.2.840.113549.1.1.8) for the MGF1 mask generation function.
 
Methods inherited from class iaik.pkcs.pkcs1.MaskGenerationAlgorithm
getAlgorithm, getInstance, getInstance, getParameters, mask, reset, setParameters, setParameters, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OID

public static final ObjectID OID
The ASN.1 object identifier (1.2.840.113549.1.1.8) for the MGF1 mask generation algorithm.
Constructor Detail

MGF1

public MGF1()
Default constructor. Creates a MGF1 object with the default hash algorithm SHA-1.

MGF1

public MGF1(AlgorithmID hashAlgorithm,
            MessageDigest hashEngine)
Creates a MGF1 object for given hash algorithm and hash engine.
Parameters:
hashAlgorithm - the hash algorithm to be used
hashEngine - the MessageDigest engine to be used
Method Detail

engineMask

protected void engineMask(byte[] mgfSeed,
                          int mgfSeedOff,
                          int mgfSeedLen,
                          int maskLen,
                          byte[] dst,
                          int dstOff)
Uses the mask generation function to generate maskLen bytes from the supplied seed mgfSeed[mgfSeedOff:mgfSeedLen] and XORs the result with dst[off:maskLen].
Overrides:
engineMask in class MaskGenerationAlgorithmSpi
Parameters:
mgfSeed - the seed from which the mask is generated
mgfSeedOff - the offest indicating the start position within the seed array
mgfSeedLen - the actual number of seed bytes
maskLen - the number of required mask bytes
dst - the destination array to which to XOR the mask result
dstOff - the offset indicating the start position within the destination array

engineSetParameters

protected void engineSetParameters(AlgorithmParameterSpec paramSpec)
                            throws InvalidAlgorithmParameterException
Sets the parameter (hash algorithm) for the MGF1 algorithm.
Overrides:
engineSetParameters in class MaskGenerationAlgorithmSpi
Parameters:
paramSpec - the parameter (hash algorithm) to be used
Throws:
InvalidAlgorithmParameterException - if the supplied parameter is not an instance of MGF1ParameterSpec

engineSetParameters

protected void engineSetParameters(AlgorithmParameters params)
                            throws InvalidAlgorithmParameterException
Sets the parameter (hash algorithm) for the MGF1 algorithm.
Overrides:
engineSetParameters in class MaskGenerationAlgorithmSpi
Parameters:
params - the parameter (hash algorithm) to be used
Throws:
InvalidAlgorithmParameterException - if the supplied parameter is not an instance of MGF1ParameterSpec

engineGetParameters

protected AlgorithmParameters engineGetParameters()
Returns the parameter (hash algorithm) used by this insatance of MGF1 object.
Overrides:
engineGetParameters in class MaskGenerationAlgorithmSpi
Returns:
the parameter (hash algorithm) as MGF1ParameterSpec

engineReset

protected void engineReset()
Resets this engine to the state before engineMask has been called.
Overrides:
engineReset in class MaskGenerationAlgorithmSpi

getOID

public ObjectID getOID()
Gets the ASN.1 object identifier (1.2.840.113549.1.1.8) for the MGF1 mask generation function.
Returns:
the OID identifying this algorithm

clone

public Object clone()
Returns a clone of this Object.
Overrides:
clone in class MaskGenerationAlgorithmSpi
Returns:
a clone of this Object

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK