GCEva.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.oblivm.backend.gc.halfANDs;
  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. public GCEva(Network channel) {
  10. super(channel, Mode.OPT);
  11. gb = new Garbler();
  12. }
  13. public GCSignal and(GCSignal a, GCSignal b) {
  14. Flag.sw.startGC();
  15. GCSignal res;
  16. if (a.isPublic() && b.isPublic())
  17. res = ((a.v && b.v) ? new GCSignal(true) : new GCSignal(false));
  18. else if (a.isPublic())
  19. res = a.v ? b : new GCSignal(false);
  20. else if (b.isPublic())
  21. res = b.v ? a : new GCSignal(false);
  22. else {
  23. ++numOfAnds;
  24. int i0 = a.getLSB();
  25. int i1 = b.getLSB();
  26. GCSignal TG = GCSignal.ZERO, WG, TE = GCSignal.ZERO, WE;
  27. try {
  28. Flag.sw.startGCIO();
  29. TG = GCSignal.receive(channel);
  30. TE = GCSignal.receive(channel);
  31. Flag.sw.stopGCIO();
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. System.exit(1);
  35. }
  36. WG = gb.hash(a, gid, false).xor((i0 == 1) ? TG : GCSignal.ZERO);
  37. WE = gb.hash(b, gid, true).xor((i1 == 1) ? (TE.xor(a)) : GCSignal.ZERO);
  38. res = WG.xor(WE);
  39. gid++;
  40. }
  41. Flag.sw.stopGC();
  42. return res;
  43. }
  44. @Override
  45. public void setEvaluate() {
  46. // TODO Auto-generated method stub
  47. }
  48. }