/** * Creates a new Build step based on this builder but with a nested sequential protocol * producer inserted into the original protocol producer. * * @param function creation of the protocol producer - will be lazy evaluated */ public <R> BuildStep<Void, BuilderT, R> seq(Computation<R, BuilderT> function) { FrescoLambda<Void, BuilderT, R> innerBuilder = (inner, ignored) -> function.buildComputation(inner); BuildStep<Void, BuilderT, R> builder = new BuildStep<>(new BuildStepSingle<>(innerBuilder, false)); createAndAppend(new LazyProtocolProducerDecorator(() -> builder.createProducer(null, factory))); return builder; }
/** * Evaluates, on the fly, a coin-tossing computation to get joint seed. */ private byte[] runCoinTossing(Computation<byte[], ProtocolBuilderNumeric> coinTossing, Network network) { NetworkBatchDecorator networkBatchDecorator = new NetworkBatchDecorator( this.getNoOfParties(), network); BuilderFactoryNumeric builderFactory = new Spdz2kBuilder<>(factory, new BasicNumericContext(effectiveBitLength, getMyId(), getNoOfParties(), null)); ProtocolBuilderNumeric root = builderFactory.createSequential(); DRes<byte[]> jointSeed = coinTossing .buildComputation(root); ProtocolProducer coinTossingProducer = root.build(); do { ProtocolCollectionList<Spdz2kResourcePool> protocolCollectionList = new ProtocolCollectionList<>( 128); // batch size is irrelevant since this is a very light-weight protocol coinTossingProducer.getNextProtocols(protocolCollectionList); new BatchedStrategy<Spdz2kResourcePool>() .processBatch(protocolCollectionList, this, networkBatchDecorator); } while (coinTossingProducer.hasNextProtocols()); return jointSeed.out(); } }