package meerkat.mixer.proofs.concrete;

import meerkat.crypto.concrete.ECElGamalEncryption;
import meerkat.mixer.proofs.generic.SigmaProtocolAnd2;
import meerkat.protobuf.Mixing;

import java.util.Random;

/**
 * Sigma protocol for plaintext equivalence of a pair of ciphertexts.
 */
public class DlogConjunction {

    public static class Prover
            extends SigmaProtocolAnd2.Prover<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.DlogProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage, Mixing.Mix2Proof.DlogProof.FinalMessage> {

        public Prover(ECElGamalEncryption encryptor, Random rand, Statements.AndStatement statement,
                      Statements.AndStatementWitness witness) {
            super(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2, new SchnorrDlogEquivalence.Prover(encryptor, rand, statement.clauses[0], witness.witnesses[0]),
                    new SchnorrDlogEquivalence.Prover(encryptor, rand, statement.clauses[1], witness.witnesses[1]));

        }
    }

    public static class Simulator extends SigmaProtocolAnd2.Simulator<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.DlogProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage, Mixing.Mix2Proof.DlogProof.FinalMessage> {
        public Simulator(ECElGamalEncryption encryptor, Random rand, Statements.AndStatement statement) {
            super(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2,
                    new SchnorrDlogEquivalence.Simulator(encryptor, rand, statement.clauses[0]), new SchnorrDlogEquivalence.Simulator(encryptor, rand, statement.clauses[1]));
        }
    }

    public static class Verifier
            extends SigmaProtocolAnd2.Verifier<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.DlogProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage, Mixing.Mix2Proof.DlogProof.FinalMessage> {

        public Verifier(ECElGamalEncryption encryptor, Statements.AndStatement statement) {
            super(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2,
                    new SchnorrDlogEquivalence.Verifier(encryptor, statement.clauses[0]), new SchnorrDlogEquivalence.Verifier(encryptor, statement.clauses[1]));
        }
    }
}
