/** * Implements batched version of Authenticate sub-protocol of Protocol 4. */ private List<AuthenticatedCandidate> authenticate(List<UnauthenticatedCandidate> candidates) { List<FieldElement> flatInputs = candidates.parallelStream() .flatMap(TripleCandidate::stream) .collect(Collectors.toList()); List<List<AuthenticatedElement>> shares = new ArrayList<>(); for (int partyId = 1; partyId <= resourcePool.getNoOfParties(); partyId++) { if (partyId == resourcePool.getMyId()) { shares.add(elementGeneration.input(flatInputs)); } else { shares.add(elementGeneration.input(partyId, flatInputs.size())); } } List<AuthenticatedElement> combined = Addable.sumRows(shares); return toAuthenticatedCandidate(combined, 5); }
/** * Creates random authenticated elements. * * @param numElements number of elements to create * @return random authenticated elements */ public List<AuthenticatedElement> getRandomElements(int numElements) { List<List<AuthenticatedElement>> perPartyElements = new ArrayList<>( resourcePool.getNoOfParties()); for (int partyId = 1; partyId <= resourcePool.getNoOfParties(); partyId++) { if (partyId == resourcePool.getMyId()) { List<FieldElement> randomElements = resourcePool.getLocalSampler().getNext(numElements); perPartyElements.add(elementGeneration.input(randomElements)); } else { perPartyElements.add(elementGeneration.input(partyId, numElements)); } } return Addable.sumRows(perPartyElements); }
/** * Computes additive (unauthenticated) shares of values and distributes the shares across * parties. */ private List<FieldElement> secretShare(List<FieldElement> values, int numShares) { List<List<FieldElement>> allShares = values.stream().map(value -> sharer.share(value, numShares)).collect(Collectors.toList()); List<List<FieldElement>> byParty = TransposeUtils.transpose(allShares); for (int partyId = 1; partyId <= resourcePool.getNoOfParties(); partyId++) { // send shares to everyone but self if (partyId != resourcePool.getMyId()) { List<FieldElement> shares = byParty.get(partyId - 1); network.send(partyId, resourcePool.getFieldDefinition().serialize(shares)); } } // return own shares return byParty.get(resourcePool.getMyId() - 1); }
private void initializeMultipliers(MascotResourcePool resourcePool, Network network) { for (int partyId = 1; partyId <= resourcePool.getNoOfParties(); partyId++) { if (partyId != resourcePool.getMyId()) { if (resourcePool.getMyId() < partyId) { rightMultipliers.put(partyId, new MultiplyRight(resourcePool, network, partyId)); leftMultipliers.put(partyId, new MultiplyLeft(resourcePool, network, partyId)); } else { leftMultipliers.put(partyId, new MultiplyLeft(resourcePool, network, partyId)); rightMultipliers.put(partyId, new MultiplyRight(resourcePool, network, partyId)); } } } }
/** * Creates new {@link CommitmentBasedInput}. */ public CommitmentBasedInput(MascotResourcePool resourcePool, Network network, ByteSerializer<T> serializer) { this.resourcePool = resourcePool; this.network = network; this.serializer = serializer; // for more than two parties, we need to use broadcast if (resourcePool.getNoOfParties() > 2) { this.broadcaster = new BroadcastingNetworkProxy(network, new BroadcastValidation(resourcePool, network)); } else { // if we have two parties or less we can just use the regular network this.broadcaster = this.network; } }
/** * Initializes COPE protocols. Implements Initialize sub-protocol of Protocol 3 (with the only * difference that the mac key share has already been sampled before this protocol runs). */ private void initializeCope(MascotResourcePool resourcePool, Network network) { for (int partyId = 1; partyId <= resourcePool.getNoOfParties(); partyId++) { if (resourcePool.getMyId() != partyId) { CopeSigner signer; CopeInputter inputter; // construction order matters since receive blocks and this is not parallelized if (resourcePool.getMyId() < partyId) { signer = new CopeSigner(resourcePool, network, partyId, this.macKeyShare); inputter = new CopeInputter(resourcePool, network, partyId); } else { inputter = new CopeInputter(resourcePool, network, partyId); signer = new CopeSigner(resourcePool, network, partyId, this.macKeyShare); } copeInputters.put(partyId, inputter); copeSigners.put(partyId, signer); } } } }
for (int partyId = 1; partyId <= resourcePool.getNoOfParties(); partyId++) { if (partyId != resourcePool.getMyId()) { MultiplyLeft leftMult = leftMultipliers.get(partyId);
List<FieldElement> shares = secretShare(values, resourcePool.getNoOfParties());