1 package civitas.crypto.votecapabilityshare;
2
3 import civitas.crypto.parameters.ElGamalParameters;
4 import civitas.crypto.votecapability.VoteCapability;
5 import civitas.util.CivitasBigInteger;
6
7 public class CombineVoteCapabilityShares {
8
9 public VoteCapability[] apply(final VoteCapabilityShare[][] shares, final ElGamalParameters params) {
10 if (shares == null || shares[0] == null) {
11 return new VoteCapability[0];
12 }
13
14 CivitasBigInteger[] product = new CivitasBigInteger[shares[0].length];
15 for (VoteCapabilityShare[] share : shares) {
16 for (int index = 0; index < share.length; index++) {
17 VoteCapabilityShare s = share[index];
18 if (product[index] == null) {
19 product[index] = s.m();
20 } else {
21 product[index] = product[index].modMultiply(s.m(), params.p);
22 }
23 }
24 }
25 VoteCapability[] capabilities = new VoteCapability[product.length];
26 for (int index = 0; index < product.length; index++) {
27 capabilities[index] = new VoteCapability(product[index]);
28 }
29 return capabilities;
30 }
31 }