68 lines
2.2 KiB
Java
68 lines
2.2 KiB
Java
package profiling.Convert;
|
|
|
|
import com.google.protobuf.ByteString;
|
|
import com.google.protobuf.InvalidProtocolBufferException;
|
|
import meerkat.crypto.concrete.ECElGamalEncryption;
|
|
import meerkat.protobuf.ConcreteCrypto;
|
|
import meerkat.protobuf.Crypto;
|
|
import meerkat.protobuf.Voting;
|
|
import mixer.Utiles;
|
|
import org.bouncycastle.math.ec.ECPoint;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import qilin.primitives.concrete.ECElGamal;
|
|
import qilin.primitives.concrete.ECGroup;
|
|
|
|
import java.math.BigInteger;
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* Created by Tzlil on 1/25/2016.
|
|
*/
|
|
public class RerandomizableEncryptedMessage2ElGamalCiphertext {
|
|
Random rand;
|
|
ECElGamal.SK key;
|
|
ECGroup group;
|
|
ECElGamalEncryption enc;
|
|
ConcreteCrypto.ElGamalPublicKey serializedPk;
|
|
int tests;
|
|
Crypto.RerandomizableEncryptedMessage[] encryptedMessage;
|
|
|
|
@Before
|
|
public void setup() throws Exception {
|
|
rand = new Random();
|
|
group = new ECGroup("secp256k1");
|
|
BigInteger sk = ECElGamal.generateSecretKey(group, rand);
|
|
key = new ECElGamal.SK(group, sk);
|
|
serializedPk = Utiles.serializePk(group, key);
|
|
enc = new ECElGamalEncryption();
|
|
enc.init(serializedPk);
|
|
tests = 1024 * 18;
|
|
encryptedMessage = new Crypto.RerandomizableEncryptedMessage[tests];
|
|
|
|
Voting.PlaintextBallot msg;
|
|
|
|
for (int i = 0; i < tests; i ++){
|
|
msg = Utiles.genRandomBallot(2,3,16);
|
|
|
|
encryptedMessage[i] = enc.encrypt(msg, enc.generateRandomness(rand));
|
|
}
|
|
}
|
|
@Test
|
|
public void RerandomizableEncryptedMessage2ElGamalCiphertext() throws InvalidProtocolBufferException {
|
|
|
|
System.out.println("RerandomizableEncryptedMessage2ElGamalCiphertext");
|
|
System.out.println("#"+ tests + " tests");
|
|
System.out.println("start tests operations");
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
for (int i = 0; i < tests; i ++){
|
|
ECElGamalEncryption.RerandomizableEncryptedMessage2ElGamalCiphertext(encryptedMessage[i]);
|
|
}
|
|
|
|
long finishTime = System.currentTimeMillis();
|
|
System.out.println(" that took: "+(finishTime-startTime)+ " ms");
|
|
System.out.println(" avg of "+((double)(finishTime-startTime))/ tests + " ms");
|
|
}
|
|
}
|