meerkat-java/mixer/src/test/java/profiling/Convert/RerandomizableEncryptedMess...

63 lines
2.1 KiB
Java
Raw Normal View History

2016-01-25 09:48:36 -05:00
package profiling.Convert;
2016-01-20 05:14:15 -05:00
import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.crypto.concrete.ECElGamalEncryption;
import meerkat.protobuf.ConcreteCrypto;
import meerkat.protobuf.Crypto;
import meerkat.protobuf.Voting;
2016-04-17 02:09:13 -04:00
import meerkat.mixer.Utils;
2016-04-05 04:49:34 -04:00
import org.factcenter.qilin.primitives.concrete.ECElGamal;
import org.factcenter.qilin.primitives.concrete.ECGroup;
2016-01-20 05:14:15 -05:00
import java.math.BigInteger;
import java.util.Random;
/**
2016-01-25 09:48:36 -05:00
* Created by Tzlil on 1/25/2016.
2016-01-20 05:14:15 -05:00
*/
2016-01-25 09:48:36 -05:00
public class RerandomizableEncryptedMessage2ElGamalCiphertext {
2016-01-20 05:14:15 -05:00
Random rand;
ECElGamal.SK key;
ECGroup group;
ECElGamalEncryption enc;
ConcreteCrypto.ElGamalPublicKey serializedPk;
2016-01-25 09:48:36 -05:00
int tests;
2016-01-20 05:14:15 -05:00
Crypto.RerandomizableEncryptedMessage[] encryptedMessage;
public void setup() throws Exception {
rand = new Random();
group = new ECGroup("secp256k1");
BigInteger sk = ECElGamal.generateSecretKey(group, rand);
key = new ECElGamal.SK(group, sk);
2016-04-05 04:51:01 -04:00
serializedPk = Utils.serializePk(group, key);
2016-01-20 05:14:15 -05:00
enc = new ECElGamalEncryption();
enc.init(serializedPk);
2016-01-25 09:48:36 -05:00
tests = 1024 * 18;
encryptedMessage = new Crypto.RerandomizableEncryptedMessage[tests];
2016-01-20 05:14:15 -05:00
Voting.PlaintextBallot msg;
2016-01-25 09:48:36 -05:00
for (int i = 0; i < tests; i ++){
2016-04-05 04:51:01 -04:00
msg = Utils.genRandomBallot(2,3,16);
2016-01-25 09:48:36 -05:00
2016-01-20 05:14:15 -05:00
encryptedMessage[i] = enc.encrypt(msg, enc.generateRandomness(rand));
}
}
2016-03-20 13:18:23 -04:00
2016-01-25 09:48:36 -05:00
public void RerandomizableEncryptedMessage2ElGamalCiphertext() throws InvalidProtocolBufferException {
2016-01-20 05:14:15 -05:00
2016-01-25 09:48:36 -05:00
System.out.println("RerandomizableEncryptedMessage2ElGamalCiphertext");
System.out.println("#"+ tests + " tests");
System.out.println("start tests operations");
2016-01-20 05:14:15 -05:00
long startTime = System.currentTimeMillis();
2016-01-25 09:48:36 -05:00
for (int i = 0; i < tests; i ++){
ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(encryptedMessage[i]);
2016-01-20 05:14:15 -05:00
}
long finishTime = System.currentTimeMillis();
System.out.println(" that took: "+(finishTime-startTime)+ " ms");
2016-01-25 09:48:36 -05:00
System.out.println(" avg of "+((double)(finishTime-startTime))/ tests + " ms");
2016-01-20 05:14:15 -05:00
}
}