1 package civitas.crypto.petcommitment;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Controller;
5
6 import civitas.crypto.messagedigest.CryptoHash;
7 import civitas.crypto.parameters.ElGamalParameters;
8 import civitas.crypto.petshare.PETShare;
9 import civitas.util.CivitasBigInteger;
10
11 @Controller
12 public class ConstructPETCommitment {
13
14 @Autowired
15 CryptoHash cryptoHash;
16
17 public PETCommitment apply(final PETShare that, final ElGamalParameters params) {
18 CivitasBigInteger d =
19 that.ciphertext1().getA().modDivide(that.ciphertext2().getA(), params.p);
20 CivitasBigInteger e =
21 that.ciphertext1().getB().modDivide(that.ciphertext2().getB(), params.p);
22
23 CivitasBigInteger di = d.modPow(that.exponent(), params.p);
24 CivitasBigInteger ei = e.modPow(that.exponent(), params.p);
25
26 return new PETCommitment(cryptoHash.apply(di, ei, null, null));
27 }
28 }