|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.security.SignatureSpi | +--java.security.Signature | +--iaik.security.rsa.RSAPkcs1Signature | +--iaik.security.rsa.RSAPssSignature
This class implements the sign and verify methods of the PKCS#1v2.1 PSS signature scheme (RSASSA-PSS).
This class follows the guidelines presented in PKCS#1 (v.2.1)) for implementing the RSASSA-PSS signature algorithm based on the RSA encryption method.
This class may be used to create/verify PSS based signatures according the specification where all parameters (hash algorithm, mask generation function, salt length, and trailer field) maybe supplied by the calling application. The trailer field is fixed to the 0xBC which is the only trailer field supported by PSS. Generally the following steps have to be performed for calculating/verifying a PSS signature:
getInstance
method, e.g.:
Signature pss = Signature.getInstance("RSASSA-PSS");
pss.initSign(rsaPrivateKey);
pss.initVerify(rsaPublicKey);
RSAPssParameterSpec
, e.g.:
// hash algorithm AlgorithmID hashID = (AlgorithmID)AlgorithmID.ripeMd160.clone(); // mask generation function ID AlgorithmID mgfID = (AlgorithmID)AlgorithmID.mgf1.clone(); mgfID.setParameter(hashID.toASN1Object()); // salt length int saltLength = 20; // create a RSAPssParameterSpec RSAPssParameterSpec pssParamSpec = new RSAPssParameterSpec(hashID, mgfID, saltLength); // optionally set hash and mgf engines MessageDigest hashEngine = MessageDigest.getInstance(“SHA-1”); pssParamSpec.setHashEngine(hashEngine); MaskGenerationAlgorithm mgfEngine = MaskGenerationAlgorithm.getInstance(“MGF1”); MGF1ParameterSpec mgf1Spec = new MGF1ParameterSpec(hashID); mgf1Spec.setHashEngine(hashEngine); mgfEngine.setParameters(mgf1Spec); pssParamSpec.setMGFEngine(mgfEngine); // set parameters (for JDK 1.1.8 use pss.setParameter(null, pssParamSpec);) pss.setParameter(pssParamSpec);
sign
method returning the signature as byte array.
Otherwise, if the Signature object has been initialized for verifying, first the
data to be verified is supplied to the Signature object, and subsequently the
signature is verified by calling the verify
method, supplied with
the byte array holding the corresponding signature value:
pss.update(data); byte[] signature = pss.sign();
pss.update(data); System.out.println("Signature " + (pss.verify(signature) ? "correct!" : "not correct!"));
Please note that the Java Cryptography Architecture only allows to set the salt length
as parameter and specifies all the other parameters by the algorithm standard name to be implemented by a
corresponding PSS signature engine: A signature engine that implements the, for instance,
"SHA1withRSAandMGF1" (in general: <digest>with<encryption>and<mgf>) PSS signature
algorithm has to use SHA-1 as hash- and MGF1 as mask generation algorithm. The trailer field
(0xBC) is fixed by the PKCS#1v2.1 standard and the salt length may be supplied as
parameter; if not, a default salt length (20 for the SHA-1 hash algorithm) will be used.
IAIK-JCE implements JCA PSS based signature engine for all hash algorithms supported
by the IAIK provider. The only mask generation in use is MGF1 as specified by
PKCS#1 (v.2.1). For
creating an instance of the PSS based signature engine call Signature.getInstance
thereby using the JCA PSS naming convention (<digest>with<encryption>and<mgf>), e.g.:
Signature shaRsaMgf1 = Signature.getInstance("SHA1withRSAandMGF1", "IAIK");The only parameter allowed to be set for such an JCA engine is the salt length. Because of the JDK1.1.x compatibility of IAIK-JCE there is no proper way to use the
java.security.spec.PSSParameterSpec
class for modelling the saltLength
parameter. The same functionality is provided by class RSAPssSaltParameterSpec
which may be used to supply the saltLength to this PSS based
signature engine; if no salt length is explicitly supplied, the defined default salt length
for the underlying signature engine will be used.
SHA1withRSAandMGF1
, for instance, uses
the SHA-1 algorithm for both message hashing and MGF1 hash operations. When using this general
RSASSA-PSS signature engine, hash algorithm and mask generation function have to be supplied
by the calling application. In this case it is the responsibility of the application to take
care of hash function substitution issues - if desired. This may be done by, for instance, setting
the same hash algorithm parameter for message hashing and MGF hashing, or, for instance, using
one and only hash algorithm in any case, or following any other suitable strategy.
SHAwithRSAandMGF1Signature
Field Summary | |
protected MessageDigest |
hash
The MessageDigest engine used to hash the data; supplied with an instance of the desired MessageDigest algorithm by any extending subclass. |
Fields inherited from class java.security.Signature |
SIGN, state, UNINITIALIZED, VERIFY |
Fields inherited from class java.security.SignatureSpi |
appRandom |
Constructor Summary | |
|
RSAPssSignature()
Default constructor. |
protected |
RSAPssSignature(String name)
Creates a RSAPssSignature engine with the given name. |
Method Summary | |
protected Object |
engineGetParameter(String param)
Returns the PSS parameters (hashAlgorithm, mask generation algorithm, salt length, trailer field) as RSAPssParameterSpec . |
protected AlgorithmParameters |
engineGetParameters()
Returns the PSS parameters (hashAlgorithm, mask generation algorithm, salt length, trailer field) as RSAPssParameterSpec . |
protected void |
engineInitSign(PrivateKey pk)
SPI: Initializes this Signature object with the given RSA private key for going to sign some data. |
protected void |
engineInitSign(PrivateKey pk,
SecureRandom random)
SPI: Initializes this Signature object with the given RSA private key for going to sign some data. |
protected void |
engineInitVerify(PublicKey pk)
SPI: Initializes this Signature object with the given RSA public key for performing a signature verification. |
protected void |
engineSetParameter(AlgorithmParameterSpec params)
Sets the parameters (hashAlgorithm, mask generation algorithm, salt length, trailer field) for this RSA PSS signature engine. |
protected void |
engineSetParameter(String param,
Object value)
Allows to supply a SecureRandom object if required by the underlying signature scheme (e.g. |
protected byte[] |
engineSign()
SPI: Calculates the signature. |
protected void |
engineUpdate(byte b)
SPI: Updates the data to be signed or verified with the specified byte. |
protected void |
engineUpdate(byte[] b,
int off,
int len)
SPI: Updates the data to be signed or verified with the specified number of bytes, beginning at the specified offset within the given byte array. |
protected boolean |
engineVerify(byte[] sigBytes)
Verifies the given signature. |
Methods inherited from class java.security.Signature |
clone, getAlgorithm, getInstance, getInstance, getParameter, getProvider, initSign, initSign, initVerify, initVerify, setParameter, setParameter, sign, sign, toString, update, update, update, verify |
Methods inherited from class java.security.SignatureSpi |
engineSign |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected MessageDigest hash
Constructor Detail |
public RSAPssSignature()
Signature.getInstance("RSASSA-PSS"); to create a JCA Signature engine for the RSASSA-PSS signature scheme.Default salt length is set to -1.
protected RSAPssSignature(String name)
SHAwithRSAandMGF1
Default salt length is set to -1.
name
- the name of the engineMethod Detail |
protected void engineInitSign(PrivateKey pk) throws InvalidKeyException
engineInitSign
in class iaik.security.rsa.RSAPkcs1Signature
privateKey
- the RSA private key to be used for signing.InvalidKeyException
- if a key encoding error occursprotected void engineInitVerify(PublicKey pk) throws InvalidKeyException
engineInitVerify
in class iaik.security.rsa.RSAPkcs1Signature
publicKey
- the RSA public key belonging to the RSA private key that has been used for signing.InvalidKeyException
- if a key encoding error occursprotected void engineSetParameter(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException
PKCS#1 (v.2.1) requires the following parameters for the RSA PSS signature scheme:
RSASSA-PSS-params :: = SEQUENCE { hashAlgorithm [0] HashAlgorithm DEFAULT sha1, maskGenerationAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, saltLength [2] INTEGER DEFAULT 20, trailerField [3] TrailerField DEFAULT trailerFieldBC } HashAlgorithm ::= AlgorithmIdentifer { {OAEP-PSSDigestAlgorithms} } MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} } TrailerField ::= INTEGER { trailerFieldBC(1) }This class does not use any default parameters. All parameters have to be supplied as
RSAPssParameterSpec
; the trailer field has
to be set to 1 which corresponds to the trailer field byte 0xBC, which is the only
trailer field supported by the RSA-PSS signature scheme.
An application also may use the RSAPssParameterSpec
to provide a SecureRandom object for supplying any random numbers as required by the
PSS signature algorithm. JDK 1.2 (or later) based applications may prefer to use method
initSign(PrivateKey, SecureRandom)
to supply a SecureRandom object if required.
If a SecureRandom never has been supplied by the application, the signature engine will use
a default SecureRandom for generating random numbers.
engineSetParameter
in class iaik.security.rsa.RSAPkcs1Signature
params
- the PSS parameters supplied as RSAPssParameterSpecInvalidParameterException
- if the parameters are not supplied as RSAPssParameterSpec, the
trailer field is invalid (not 1), or any of the required hash
or mgf engines is not availableprotected Object engineGetParameter(String param) throws InvalidParameterException
RSAPssParameterSpec
.engineGetParameter
in class iaik.security.rsa.RSAPkcs1Signature
RSAPssParameterSpec
.InvalidParameterException
- should not occurprotected AlgorithmParameters engineGetParameters()
RSAPssParameterSpec
.RSAPssParameterSpec
.protected byte[] engineSign() throws SignatureException
engineSign
in class SignatureSpi
SignatureException
- if an error occurs when creating the signatureprotected boolean engineVerify(byte[] sigBytes) throws SignatureException
engineVerify
in class SignatureSpi
sigBytes
- the signature bytes to be verifiedtrue
if signature is OK, false
otherwiseSignatureException
- if an error occurs when verifying the signatureprotected void engineInitSign(PrivateKey pk, SecureRandom random) throws InvalidKeyException
Note that this method is not available for JDK versions prior
JDK 1.2. When using JDK 1.1 a SecureRandom object may be supplied as
parameter
by calling method setParameter.
If a SecureRandom never has been supplied by the application, the signature engine will use
a default SecureRandom, if required.
engineInitSign
in class SignatureSpi
privateKey
- the RSA private key to be used for signing.SecureRandom
- the SecureRandom if random numbers are required by the signature engine (e.g. PSS)InvalidKeyException
- if a key encoding error occursprotected void engineUpdate(byte b)
engineUpdate
in class SignatureSpi
b
- the byte to be used for updating.protected void engineUpdate(byte[] b, int off, int len)
engineUpdate
in class SignatureSpi
b
- the byte array holding the data to be used for this update operation.off
- the offset, indicating the start position within the given byte array.len
- the number of bytes to be obtained from the given byte array, starting at the given position.protected void engineSetParameter(String param, Object value) throws InvalidParameterException
initSign(PrivateKey, SecureRandom)
is not available. If required by the underlying signature scheme (e.g. PSS) an
application may supply a SecureRandom object as parameter
.
If a SecureRandom never has been supplied by the application, the signature engine will use
a default SecureRandom, if required.engineSetParameter
in class SignatureSpi
param
- ignoredvalue
- the SecureRandom supplied as PKCS1AlgorithmParameterSpecInvalidParameterException
- if the SecureRandom is not supplied as PKCS1AlgorithmParameterSpec
|
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 |