@Override public DRes<SInt> input(BigInteger value, int inputParty) { return this.delegate.input(value, inputParty); }
/** * Convenience implementation of {@link #input(BigInteger, int)} */ default DRes<SInt> input(long value, int inputParty) { return input(BigInteger.valueOf(value), inputParty); }
private List<DRes<SInt>> buildAsReceiver(Numeric nb) { List<DRes<SInt>> closed = new ArrayList<>(); for (int i = 0; i < numberOfInputs; i++) { closed.add(nb.input(null, inputParty)); } return closed; }
private List<DRes<SInt>> buildAsProvider(Numeric nb) { return openInputs.stream().map(openInput -> nb.input(openInput, inputParty)) .collect(Collectors.toList()); }
private DRes<SInt> convertToSInt(int integer, ProtocolBuilderNumeric producer) { Numeric numeric = producer.numeric(); BigInteger value = BigInteger.valueOf(integer); return numeric.input(value, 1); } }
@Override public DRes<SReal> input(BigDecimal value, int inputParty) { return builder.seq(seq -> { DRes<SInt> input = seq.numeric().input(unscaled(value, defaultPrecision), inputParty); return new SFixed(input, defaultPrecision); }); }
@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 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); } };
@Override public void test() throws Exception { // define functionality to be tested Application<BigInteger, ProtocolBuilderNumeric> testApplication = root -> { Numeric numeric = root.numeric(); AdvancedNumeric advancedNumeric = root.advancedNumeric(); DRes<SInt> left = numeric.input(leftOpen, 1); DRes<SInt> right = numeric.input(rightOpen, 1); DRes<SInt> selector = numeric.input(selectorOpen, 1); DRes<SInt> selected = advancedNumeric.condSelect(selector, left, right); return numeric.open(selected); }; BigInteger output = runApplication(testApplication); Assert.assertEquals(expected, output); } };
@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.add(left, right); return numeric.open(result); }; BigInteger output = runApplication(app); Assert.assertEquals(BigInteger.valueOf(14), 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> 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); } };
@Override public void test() { BigInteger modulus = conf.getResourcePool().getModulus(); BigInteger leftValue = modulus.subtract(BigInteger.ONE); BigInteger rightValue = BigInteger.valueOf(4); 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.add(left, right); return numeric.open(result); }; BigInteger output = runApplication(app); Assert.assertEquals(BigInteger.valueOf(3), output); } };
@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); 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> 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 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> input = numeric.input(value, 1); return numeric.open(input); }; BigInteger output = runApplication(app); Assert.assertEquals(value, output); } };
@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<Pair<BigInteger, BigInteger>, ProtocolBuilderNumeric> app = producer -> { BigInteger modulus = producer.getBasicNumericContext().getModulus(); BigInteger input = modulus.divide(BigInteger.valueOf(2)).add(BigInteger.ONE); Numeric numeric = producer.numeric(); DRes<SInt> closed = numeric.input(input, 1); DRes<BigInteger> opened = numeric.open(closed); return () -> new Pair<>(opened.out(), input); }; Pair<BigInteger, BigInteger> actualAndExpected = runApplication(app); Assert.assertEquals(actualAndExpected.getSecond(), actualAndExpected.getFirst()); } };