package profiling.BigInteger; import com.google.protobuf.InvalidProtocolBufferException; import meerkat.crypto.concrete.ECElGamalEncryption; import meerkat.protobuf.ConcreteCrypto; import meerkat.protobuf.Voting; import mixer.Utiles; import org.junit.Before; import org.junit.Test; import qilin.primitives.RandomOracle; import qilin.primitives.concrete.ECElGamal; import qilin.primitives.concrete.ECGroup; import java.math.BigInteger; import java.util.Random; /** * Created by Tzlil on 1/21/2016. */ public class AddSub { int tests; BigInteger[] randoms; BigInteger[] randoms2; public void setup() throws Exception { Random rand = new Random(); tests = 1 << 17; randoms = new BigInteger[tests]; rand = new Random(); ECGroup group = new ECGroup("secp256k1"); BigInteger sk = ECElGamal.generateSecretKey(group, rand); ECElGamal.SK key = new ECElGamal.SK(group, sk); ConcreteCrypto.ElGamalPublicKey serializedPk = Utiles.serializePk(group, key); ECElGamalEncryption enc = new ECElGamalEncryption(); enc.init(serializedPk); for (int i =0 ; i < tests ; i++){ randoms[i] = new BigInteger(enc.generateRandomness(rand).getData().toByteArray()); } randoms2 = new BigInteger[tests]; for (int i =0 ; i < tests ; i++){ randoms2[i] = new BigInteger(enc.generateRandomness(rand).getData().toByteArray()); } } public void AddSubProfiling() throws InvalidProtocolBufferException { System.out.println("AddSub"); System.out.println("#" + tests + " tests"); long startTime = System.currentTimeMillis(); int i = 0; while (i < randoms.length / 2) { randoms[i].add(randoms2[i]); i++; } while (i < randoms.length) { randoms[i].subtract(randoms2[i]); i++; } long finishTime = System.currentTimeMillis(); System.out.println(" that took: "+(finishTime-startTime)+ " ms"); System.out.println(" avg of "+((double)(finishTime-startTime))/tests + " ms"); } }