2016-01-25 09:48:36 -05:00
|
|
|
package profiling.BigInteger;
|
|
|
|
|
|
|
|
import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
|
import meerkat.crypto.concrete.ECElGamalEncryption;
|
|
|
|
import meerkat.protobuf.ConcreteCrypto;
|
|
|
|
import mixer.Utiles;
|
2016-04-05 04:49:34 -04:00
|
|
|
import org.factcenter.qilin.primitives.concrete.ECElGamal;
|
|
|
|
import org.factcenter.qilin.primitives.concrete.ECGroup;
|
2016-01-25 09:48:36 -05:00
|
|
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Tzlil on 1/21/2016.
|
|
|
|
*/
|
|
|
|
public class Modulo {
|
|
|
|
int tests;
|
|
|
|
BigInteger[] randoms;
|
|
|
|
BigInteger orderUpperBound;
|
|
|
|
|
|
|
|
public void setup() throws Exception {
|
|
|
|
Random rand = new Random();
|
|
|
|
ECGroup group = new ECGroup("secp256k1");
|
|
|
|
orderUpperBound = group.orderUpperBound();
|
|
|
|
tests = 1<<17;
|
|
|
|
randoms = new BigInteger[tests];
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ModuloProfiling() throws InvalidProtocolBufferException {
|
|
|
|
|
|
|
|
System.out.println("ModuloProfiling");
|
|
|
|
System.out.println("#" + tests + " tests");
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
for (int i = 0 ; i < randoms.length;i++) {
|
|
|
|
randoms[i].mod(orderUpperBound);
|
|
|
|
}
|
|
|
|
long finishTime = System.currentTimeMillis();
|
|
|
|
System.out.println(" that took: "+(finishTime-startTime)+ " ms");
|
|
|
|
System.out.println(" avg of "+((double)(finishTime-startTime))/tests + " ms");
|
|
|
|
}
|
|
|
|
}
|