GCEva.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.oblivm.backend.gc.offline;
  2. import com.oblivm.backend.flexsc.Flag;
  3. import com.oblivm.backend.flexsc.Mode;
  4. import com.oblivm.backend.gc.GCEvaComp;
  5. import com.oblivm.backend.gc.GCSignal;
  6. import com.oblivm.backend.network.Network;
  7. public class GCEva extends GCEvaComp {
  8. Garbler gb;
  9. GCSignal[][] gtt = new GCSignal[2][2];
  10. public GCEva(Network channel) {
  11. super(channel, Mode.OFFLINE);
  12. gb = new Garbler();
  13. gtt[0][0] = GCSignal.ZERO;
  14. }
  15. private void receiveGTT() {
  16. try {
  17. Flag.sw.startGCIO();
  18. gtt[0][1] = GCSignal.receive(channel);
  19. gtt[1][0] = GCSignal.receive(channel);
  20. gtt[1][1] = GCSignal.receive(channel);
  21. Flag.sw.stopGCIO();
  22. } catch (Exception e) {
  23. e.printStackTrace();
  24. System.exit(1);
  25. }
  26. }
  27. public GCSignal and(GCSignal a, GCSignal b) {
  28. Flag.sw.startGC();
  29. GCSignal res;
  30. if (a.isPublic() && b.isPublic())
  31. res = ((a.v && b.v) ? new GCSignal(true) : new GCSignal(false));
  32. else if (a.isPublic())
  33. res = a.v ? b : new GCSignal(false);
  34. else if (b.isPublic())
  35. res = b.v ? a : new GCSignal(false);
  36. else {
  37. ++numOfAnds;
  38. receiveGTT();
  39. int i0 = a.getLSB();
  40. int i1 = b.getLSB();
  41. res = gb.dec(a, b, gid, gtt[i0][i1]);
  42. gid++;
  43. }
  44. Flag.sw.stopGC();
  45. return res;
  46. }
  47. @Override
  48. public void setEvaluate() {
  49. // TODO Auto-generated method stub
  50. }
  51. }