package profiling.BigInteger;

import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.crypto.concrete.ECElGamalEncryption;
import meerkat.crypto.concrete.Util;
import meerkat.protobuf.ConcreteCrypto;
import meerkat.mixer.Utils;
import org.factcenter.qilin.primitives.concrete.ECElGamal;
import org.factcenter.qilin.primitives.concrete.ECGroup;

import java.math.BigInteger;
import java.util.Random;

/**
 * Created by Tzlil on 1/25/2016.
 */
public class GenerateRandomness {
    int tests;
    ECElGamalEncryption enc;
    Random rand;

    public void setup() throws Exception {
        rand = new Random();
        ECGroup group = new ECGroup("secp256k1");
        tests = 1<<18;

        BigInteger sk = ECElGamal.generateSecretKey(group, rand);
        ECElGamal.SK key = new ECElGamal.SK(group, sk);
        ConcreteCrypto.ElGamalPublicKey serializedPk = Util.encodePK(group, key);
        enc = new ECElGamalEncryption();
        enc.init(serializedPk);

    }

    public void GenerateRandomnessProfiling() throws InvalidProtocolBufferException {

        System.out.println("GenerateRandomnessProfiling");
        System.out.println("#" + tests + " tests");
        long startTime = System.currentTimeMillis();
        for (int i =0 ; i < tests ; i++){
            enc.generateRandomness(rand).getData().toByteArray();
        }
        long finishTime = System.currentTimeMillis();
        System.out.println("    that took: "+(finishTime-startTime)+ " ms");
        System.out.println("    avg of "+((double)(finishTime-startTime))/tests + " ms");
    }
}
