123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- package YaoGC;
- import java.math.*;
- import sprout.oram.PID;
- import sprout.oram.TID;
- import Cipher.Cipher;
- public abstract class SimpleCircuit_2_2 extends Circuit {
- protected BigInteger[][] gtt;
- public SimpleCircuit_2_2(String name) {
- super(2, 2, name);
- }
- public void build() throws Exception {
- createInputWires();
- createOutputWires();
- }
- protected void createInputWires() {
- super.createInputWires();
- for (int i = 0; i < inDegree; i++)
- inputWires[i].addObserver(this, new TransitiveObservable.Socket(
- inputWires, i));
- }
- protected void createOutputWires() {
- outputWires[0] = new Wire();
- outputWires[1] = new Wire();
- }
- protected void execute(boolean evaluate) {
- if (evaluate) {
- execYao();
- } else {
- passTruthTable();
- }
- outputWires[0].setReady(evaluate);
- outputWires[1].setReady(evaluate);
-
-
-
- }
- protected abstract void execYao();
- protected abstract void passTruthTable();
- protected abstract boolean shortCut();
- protected abstract boolean collapse();
- protected void sendGTT() {
- timing.stopwatch[PID.gcf][TID.offline].stop();
- timing.stopwatch[PID.gcf][TID.offline_write].start();
- receiver.write(gtt[0][1]);
- receiver.write(gtt[1][0]);
- receiver.write(gtt[1][1]);
- if (outputWires[0].outBitEncPair != null)
- receiver.write(outputWires[0].outBitEncPair);
- if (outputWires[1].outBitEncPair != null)
- receiver.write(outputWires[1].outBitEncPair);
- timing.stopwatch[PID.gcf][TID.offline_write].stop();
- timing.stopwatch[PID.gcf][TID.offline].start();
- }
- protected void receiveGTT() {
- try {
- gtt = new BigInteger[2][2];
- gtt[0][0] = BigInteger.ZERO;
- timing.stopwatch[PID.gcf][TID.offline].stop();
- timing.stopwatch[PID.gcf][TID.offline_read].start();
- gtt[0][1] = sender.readBigInteger();
- gtt[1][0] = sender.readBigInteger();
- gtt[1][1] = sender.readBigInteger();
- if (outputWires[0].outBitEncPair != null)
- outputWires[0].outBitEncPair = sender.readBigIntegerArray();
- if (outputWires[1].outBitEncPair != null)
- outputWires[1].outBitEncPair = sender.readBigIntegerArray();
- timing.stopwatch[PID.gcf][TID.offline_read].stop();
- timing.stopwatch[PID.gcf][TID.offline].start();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
- protected void encryptTruthTable() {
- Wire inWireL = inputWires[0];
- Wire inWireR = inputWires[1];
- Wire outWire0 = outputWires[0];
- Wire outWire1 = outputWires[1];
- BigInteger[] labelL = { inWireL.lbl, Wire.conjugate(inWireL.lbl) };
- if (inWireL.invd == true) {
- BigInteger tmp = labelL[0];
- labelL[0] = labelL[1];
- labelL[1] = tmp;
- }
- BigInteger[] labelR = { inWireR.lbl, Wire.conjugate(inWireR.lbl) };
- if (inWireR.invd == true) {
- BigInteger tmp = labelR[0];
- labelR[0] = labelR[1];
- labelR[1] = tmp;
- }
- int k0 = outWire0.serialNum;
- int k1 = outWire1.serialNum;
- int cL = inWireL.lbl.testBit(0) ? 1 : 0;
- int cR = inWireR.lbl.testBit(0) ? 1 : 0;
- timing.stopwatch[PID.sha1][TID.offline].start();
- if (cL != 0 || cR != 0)
- gtt[0 ^ cL][0 ^ cR] = Cipher.encrypt(labelL[0], labelR[0], k0, k1,
- gtt[0 ^ cL][0 ^ cR]);
- if (cL != 0 || cR != 1)
- gtt[0 ^ cL][1 ^ cR] = Cipher.encrypt(labelL[0], labelR[1], k0, k1,
- gtt[0 ^ cL][1 ^ cR]);
- if (cL != 1 || cR != 0)
- gtt[1 ^ cL][0 ^ cR] = Cipher.encrypt(labelL[1], labelR[0], k0, k1,
- gtt[1 ^ cL][0 ^ cR]);
- if (cL != 1 || cR != 1)
- gtt[1 ^ cL][1 ^ cR] = Cipher.encrypt(labelL[1], labelR[1], k0, k1,
- gtt[1 ^ cL][1 ^ cR]);
- timing.stopwatch[PID.sha1][TID.offline].stop();
- }
- }
|