@Override public DRes<SInt> randomBit() { this.bitCount++; return this.delegate.randomBit(); }
@Override public DRes<AdvancedNumeric.RandomAdditiveMask> buildComputation( ProtocolBuilderNumeric builder) { Numeric numericBuilder = builder.numeric(); bits = new ArrayList<>(); for (int i = 0; i < noOfBits; i++) { DRes<SInt> randomBit = numericBuilder.randomBit(); bits.add(randomBit); } MiscBigIntegerGenerators oIntGenerators = builder.getBigIntegerHelper(); List<BigInteger> twoPows = oIntGenerators.getTwoPowersList(noOfBits); AdvancedNumeric innerProductBuilder = builder.advancedNumeric(); value = innerProductBuilder.innerProductWithPublicPart(twoPows, bits); return () -> new AdvancedNumeric.RandomAdditiveMask( bits, value.out()); } }
@Override public void test() { Application<List<BigInteger>, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); Collections collections = producer.collections(); int numBits = 10; List<DRes<SInt>> bits = new ArrayList<>(numBits); for (int i = 0; i < numBits; i++) { bits.add(numeric.randomBit()); } DRes<List<DRes<BigInteger>>> opened = collections.openList(() -> bits); return () -> opened.out().stream().map(DRes::out) .collect(Collectors.toList()); }; List<BigInteger> bits = runApplication(app); for (BigInteger bit : bits) { Assert.assertTrue("Expected bit but was " + bit, bit.equals(BigInteger.ZERO) || bit.equals(BigInteger.ONE)); } } };