@Override public DRes<BigInteger> open(DRes<SInt> secretShare, int outputParty) { return this.delegate.open(secretShare, outputParty); }
@Override public DRes<Pair<DRes<BigInteger>, DRes<BigInteger>>> buildComputation( ProtocolBuilderNumeric par) { Pair<DRes<SInt>, DRes<SInt>> closedPairOut = closedPair.out(); Numeric nb = par.numeric(); Pair<DRes<BigInteger>, DRes<BigInteger>> openPair = new Pair<>(nb.open(closedPairOut.getFirst()), nb.open(closedPairOut.getSecond())); return () -> openPair; }
@Override public DRes<BigInteger> buildComputation( ProtocolBuilderNumeric producer) { List<DRes<SInt>> input = Arrays.stream(inputAsArray) .map((integer) -> convertToSInt(integer, producer)) .collect(Collectors.toList()); DRes<SInt> result = producer.advancedNumeric().sum(input); return producer.numeric().open(result); }
@Override public DRes<BigInteger> buildComputation( ProtocolBuilderNumeric producer) { DRes<SInt> result = producer.advancedNumeric().product( Arrays.stream(inputAsArray) .map((integer) -> convertToSInt(integer, producer)) .collect(Collectors.toList())); return producer.numeric().open(result); } }
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> exponent = numeric.known(BigInteger.valueOf(exp)); DRes<SInt> result = producer.advancedNumeric().exp(input, exponent, 5); return numeric.open(result); }; BigInteger result = runApplication(app); Assert.assertEquals(BigInteger.valueOf(input).pow(exp), result); } };
@Override public void test() throws Exception { Application<BigInteger, ProtocolBuilderNumeric> app = builder -> { DRes<SInt> sharedInput = builder.numeric().known(input); AdvancedNumeric bitLengthBuilder = builder.advancedNumeric(); DRes<SInt> bitLength = bitLengthBuilder.bitLength(sharedInput, input.bitLength() * 2); return builder.numeric().open(bitLength); }; BigInteger result = runApplication(app); Assert.assertEquals(BigInteger.valueOf(input.bitLength()), result); } };
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> input = numeric.input(value, 1); DRes<SInt> result = numeric.add(add, input); return numeric.open(result); }; BigInteger output = runApplication(app); Assert.assertEquals(BigInteger.valueOf(14), output); } };
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> input = numeric.input(value, 1); DRes<SInt> result = numeric.mult(constant, input); return numeric.open(result); }; BigInteger output = runApplication(app); Assert.assertEquals(BigInteger.valueOf(40), output); } };
@Override public DRes<BigDecimal> open(DRes<SReal> x) { return builder.seq(seq -> { SFixed floatX = (SFixed) x.out(); DRes<SInt> unscaled = floatX.getSInt(); DRes<BigInteger> unscaledOpen = seq.numeric().open(unscaled); int precision = floatX.getPrecision(); return () -> scaled(builder.getBasicNumericContext().getFieldDefinition(), unscaledOpen.out(), precision); }); }
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> leftClosed = numeric.input(left, 1); DRes<SInt> result = numeric.sub(leftClosed, right); return numeric.open(result); }; BigInteger actual = runApplication(app); BigInteger subtract = conf.getResourcePool().getModulus().add(BigInteger.valueOf(-6)); Assert.assertEquals(subtract, actual); } };
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = builder -> { DRes<SInt> p = builder.numeric().known(BigInteger.valueOf(numerator)); DRes<SInt> result = builder.advancedNumeric().mod(p, denominator); return builder.numeric().open(result); }; BigInteger result = runApplication(app); Assert.assertEquals(BigInteger.valueOf(numerator % denominator), result); } };
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> input = numeric.input(value, 1); return numeric.open(input); }; BigInteger output = runApplication(app); Assert.assertEquals(value, output); } };
@Override public void test() throws Exception { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> base = numeric.input(input, 1); DRes<SInt> exponent = numeric.input(BigInteger.valueOf(exp), 1); DRes<SInt> result = producer.advancedNumeric().exp(base, exponent, 5); return numeric.open(result); }; BigInteger result = runApplication(app); Assert.assertEquals(input.pow(exp), result); } };
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> rightClosed = numeric.input(right, 1); DRes<SInt> result = numeric.sub(left, rightClosed); return numeric.open(result); }; BigInteger actual = runApplication(app); BigInteger subtract = conf.getResourcePool().getModulus().add(BigInteger.valueOf(-6)); Assert.assertEquals(subtract, actual); } };
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> left = numeric.input(leftValue, 1); DRes<SInt> right = numeric.input(rightValue, 1); DRes<SInt> result = numeric.mult(left, right); return numeric.open(result); }; BigInteger output = runApplication(app); Assert.assertEquals(leftValue.multiply(rightValue), output); } };
@Test public void testRunApplication() { Application<BigInteger, ProtocolBuilderNumeric> app = builder -> { DRes<SInt> a = builder.numeric().known(BigInteger.valueOf(10)); DRes<SInt> b = builder.numeric().known(BigInteger.valueOf(10)); return builder.numeric().open(builder.numeric().add(a, b)); }; DummyArithmeticResourcePool rp = new DummyArithmeticResourcePoolImpl(0, 1, fieldDefinition); BigInteger b = sce.runApplication(app, rp, null); assertThat(b, is(BigInteger.valueOf(20))); }
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> leftClosed = numeric.input(left, 1); DRes<SInt> rightClosed = numeric.input(right, 1); DRes<SInt> result = numeric.sub(leftClosed, rightClosed); return numeric.open(result); }; BigInteger actual = runApplication(app); Assert.assertEquals(BigInteger.valueOf(6), actual); } };
@Override public DRes<SInt> buildComputation(ProtocolBuilderNumeric builder) { Numeric numeric = builder.numeric(); DRes<SInt> random = numeric.randomElement(); DRes<SInt> product = numeric.mult(value, random); DRes<BigInteger> open = numeric.open(product); return builder.seq((seq) -> { BigInteger value = open.out(); BigInteger inverse = value.modInverse(seq.getBasicNumericContext().getModulus()); return seq.numeric().mult(inverse, random); }); } }
@Override public void test() { Application<BigInteger, ProtocolBuilderNumeric> app = producer -> { Numeric numeric = producer.numeric(); DRes<SInt> left = numeric.input(leftValue, 1); DRes<SInt> right = numeric.input(rightValue, 1); DRes<SInt> result = numeric.mult(left, right); return numeric.open(result); }; BigInteger output = runApplication(app); Assert.assertEquals(BigInteger.ZERO, output); } };
@Test public void testRunApplicationLong() { Application<BigInteger, ProtocolBuilderNumeric> app = builder -> { DRes<SInt> a = builder.numeric().known(10L); DRes<SInt> b = builder.numeric().known(10L); return builder.numeric().open(builder.numeric().add(a, b)); }; DummyArithmeticResourcePool rp = new DummyArithmeticResourcePoolImpl(0, 1, fieldDefinition); BigInteger b = sce.runApplication(app, rp, null); assertThat(b, is(BigInteger.valueOf(20))); }