public class MGF1 extends MaskGenerationAlgorithm implements java.lang.Cloneable
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);
MaskGenerationAlgorithm
,
MGF1ParameterSpec
,
MGF1Parameters
Modifier and Type | Field and Description |
---|---|
static ObjectID |
OID
The ASN.1 object identifier (1.2.840.113549.1.1.8) for the MGF1 mask generation algorithm.
|
Constructor and Description |
---|
MGF1()
Default constructor.
|
MGF1(AlgorithmID hashAlgorithm,
java.security.MessageDigest hashEngine)
Creates a MGF1 object for given hash algorithm and hash engine.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a clone of this Object.
|
protected java.security.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(java.security.AlgorithmParameters params)
Sets the parameter (hash algorithm) for the
MGF1 algorithm. |
protected void |
engineSetParameters(java.security.spec.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.
|
getAlgorithm, getInstance, getInstance, getInstance, getParameters, mask, reset, setParameters, setParameters, toString
public static final ObjectID OID
public MGF1()
public MGF1(AlgorithmID hashAlgorithm, java.security.MessageDigest hashEngine)
hashAlgorithm
- the hash algorithm to be usedhashEngine
- the MessageDigest engine to be usedprotected void engineMask(byte[] mgfSeed, int mgfSeedOff, int mgfSeedLen, int maskLen, byte[] dst, int dstOff)
engineMask
in class MaskGenerationAlgorithmSpi
mgfSeed
- the seed from which the mask is generatedmgfSeedOff
- the offset indicating the start position within the seed arraymgfSeedLen
- the actual number of seed bytesmaskLen
- the number of required mask bytesdst
- the destination array to which to XOR the mask resultdstOff
- the offset indicating the start position within the destination arrayprotected void engineSetParameters(java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.InvalidAlgorithmParameterException
MGF1
algorithm.engineSetParameters
in class MaskGenerationAlgorithmSpi
paramSpec
- the parameter (hash algorithm) to be usedjava.security.InvalidAlgorithmParameterException
- if the supplied parameter is not an instance of MGF1ParameterSpec
protected void engineSetParameters(java.security.AlgorithmParameters params) throws java.security.InvalidAlgorithmParameterException
MGF1
algorithm.engineSetParameters
in class MaskGenerationAlgorithmSpi
params
- the parameter (hash algorithm) to be usedjava.security.InvalidAlgorithmParameterException
- if the supplied parameter is not an instance of MGF1ParameterSpec
protected java.security.AlgorithmParameters engineGetParameters()
MGF1
object.engineGetParameters
in class MaskGenerationAlgorithmSpi
MGF1ParameterSpec
protected void engineReset()
engineMask
has been called.engineReset
in class MaskGenerationAlgorithmSpi
public ObjectID getOID()
public java.lang.Object clone()
clone
in class MaskGenerationAlgorithmSpi