@Override public DRes<SBool> xor(DRes<SBool> left, DRes<SBool> right) { this.xorCount++; return this.delegate.xor(left, right); }
xorKey = leftKey.stream().map(e -> seq.binary().xor(e, rightKey.get(leftKey.indexOf(e)))) .collect(Collectors.toList()); leftValue.stream().map(e -> seq.binary().xor(e, rightValue.get(leftValue.indexOf(e)))) .collect(Collectors.toList()); return () -> comparison; }).par((par, data) -> { List<DRes<SBool>> lastValue = xorValue.stream().map(e -> par.binary().xor(e, data.getSecond().get(xorValue.indexOf(e)))) .collect(Collectors.toList()); xorKey.stream().map(e -> par.binary().xor(e, data.getFirst().get(xorKey.indexOf(e)))) .collect(Collectors.toList());
@Override public DRes<SBool> buildComputation(ProtocolBuilderBinary builder) { DRes<SBool> tmp = builder.binary().xor(inA, inB); return builder.binary().not(tmp); } }
@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; }); }
outWireXor = builder.binary().xor(leftInWireXor, rightInWireXor); this.wires.put(out[0], outWireXor);
}).seq((seq, ors) -> { List<DRes<SBool>> xors = new ArrayList<>(); xors.add(seq.binary().xor(ors.get(0), seq.binary().known(false))); xors.add(seq.binary().xor(ors.get(i - 1), ors.get(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)));
commonKey.add(bin.xor(key1Inputs.get(i), key2Inputs.get(i)));
@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>> xors = new ArrayList<>(); xors.add(builder.open(builder.xor(falseBool, falseBool))); xors.add(builder.open(builder.xor(trueBool, falseBool))); xors.add(builder.open(builder.xor(falseBool, trueBool))); xors.add(builder.open(builder.xor(trueBool, trueBool))); return () -> xors; }).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(true, outs.get(1)); Assert.assertEquals(true, outs.get(2)); Assert.assertEquals(false, outs.get(3)); } } };
@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.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)); } } };