|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.pkcs.pkcs1.MaskGenerationAlgorithmSpi | +--iaik.pkcs.pkcs1.MaskGenerationAlgorithm
JCA compliant engine that provides the functionality of a PKCS#1v2.1 mask generation function.
Mask generation functions are used by the PKCS#1v2.1 PSS signature and OAEP encryption schemes:
A mask generation function takes an octet string of variable length and a desired output length as input, and outputs an octet string of the desired length. There may be restrictions on the length of the input and output octet strings, but such bounds are generally very large. Mask generation functions are deterministic; the octet string output is completely determined by the input octet string. The output of a mask generation function should be pseudorandom: Given one part of the output but not the input, it should be infeasible to predict another part of the output. The provable security of RSAES- OAEP and RSASSA-PSS relies on the random nature of the output of the mask generation function, which in turn relies on the random nature of the underlying hash.This class implements both interfaces of the JCA, the API as used by the application and the SPI (
engine
methods) as implemented by the provider.
An application wishing to use some specific mask generation function, first tries to get an engine instance for the desired algorithm (e.g. MGF1):
MaskGenerationAlgorithm mgf = MaskGenerationAlgorithm.getInstance("MGF1", "IAIK");After supplying the engine with parameters (if required), method
mask
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. For example, the only mask generation
function specified by PKCS#1, MGF1
, is based on a hash algorithm
which 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);
Constructor Summary | |
protected |
MaskGenerationAlgorithm(String algorithm)
Creates a MaskGenerationAlgorithm with the given algorithm name. |
Method Summary | |
String |
getAlgorithm()
Gets the name of the mask generation algorithm this engine implements. |
static MaskGenerationAlgorithm |
getInstance(String algorithm)
Creates an MaskGenerationAlgorithm engine for the given algorithm name. |
static MaskGenerationAlgorithm |
getInstance(String algorithm,
String provider)
Creates a provider-specific MaskGenerationAlgorithm engine for the given algorithm name. |
AlgorithmParameters |
getParameters()
Gets the algorithm parameters required by this MGF engine. |
void |
mask(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]. |
void |
reset()
Resets this engine to the state before mask has been called. |
void |
setParameters(AlgorithmParameters params)
Sets any algorithm parameters required by this MGF engine. |
void |
setParameters(AlgorithmParameterSpec paramSpec)
Sets any algorithm parameters required by this MGF engine. |
String |
toString()
Returns a string representation. |
Methods inherited from class iaik.pkcs.pkcs1.MaskGenerationAlgorithmSpi |
clone, engineGetParameters, engineMask, engineReset, engineSetParameters, engineSetParameters |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected MaskGenerationAlgorithm(String algorithm)
Method Detail |
public static final MaskGenerationAlgorithm getInstance(String algorithm) throws NoSuchAlgorithmException
algorithm
- the name of the mgf algorithm for which an engine should be createdNoSuchAlgorithmException
- if no implementation for the requested algorithm
is availablepublic static final MaskGenerationAlgorithm getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
algorithm
- the name of the mgf algorithm for which an engine should be createdprovider
- the name of the provider whose MGF implementation is requestedNoSuchAlgorithmException
- if no implementation for the requested algorithm
is availableNoSuchProviderException
- if the requested provider is not availablepublic final void mask(byte[] mgfSeed, int mgfSeedOff, int mgfSeedLen, int maskLen, byte[] dst, int dstOff)
A call to this method resets this engine to the state before mask
has been called.
mgfSeed
- the seed from which the mask is generatedmgfSeedOff
- the offest 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 arraypublic final void reset()
mask
has been called.public final String getAlgorithm()
public String toString()
toString
in class Object
public final void setParameters(AlgorithmParameterSpec paramSpec) throws InvalidAlgorithmParameterException
paramSpec
- the parameters to be setInvalidAlgorithmParameterException
- if the parameters are inappropriate for
this engine or are invalidpublic final void setParameters(AlgorithmParameters params) throws InvalidAlgorithmParameterException
params
- the parameters to be setInvalidAlgorithmParameterException
- if the parameters are inappropriate for
this engine or are invalidpublic final AlgorithmParameters getParameters()
|
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). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |