package meerkat.mixer.proofs.concrete;

import meerkat.mixer.proofs.SigmaProtocol;
import meerkat.mixer.proofs.SigmaProtocolTest;
import meerkat.mixer.proofs.generic.SigmaProtocolAnd2;
import meerkat.protobuf.Mixing;
import org.factcenter.qilin.util.Pair;

import java.math.BigInteger;

/**
 * Created by talm on 12/01/17.
 */
public class DlogAndStatementSigmaTest extends SigmaProtocolTest<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage> {
    final DlogStatementSchnorrSigmaTest dlogtest;

    Statements.DlogStatement s1, s2;
    Statements.DlogStatementWitness w1, w2;

    public DlogAndStatementSigmaTest() {
        this.dlogtest = new DlogStatementSchnorrSigmaTest();
    }

    @Override
    protected void generateRandomTrueStatement() {
        Pair<Statements.DlogStatement, Statements.DlogStatementWitness> s1w1 = dlogtest.returnRandomTrueStatement();
        s1 = s1w1.a; w1 = s1w1.b;

        Pair<Statements.DlogStatement, Statements.DlogStatementWitness> s2w2 = dlogtest.returnRandomTrueStatement();
        s2 = s2w2.a; w2 = s2w2.b;
    }

    @Override
    protected void generateRandomFalseStatement() {
        s1 = dlogtest.returnRandomFalseStatement();
        s2 = dlogtest.returnRandomFalseStatement();
    }

    @Override
    protected SigmaProtocol.Prover<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage> getNewProver() {
        return new SigmaProtocolAnd2.Prover<>(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2,
                new SchnorrDlogEquivalence.Prover(dlogtest.encryptor, rand, s1, w1), new SchnorrDlogEquivalence.Prover(dlogtest.encryptor, rand, s2, w2));
    }

    @Override
    protected SigmaProtocol.Verifier<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage> getNewVerifier() {
        return new SigmaProtocolAnd2.Verifier<>(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2,
                new SchnorrDlogEquivalence.Verifier(dlogtest.encryptor, s1), new SchnorrDlogEquivalence.Verifier(dlogtest.encryptor, s2));
    }

    @Override
    protected SigmaProtocol.Simulator<Mixing.Mix2Proof.AndProof.FirstMessage, Mixing.Mix2Proof.AndProof.FinalMessage> getNewSimulator() {
        return new SigmaProtocolAnd2.Simulator<>(ProtobufConcatenators.concatAnd1, ProtobufConcatenators.concatAnd2,
                new SchnorrDlogEquivalence.Simulator(dlogtest.encryptor, rand, s1), new SchnorrDlogEquivalence.Simulator(dlogtest.encryptor, rand, s2));
    }

    @Override
    protected BigInteger getChallengeModulus() {
        return dlogtest.getChallengeModulus();
    }
}
