@Override public DRes<SBool> and(DRes<SBool> left, DRes<SBool> right) { this.andCount++; return this.delegate.and(left, right); }
@Override public DRes<SBool> buildComputation(ProtocolBuilderBinary builder) { Binary binary = builder.binary(); DRes<SBool> x = binary.xor(a, b); DRes<SBool> y = binary.and(selector, x); return binary.xor(y, b); }
outWireAnd = builder.binary().and(leftInWireAnd, rightInWireAnd); this.wires.put(out[0], outWireAnd); } else if ("INV".equals(type)) {
@Override public DRes<SBool> buildComputation(ProtocolBuilderBinary builder) { DRes<SBool> tmp = builder.binary().and(inA, inB); return builder.binary().not(tmp); } }
int idx = 0; while (idx < input.size() - 1) { ands.add(par.binary().and(input.get(idx), input.get(idx + 1))); idx += 2;
for (int i = 0; i < xors.size(); i++) { boolean ithBit = ithBit(xors.size() - 1 - i, res.size() - 1 - j); //j'th bit of i DRes<SBool> tmp = seq.binary().and(xors.get(i), seq.binary().known(ithBit)); res.add(j, seq.binary().xor(tmp, res.remove(j)));
@Override public DRes<SBool> buildComputation(ProtocolBuilderBinary builder) { return builder.seq(seq -> { int round = 0; DRes<SBool> xor = seq.binary().xor(inA.get(length - 1), inB.get(length - 1)); round++; DRes<SBool> outC = seq.binary().and(inA.get(length - 1), xor); round++; return new IterationState(round, outC); }).whileLoop( (state) -> state.round <= length, (seq, state) -> { int i = length - state.round; DRes<SBool> xor = seq.binary().xor(inA.get(i), inB.get(i)); DRes<SBool> tmp = seq.binary().xor(inA.get(i), state.value); tmp = seq.binary().and(tmp, xor); DRes<SBool> outC = seq.binary().xor(state.value, tmp); return new IterationState(state.round + 1, outC); }).seq((state, seq) -> { return seq.value; }); }
@Override public DRes<SBool> buildComputation(ProtocolBuilderBinary builder) { DRes<SBool> t0 = builder.binary().and(inA, inB); DRes<SBool> t1 = builder.binary().xor(inA, inB); return builder.binary().xor(t0, t1); } }
@Override public DRes<Pair<SBool, SBool>> buildComputation(ProtocolBuilderBinary builder) { return builder.par(par -> { DRes<SBool> res = par.binary().xor(left, right); DRes<SBool> carry = par.binary().and(left, right); return () -> new Pair<SBool, SBool>(res.out(), carry.out()); }); }
@Override public void test() throws Exception { Application<List<Boolean>, ProtocolBuilderBinary> app = producer -> producer.seq(seq -> { Binary builder = seq.binary(); DRes<SBool> falseBool = builder.known(false); DRes<SBool> trueBool = builder.known(true); List<DRes<Boolean>> list = new ArrayList<>(); list.add(builder.open(builder.and(falseBool, falseBool))); list.add(builder.open(builder.and(trueBool, falseBool))); list.add(builder.open(builder.and(falseBool, trueBool))); list.add(builder.open(builder.and(trueBool, trueBool))); return () -> list; }).seq((seq, list) -> { return () -> list.stream().map(DRes::out).collect(Collectors.toList()); }); List<Boolean> outs = runApplication(app); if (doAsserts) { Assert.assertEquals(false, outs.get(0)); Assert.assertEquals(false, outs.get(1)); Assert.assertEquals(false, outs.get(2)); Assert.assertEquals(true, outs.get(3)); } } };
@Override public DRes<Pair<SBool, SBool>> buildComputation(ProtocolBuilderBinary builder) { return builder.par(par -> { xor1 = par.binary().xor(valueA, valueB); and1 = par.binary().and(valueA, valueB); return () -> (par); }).par((par, pair) -> { xor2 = par.binary().xor(xor1, carry); and2 = par.binary().and(xor1, carry); return () -> (par); }).par((par, pair) -> { xor3 = par.binary().xor(and2, and1); return () -> new Pair<SBool, SBool>(xor2.out(), xor3.out()); }); } }
@Override public void test() throws Exception { Application<List<Boolean>, ProtocolBuilderBinary> app = producer -> producer.seq(seq -> { Binary builder = seq.binary(); DRes<SBool> falseBool = builder.known(false); DRes<SBool> trueBool = builder.known(true); List<DRes<Boolean>> list = new ArrayList<>(); list.add(builder .open(builder.not(builder.and(builder.xor(falseBool, falseBool), falseBool)))); list.add(builder .open(builder.not(builder.and(builder.xor(falseBool, trueBool), falseBool)))); list.add( builder.open(builder.not(builder.and(builder.xor(trueBool, falseBool), trueBool)))); list.add( builder.open(builder.not(builder.and(builder.xor(trueBool, trueBool), trueBool)))); return () -> list; }).seq((seq, list) -> { return () -> list.stream().map(DRes::out).collect(Collectors.toList()); }); List<Boolean> outs = runApplication(app); if (doAsserts) { Assert.assertEquals(true, outs.get(0)); Assert.assertEquals(true, outs.get(1)); Assert.assertEquals(false, outs.get(2)); Assert.assertEquals(true, outs.get(3)); } } };
List<DRes<SBool>> list = new ArrayList<>(); for (int i = 0; i < amount; i++) { list.add(builder.and(falseBool, trueBool));