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

package org.bouncycastle.crypto.signers;

import org.bouncycastle.crypto.CryptoServicesRegistrar;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.math.ec.rfc8032.Ed448;
import org.bouncycastle.crypto.params.Ed448PublicKeyParameters;
import org.bouncycastle.crypto.params.Ed448PrivateKeyParameters;
import org.bouncycastle.crypto.Xof;
import org.bouncycastle.crypto.Signer;

public class Ed448phSigner implements Signer
{
    private final Xof prehash;
    private final byte[] context;
    private boolean forSigning;
    private Ed448PrivateKeyParameters privateKey;
    private Ed448PublicKeyParameters publicKey;
    
    public Ed448phSigner(final byte[] array) {
        this.prehash = Ed448.createPrehash();
        if (null == array) {
            throw new NullPointerException("'context' cannot be null");
        }
        this.context = Arrays.clone(array);
    }
    
    @Override
    public void init(final boolean forSigning, final CipherParameters cipherParameters) {
        this.forSigning = forSigning;
        if (forSigning) {
            this.privateKey = (Ed448PrivateKeyParameters)cipherParameters;
            this.publicKey = null;
        }
        else {
            this.privateKey = null;
            this.publicKey = (Ed448PublicKeyParameters)cipherParameters;
        }
        CryptoServicesRegistrar.checkConstraints(Utils.getDefaultProperties("Ed448", 224, cipherParameters, forSigning));
        this.reset();
    }
    
    @Override
    public void update(final byte b) {
        this.prehash.update(b);
    }
    
    @Override
    public void update(final byte[] array, final int n, final int n2) {
        this.prehash.update(array, n, n2);
    }
    
    @Override
    public byte[] generateSignature() {
        if (!this.forSigning || null == this.privateKey) {
            throw new IllegalStateException("Ed448phSigner not initialised for signature generation.");
        }
        final byte[] array = new byte[64];
        if (64 != this.prehash.doFinal(array, 0, 64)) {
            throw new IllegalStateException("Prehash digest failed");
        }
        final byte[] array2 = new byte[114];
        this.privateKey.sign(1, this.context, array, 0, 64, array2, 0);
        return array2;
    }
    
    @Override
    public boolean verifySignature(final byte[] array) {
        if (this.forSigning || null == this.publicKey) {
            throw new IllegalStateException("Ed448phSigner not initialised for verification");
        }
        if (114 != array.length) {
            this.prehash.reset();
            return false;
        }
        final byte[] array2 = new byte[64];
        if (64 != this.prehash.doFinal(array2, 0, 64)) {
            throw new IllegalStateException("Prehash digest failed");
        }
        return this.publicKey.verify(1, this.context, array2, 0, 64, array, 0);
    }
    
    @Override
    public void reset() {
        this.prehash.reset();
    }
}
