FileDocCategorySizeDatePackage
JDKPSSSigner.javaAPI DocAndroid 1.5 API8802Wed May 06 22:41:06 BST 2009org.bouncycastle.jce.provider

JDKPSSSigner

public class JDKPSSSigner extends Signature

Fields Summary
private AlgorithmParameters
engineParams
private PSSParameterSpec
paramSpec
private PSSParameterSpec
originalSpec
private org.bouncycastle.crypto.AsymmetricBlockCipher
signer
private org.bouncycastle.crypto.Digest
digest
private int
saltLength
private byte
trailer
private org.bouncycastle.crypto.signers.PSSSigner
pss
Constructors Summary
protected JDKPSSSigner(String name, org.bouncycastle.crypto.AsymmetricBlockCipher signer, PSSParameterSpec paramSpec)

        super(name);

        this.signer = signer;
        
        if (paramSpec == null)
        {
            originalSpec = null;
            paramSpec = PSSParameterSpec.DEFAULT;
        }
        else
        {
            originalSpec = paramSpec;
            this.paramSpec = paramSpec;
        }
        
        this.digest = JCEDigestUtil.getDigest(paramSpec.getDigestAlgorithm());
        this.saltLength = paramSpec.getSaltLength();
        this.trailer = getTrailer(paramSpec.getTrailerField());
    
Methods Summary
protected java.lang.ObjectengineGetParameter(java.lang.String param)

        throw new UnsupportedOperationException("engineGetParameter unsupported");
    
protected java.security.AlgorithmParametersengineGetParameters()

        if (engineParams == null)
        {
            if (paramSpec != null)
            {
                try
                {
                    engineParams = AlgorithmParameters.getInstance("PSS", "BC");
                    engineParams.init(paramSpec);
                }
                catch (Exception e)
                {
                    throw new RuntimeException(e.toString());
                }
            }
        }

        return engineParams;
    
protected voidengineInitSign(java.security.PrivateKey privateKey, java.security.SecureRandom random)

        if (!(privateKey instanceof RSAPrivateKey))
        {
            throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
        }

        pss = new PSSSigner(signer, digest, saltLength, trailer);
        pss.init(true, new ParametersWithRandom(RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey), random));
    
protected voidengineInitSign(java.security.PrivateKey privateKey)

        if (!(privateKey instanceof RSAPrivateKey))
        {
            throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
        }

        pss = new PSSSigner(signer, digest, saltLength, trailer);
        pss.init(true, RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey));
    
protected voidengineInitVerify(java.security.PublicKey publicKey)

        if (!(publicKey instanceof RSAPublicKey))
        {
            throw new InvalidKeyException("Supplied key is not a RSAPublicKey instance");
        }

        pss = new PSSSigner(signer, digest, saltLength);
        pss.init(false,
            RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey));
    
protected voidengineSetParameter(java.security.spec.AlgorithmParameterSpec params)

        if (params instanceof PSSParameterSpec)
        {
            paramSpec = (PSSParameterSpec)params;
            
            if (originalSpec != null)
            {
                if (!JCEDigestUtil.isSameDigest(originalSpec.getDigestAlgorithm(), paramSpec.getDigestAlgorithm()))
                {
                    throw new InvalidParameterException("parameter must be using " + originalSpec.getDigestAlgorithm());
                }
            }
            if (!paramSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !paramSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId()))
            {
                throw new InvalidParameterException("unknown mask generation function specified");
            }
            
            if (!(paramSpec.getMGFParameters() instanceof MGF1ParameterSpec))
            {
                throw new InvalidParameterException("unkown MGF parameters");
            }
            
            MGF1ParameterSpec   mgfParams = (MGF1ParameterSpec)paramSpec.getMGFParameters();
            
            if (!JCEDigestUtil.isSameDigest(mgfParams.getDigestAlgorithm(), paramSpec.getDigestAlgorithm()))
            {
                throw new InvalidParameterException("digest algorithm for MGF should be the same as for PSS parameters.");
            }
            
            digest = JCEDigestUtil.getDigest(mgfParams.getDigestAlgorithm());
            
            if (digest == null)
            {
                throw new InvalidParameterException("no match on MGF digest algorithm: "+ mgfParams.getDigestAlgorithm());
            }
            
            this.saltLength = paramSpec.getSaltLength();
            this.trailer = getTrailer(paramSpec.getTrailerField());
        }
        else
        {
            throw new InvalidParameterException("Only PSSParameterSpec supported");
        }
    
protected voidengineSetParameter(java.lang.String param, java.lang.Object value)

deprecated
replaced with

        throw new UnsupportedOperationException("engineSetParameter unsupported");
    
protected byte[]engineSign()

        try
        {
            return pss.generateSignature();
        }
        catch (CryptoException e)
        {
            throw new SignatureException(e.getMessage());
        }
    
protected voidengineUpdate(byte b)

        pss.update(b);
    
protected voidengineUpdate(byte[] b, int off, int len)

        pss.update(b, off, len);
    
protected booleanengineVerify(byte[] sigBytes)

        return pss.verifySignature(sigBytes);
    
private bytegetTrailer(int trailerField)

        if (trailerField == 1)
        {
            return PSSSigner.TRAILER_IMPLICIT;
        }
        
        throw new IllegalArgumentException("unknown trailer field");