// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.crypto.ec;

import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECAlgorithms;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;

public class ECElGamalDecryptor implements ECDecryptor
{
    private ECPrivateKeyParameters key;
    
    @Override
    public void init(final CipherParameters cipherParameters) {
        if (!(cipherParameters instanceof ECPrivateKeyParameters)) {
            throw new IllegalArgumentException("ECPrivateKeyParameters are required for decryption.");
        }
        this.key = (ECPrivateKeyParameters)cipherParameters;
    }
    
    @Override
    public ECPoint decrypt(final ECPair ecPair) {
        if (this.key == null) {
            throw new IllegalStateException("ECElGamalDecryptor not initialised");
        }
        final ECCurve curve = this.key.getParameters().getCurve();
        return ECAlgorithms.cleanPoint(curve, ecPair.getY()).subtract(ECAlgorithms.cleanPoint(curve, ecPair.getX()).multiply(this.key.getD())).normalize();
    }
}
