FileDocCategorySizeDatePackage
JCEECDHKeyAgreement.javaAPI DocAzureus 3.0.3.44522Sun Apr 09 03:05:40 BST 2006org.bouncycastle.jce.provider

JCEECDHKeyAgreement

public class JCEECDHKeyAgreement extends KeyAgreementSpi
Diffie-Hellman key agreement using elliptic curve keys, ala IEEE P1363 both the simple one, and the simple one with cofactors are supported.

Fields Summary
private BigInteger
result
private org.bouncycastle.crypto.CipherParameters
privKey
private org.bouncycastle.crypto.BasicAgreement
agreement
Constructors Summary
protected JCEECDHKeyAgreement(org.bouncycastle.crypto.BasicAgreement agreement)

        this.agreement = agreement;
    
Methods Summary
public java.security.KeydoPhase(java.security.Key key, boolean lastPhase)

    	return( engineDoPhase( key, lastPhase ));
    
protected java.security.KeyengineDoPhase(java.security.Key key, boolean lastPhase)

        if (privKey == null)
        {
            throw new IllegalStateException("EC Diffie-Hellman not initialised.");
        }

        if (!lastPhase)
        {
            throw new IllegalStateException("EC Diffie-Hellman can only be between two parties.");
        }

        if (!(key instanceof ECPublicKey))
        {
            throw new InvalidKeyException("EC Key Agreement doPhase requires ECPublicKey");
        }

        CipherParameters pubKey = ECUtil.generatePublicKeyParameter((PublicKey)key);

        result = agreement.calculateAgreement(pubKey);

        return null;
    
protected byte[]engineGenerateSecret()

        return result.toByteArray();
    
protected intengineGenerateSecret(byte[] sharedSecret, int offset)

        byte[]  secret = result.toByteArray();

        if (sharedSecret.length - offset < secret.length)
        {
            throw new ShortBufferException("ECKeyAgreement - buffer too short");
        }

        System.arraycopy(secret, 0, sharedSecret, offset, secret.length);

        return secret.length;
    
protected javax.crypto.SecretKeyengineGenerateSecret(java.lang.String algorithm)

        return new SecretKeySpec(result.toByteArray(), algorithm);
    
protected voidengineInit(java.security.Key key, java.security.SecureRandom random)

        if (!(key instanceof ECPrivateKey))
        {
            throw new InvalidKeyException("ECKeyAgreement requires ECPrivateKey");
        }

        privKey = ECUtil.generatePrivateKeyParameter((PrivateKey)key);

        agreement.init(privKey);
    
protected voidengineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)

        if (!(key instanceof ECPrivateKey))
        {
            throw new InvalidKeyException("ECKeyAgreement requires ECPrivateKey for initialisation");
        }

        privKey = ECUtil.generatePrivateKeyParameter((PrivateKey)key);

        agreement.init(privKey);
    
public byte[]generateSecret()

    	return( engineGenerateSecret());
    
public voidinit(java.security.Key key)

    	engineInit( key, null );