boolean receiveBroadcastValidation(Network network, byte[] digest) { //TODO: should we check that we get messages from all players? boolean validated = true; List<byte[]> digests = network.receiveFromAll(); for (byte[] d : digests) { boolean equals = Arrays.equals(d, digest); validated = validated && equals; } return validated; } }
/** * Receives digests from other parties and checks that these are consistent with own digest. */ public void receiveAndValidateDigests(byte[] ownDigest) { List<byte[]> received = network.receiveFromAll(); validateDigests(ownDigest, received); }
/** * Sends own opening info to others and receives others' opening info. * * @param opening own opening info */ private List<byte[]> distributeOpenings(byte[] opening) { // send (over regular network) own opening info network.sendToAll(opening); // receive opening info from others return network.receiveFromAll(); }
/** * Runs broadcast validation upon receiving messages to ensure consistency. */ @Override public List<byte[]> receiveFromAll() { List<byte[]> received = network.receiveFromAll(); validator.validate(received); return received; }
private boolean receiveMaliciousBroadcastValidation(Network network, byte[] digest) { // TODO: should we check that we get messages from all players? boolean validated = true; List<byte[]> digests = network.receiveFromAll(); for (byte[] d : digests) { boolean equals = Arrays.equals(d, digest); validated = validated && equals; } return validated; } }
private boolean receiveMaliciousBroadcastValidation(Network network, byte[] digest) { // TODO: should we check that we get messages from all players? boolean validated = true; List<byte[]> digests = network.receiveFromAll(); for (byte[] d : digests) { boolean equals = Arrays.equals(d, digest); validated = validated && equals; } return validated; } }
private boolean receiveMaliciousBroadcastValidation(Network network, byte[] digest) { // TODO: should we check that we get messages from all players? boolean validated = true; List<byte[]> digests = network.receiveFromAll(); for (byte[] d : digests) { boolean equals = Arrays.equals(d, digest); validated = validated && equals; } return validated; } }
@Override public EvaluationStatus evaluate(int round, ResourcePoolT resourcePool, Network network) { if (round == 0) { network.sendToAll(input.clone()); return EvaluationStatus.HAS_MORE_ROUNDS; } else { result = network.receiveFromAll(); return EvaluationStatus.IS_DONE; } } }
/** * Opens secret elements (distributes shares among all parties and recombines). Implements Open * sub-protocol of Protocol 3. * * @param closed authenticated elements to open * @return opened value */ public List<FieldElement> open(List<AuthenticatedElement> closed) { // get shares from authenticated elements (step 1) List<FieldElement> ownShares = closed.stream().map(AuthenticatedElement::getShare).collect(Collectors.toList()); // send own shares to others network.sendToAll(resourcePool.getFieldDefinition().serialize(ownShares)); // receive others' shares List<byte[]> rawShares = network.receiveFromAll(); // parse List<List<FieldElement>> shares = rawShares.stream() .map(resourcePool.getFieldDefinition()::deserializeList) .collect(Collectors.toList()); // recombine (step 2) return Addable.sumRows(shares); }
/** * Sends own commitment to others and receives others' commitments. * * @param comm own commitment */ private List<HashBasedCommitment> distributeCommitments(HashBasedCommitment comm) { // broadcast own commitment broadcaster.sendToAll(getResourcePool().getCommitmentSerializer().serialize(comm)); // receive other parties' commitments from broadcast List<byte[]> rawComms = broadcaster.receiveFromAll(); // parse return rawComms.stream() .map(getResourcePool().getCommitmentSerializer()::deserialize) .collect(Collectors.toList()); }
/** * Performs broadcast validation on a list of messages. * * @param messages messages to validate */ public void validate(List<byte[]> messages) { // compute digest byte[] digest = computeDigest(messages); // send it to others network.sendToAll(digest); // receive others' digests List<byte[]> digests = network.receiveFromAll(); // validate digests validateDigests(digest, digests); }
} else if (round == 1) { List<byte[]> commitments = network.receiveFromAll(); for (int i = 0; i < commitments.size(); i++) { comms.put(i + 1, commitments.get(i));
} else if (round == 1) { List<byte[]> values = network.receiveFromAll(); List<byte[]> randomnesses = network.receiveFromAll();
@Override public EvaluationStatus evaluate(int round, SpdzResourcePool spdzResourcePool, Network network) { FieldDefinition definition = spdzResourcePool.getFieldDefinition(); if (round == 0) { SpdzSInt out = (SpdzSInt) in.out(); network.sendToAll((out.serializeShare(definition))); return EvaluationStatus.HAS_MORE_ROUNDS; } else { List<byte[]> shares = network.receiveFromAll(); FieldElement openedVal = definition.deserialize(shares.get(0)); for (int i = 1; i < shares.size(); i++) { byte[] buffer = shares.get(i); openedVal = openedVal.add(definition.deserialize(buffer)); } spdzResourcePool.getOpenedValueStore().pushOpenedValue(((SpdzSInt) in.out()), openedVal); this.out = definition.convertToUnsigned(openedVal); return EvaluationStatus.IS_DONE; } }
@Override public EvaluationStatus evaluate(int round, ResourcePoolImpl resourcePool, Network network) { TinyTablesProtocolSuite ps = TinyTablesProtocolSuite.getInstance(resourcePool.getMyId()); /* * When opening a value, all players send their shares of the masking value r to the other * players, and each player can then calculate the unmasked value as the XOR of the masked value * and all the shares of the mask. */ if (round == 0) { TinyTablesElement myR = ps.getStorage().getMaskShare(id); network.sendToAll(new byte[]{BooleanSerializer.toBytes(myR.getShare())}); return EvaluationStatus.HAS_MORE_ROUNDS; } else { // round > 0 List<byte[]> buffers = network.receiveFromAll(); List<TinyTablesElement> maskShares = new ArrayList<>(); for (byte[] buffer : buffers) { maskShares.add(TinyTablesElement.getInstance(BooleanSerializer.fromBytes(buffer[0]))); } boolean mask = TinyTablesElement.open(maskShares); this.opened = ((TinyTablesSBool) toOpen.out()).getValue().getShare() ^ mask; return EvaluationStatus.IS_DONE; } }
@Override public EvaluationStatus evaluate(int round, ResourcePoolImpl resourcePool, Network network) { TinyTablesProtocolSuite ps = TinyTablesProtocolSuite.getInstance(resourcePool.getMyId()); if (round == 0) { TinyTable tinyTable = Objects.requireNonNull(ps.getStorage().getTinyTable(id), "Unable to find TinyTable for gate with id " + id); TinyTablesElement myShare = tinyTable.getValue(((TinyTablesSBool) inLeft.out()).getValue(), ((TinyTablesSBool) inRight.out()).getValue()); network.sendToAll(new byte[]{BooleanSerializer.toBytes(myShare.getShare())}); return EvaluationStatus.HAS_MORE_ROUNDS; } else { List<byte[]> buffers = network.receiveFromAll(); List<TinyTablesElement> shares = new ArrayList<>(); for (byte[] bytes : buffers) { shares.add(TinyTablesElement.getInstance(BooleanSerializer.fromBytes(bytes[0]))); } boolean open = TinyTablesElement.open(shares); this.out = TinyTablesSBool.getInstance(TinyTablesElement.getInstance(open)); return EvaluationStatus.IS_DONE; } }
@Override public EvaluationStatus evaluate(int round, SpdzResourcePool spdzResourcePool, Network network) { int players = spdzResourcePool.getNoOfParties(); FieldDefinition definition = spdzResourcePool.getFieldDefinition(); if (round == 0) { network.sendToAll(commitment.computeCommitment(definition)); return EvaluationStatus.HAS_MORE_ROUNDS; } else if (round == 1) { List<byte[]> commitments = network.receiveFromAll(); for (int i = 0; i < commitments.size(); i++) { comms.put(i + 1, commitments.get(i)); } if (players < 3) { this.result = true; return EvaluationStatus.IS_DONE; } else { broadcastDigest = sendMaliciousBroadcastValidation(spdzResourcePool.getMessageDigest(), network, comms.values()); return EvaluationStatus.HAS_MORE_ROUNDS; } } else { this.result = receiveMaliciousBroadcastValidation(network, broadcastDigest); return EvaluationStatus.IS_DONE; } }
@Override public EvaluationStatus evaluate(int round, SpdzResourcePool spdzResourcePool, Network network) { int myId = spdzResourcePool.getMyId(); SpdzDataSupplier dataSupplier = spdzResourcePool.getDataSupplier(); FieldDefinition definition = spdzResourcePool.getFieldDefinition(); if (round == 0) { this.mask = dataSupplier.getNextInputMask(targetPlayer); SpdzSInt closedValue = (SpdzSInt) this.in.out(); inMinusMask = closedValue.subtract(this.mask.getMask()); network.sendToAll(inMinusMask.serializeShare(definition)); return EvaluationStatus.HAS_MORE_ROUNDS; } else { List<byte[]> shares = network.receiveFromAll(); FieldElement openedVal = definition.deserialize(shares.get(0)); for (int i = 1; i < shares.size(); i++) { byte[] buffer = shares.get(i); openedVal = openedVal.add(definition.deserialize(buffer)); } spdzResourcePool.getOpenedValueStore().pushOpenedValue(inMinusMask, openedVal); if (targetPlayer == myId) { openedVal = openedVal.add(this.mask.getRealValue()); this.out = definition.convertToUnsigned(openedVal); } return EvaluationStatus.IS_DONE; } } }
@Override public EvaluationStatus evaluate(int round, Spdz2kResourcePool<PlainT> resourcePool, Network network) { OpenedValueStore<Spdz2kSInt<PlainT>, PlainT> openedValueStore = resourcePool .getOpenedValueStore(); if (round == 0) { authenticatedElement = toSpdz2kSInt(share); network.sendToAll(authenticatedElement .getShare() .getLeastSignificant() .toByteArray()); return EvaluationStatus.HAS_MORE_ROUNDS; } else { ByteSerializer<PlainT> serializer = resourcePool .getFactory() .getSerializer(); List<PlainT> shares = serializer.deserializeList(network.receiveFromAll()); PlainT recombined = UInt.sum(shares); openedValueStore.pushOpenedValue(authenticatedElement, recombined); this.opened = recombined .getLeastSignificant() .toBigInteger(); return EvaluationStatus.IS_DONE; } }
@Override public EvaluationStatus evaluate(int round, Spdz2kResourcePool<PlainT> resourcePool, Network network) { OpenedValueStore<Spdz2kSInt<PlainT>, PlainT> openedValueStore = resourcePool .getOpenedValueStore(); Spdz2kDataSupplier<PlainT> supplier = resourcePool.getDataSupplier(); if (round == 0) { this.inputMask = supplier.getNextInputMask(outputParty); inMinusMask = toSpdz2kSInt(share).subtract(this.inputMask.getMaskShare()); network.sendToAll(inMinusMask .getShare() .getLeastSignificant() .toByteArray()); return EvaluationStatus.HAS_MORE_ROUNDS; } else { List<PlainT> shares = resourcePool .getFactory() .getSerializer() .deserializeList(network.receiveFromAll()); PlainT recombined = UInt.sum(shares); openedValueStore.pushOpenedValue(inMinusMask, recombined); if (outputParty == resourcePool.getMyId()) { this.opened = recombined.add(inputMask.getOpenValue()) .getLeastSignificant() .toBigInteger(); } return EvaluationStatus.IS_DONE; } }