@Override public DRes<SInt> buildComputation(ProtocolBuilderNumeric builder) { AdvancedNumeric advancedNumericBuilder = builder.advancedNumeric(); DRes<SInt> divisionResult = advancedNumericBuilder.div(dividend, divisor); Numeric numeric = builder.numeric(); return numeric.sub(dividend, numeric.mult(divisor, divisionResult)); } }
@Override public DRes<SInt> buildComputation(ProtocolBuilderNumeric builder) { DRes<SInt> diff = builder.numeric().sub(left, right); return builder.comparison().compareZero(diff, bitLength); } }
@Override public DRes<SInt> sign(DRes<SInt> x) { Numeric input = builder.numeric(); // TODO create a compareLeqOrEqZero on comparison builder DRes<SInt> compare = compareLEQ(input.known(BigInteger.ZERO), x); BigInteger oint = BigInteger.valueOf(2); Numeric numericBuilder = builder.numeric(); DRes<SInt> twice = numericBuilder.mult(oint, compare); return numericBuilder.sub(twice, BigInteger.valueOf(1)); }
/** * Prints the current state of the LPSolver to System.out. NOTE: This information is useful for * debugging, but should not be revealed in production environments. */ private void printState(ProtocolBuilderNumeric builder, LpState state) { PrintStream stream = System.out; int iterations = state.iteration; builder.debug().openAndPrint("Basis [" + iterations + "]: ", state.basis, stream); builder.debug().openAndPrint("Update Matrix [" + iterations + "]: ", updateMatrix, stream); builder.debug().openAndPrint("Pivot [" + iterations + "]: ", state.prevPivot, stream); }
private DRes<SInt> getBitLength(ProtocolBuilderNumeric builder, DRes<SInt> input, int maximumBitLength) { return builder.advancedNumeric() .bitLength(input, maximumBitLength); }
@Override public DRes<SInt> add(DRes<SInt> a, DRes<SInt> b) { addCount++; return this.delegate.add(a, b); }
@Override public DRes<SInt> mult(DRes<SInt> a, DRes<SInt> b) { this.multCount++; return this.delegate.mult(a, b); }
private DRes<SInt> shiftRight(ProtocolBuilderNumeric builder, DRes<SInt> input, int numberOfPositions) { return builder.advancedNumeric() .rightShift(input, numberOfPositions); } }
@Override public DRes<SInt> sub(DRes<SInt> a, DRes<SInt> b) { subCount++; return this.delegate.sub(a, b); }
@Override public DRes<SInt> randomBit() { this.bitCount++; return this.delegate.randomBit(); }
@Override public DRes<SInt> equals(int bitLength, DRes<SInt> x, DRes<SInt> y) { eqCount++; return this.delegate.equals(x, y); }
@Override public DRes<SInt> randomElement() { this.randElmCount++; return this.delegate.randomElement(); }
ProtocolBuilderNumeric(BuilderFactoryNumeric factory, boolean parallel) { super(factory, parallel); this.factory = factory; this.basicNumericContext = factory.getBasicNumericContext(); this.realNumericContext = factory.getRealNumericContext(); }
@Override public DRes<SInt> compareLEQ(DRes<SInt> x1, DRes<SInt> x2) { leqCount++; return this.delegate.compareLEQ(x1, x2); }
/** * Creates a {@link Comparison} computation directory for this instance - i.e. this intended * producer. Contains protocols on comparing numbers and computing the sign. * * @return The comparison computation directory. */ public Comparison comparison() { if (comparison == null) { comparison = factory.createComparison(this); } return comparison; }
/** * Creates a {@link Collections} computation directory for this instance - i.e. this intended * producer. Contains operations on collections. * * @return The collections computation directory. */ public Collections collections() { if (collections == null) { collections = factory.createCollections(this); } return collections; }
/** * Creates a {@link RealLinearAlgebra} computation directory for this instance - i.e. this * intended producer. Contains linear algebra functions over fixed point numbers. * * @return The advanced real numeric computation directory. */ public RealLinearAlgebra realLinAlg() { if (realLinearAlgebra == null) { realLinearAlgebra = factory.createRealLinearAlgebra(this); } return realLinearAlgebra; }
/** * Opens and outputs the plaintext values of this tableau for debugging. * * @param builder a builder to provide the open and print functionality * @param ps a PrintStream on which to print the debugging information */ public void debugInfo(ProtocolBuilderNumeric builder, PrintStream ps) { builder.debug().openAndPrint("C: ", C, ps); builder.debug().openAndPrint("B: ", B, ps); builder.debug().openAndPrint("F: ", F, ps); builder.debug().openAndPrint("z: ", z, ps); } }