1 package civitas.crypto.proofvote;
2
3 import java.util.List;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Controller;
7
8 import civitas.crypto.CryptoBase;
9 import civitas.crypto.ciphertext.ElGamalCiphertextish;
10 import civitas.crypto.messagedigest.CryptoHash;
11 import civitas.crypto.parameters.ElGamalParameters;
12 import civitas.crypto.reencryptfactor.ElGamalReencryptFactor;
13 import civitas.util.CivitasBigInteger;
14 import civitas.util.CivitasBigIntegerFactory;
15
16 @Controller
17 public class ConstructProofVote {
18 @Autowired
19 CryptoBase cryptoBase;
20
21 @Autowired
22 CryptoHash cryptoHash;
23
24 @Autowired
25 CalculateProofEnvironment calculateProofEnvironment;
26
27 public ProofVote apply(
28 final ElGamalParameters params,
29 final ElGamalCiphertextish encCapability,
30 final ElGamalCiphertextish encChoice,
31 final String context,
32 final ElGamalReencryptFactor alpha1,
33 final ElGamalReencryptFactor alpha2) {
34
35 CivitasBigInteger r1 = cryptoBase.generateRandomElement(params.q);
36 CivitasBigInteger r2 = cryptoBase.generateRandomElement(params.q);
37 List<CivitasBigInteger> e = calculateProofEnvironment.apply(params, encCapability, encChoice, context);
38 e.add(params.g.modPow(r1, params.p));
39 e.add(params.g.modPow(r2, params.p));
40
41 CivitasBigInteger c =
42 CivitasBigIntegerFactory.obtain(1, cryptoHash.apply(e)).mod(params.q);
43 CivitasBigInteger s1 = r1.modSubtract(c.modMultiply(alpha1.r(), params.q), params.q);
44 CivitasBigInteger s2 = r2.modSubtract(c.modMultiply(alpha2.r(), params.q), params.q);
45 return new ProofVote(c, s1, s2);
46 }
47 }