PMCompEnv.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright (C) 2014 by Xiao Shaun Wang <wangxiao@cs.umd.edu>
  2. package com.oblivm.backend.flexsc;
  3. import com.oblivm.backend.network.Network;
  4. import com.oblivm.backend.util.Utils;
  5. /*
  6. * The computational environment for performance measurement.
  7. */
  8. public class PMCompEnv extends BooleanCompEnv {
  9. public static class Statistics {
  10. public long andGate = 0;
  11. public long xorGate = 0;
  12. public long notGate = 0;
  13. public long OTs = 0;
  14. public long NumEncAlice = 0;
  15. public long NumEncBob = 0;
  16. public long bandwidth = 0;
  17. public void flush() {
  18. bandwidth = 0;
  19. andGate = 0;
  20. xorGate = 0;
  21. notGate = 0;
  22. OTs = 0;
  23. NumEncAlice = 0;
  24. NumEncBob = 0;
  25. }
  26. public void add(Statistics s2) {
  27. andGate += s2.andGate;
  28. xorGate += s2.xorGate;
  29. notGate += s2.notGate;
  30. OTs += s2.OTs;
  31. NumEncAlice += s2.NumEncAlice;
  32. NumEncBob += s2.NumEncBob;
  33. bandwidth += s2.bandwidth;
  34. }
  35. public void finalize() {
  36. NumEncAlice = andGate * 4 + OTs * 2;
  37. NumEncBob = andGate * 1 + OTs * 1;
  38. }
  39. public Statistics newInstance() {
  40. Statistics s = new Statistics();
  41. s.andGate = andGate;
  42. s.xorGate = xorGate;
  43. s.notGate = notGate;
  44. s.OTs = OTs;
  45. s.NumEncAlice = NumEncAlice;
  46. s.NumEncBob = NumEncBob;
  47. s.bandwidth = bandwidth;
  48. return s;
  49. }
  50. }
  51. public Statistics statistic;
  52. public PMCompEnv(Network channel, Party p) {
  53. super(channel, p, Mode.COUNT);
  54. this.party = p;
  55. t = true;
  56. f = false;
  57. statistic = new Statistics();
  58. }
  59. @Override
  60. public Boolean inputOfAlice(boolean in) {
  61. return f;
  62. }
  63. @Override
  64. public Boolean inputOfBob(boolean in) {
  65. ++statistic.OTs;
  66. statistic.bandwidth += 10;
  67. return f;
  68. }
  69. @Override
  70. public boolean outputToAlice(Boolean out) {
  71. statistic.bandwidth += 10;
  72. return false;
  73. }
  74. @Override
  75. public boolean outputToBob(Boolean out) {
  76. statistic.bandwidth += 10;
  77. return false;
  78. }
  79. @Override
  80. public Boolean and(Boolean a, Boolean b) {
  81. ++statistic.andGate;
  82. ++this.numOfAnds;
  83. statistic.bandwidth += 3 * 10;
  84. return f;
  85. }
  86. @Override
  87. public Boolean xor(Boolean a, Boolean b) {
  88. ++statistic.xorGate;
  89. return f;
  90. }
  91. @Override
  92. public Boolean not(Boolean a) {
  93. ++statistic.notGate;
  94. return f;
  95. }
  96. @Override
  97. public boolean[] outputToAlice(Boolean[] out) {
  98. statistic.bandwidth += 10 * out.length;
  99. return Utils.tobooleanArray(out);
  100. }
  101. @Override
  102. public boolean[] outputToBob(Boolean[] out) {
  103. statistic.bandwidth += 10 * out.length;
  104. return Utils.tobooleanArray(out);
  105. }
  106. @Override
  107. public Boolean[] inputOfAlice(boolean[] in) {
  108. statistic.bandwidth += 10 * in.length;
  109. return Utils.toBooleanArray(in);
  110. }
  111. @Override
  112. public Boolean[] inputOfBob(boolean[] in) {
  113. statistic.OTs += in.length;
  114. statistic.bandwidth += 10 * 2 * (80 + in.length);
  115. return Utils.toBooleanArray(in);
  116. }
  117. @Override
  118. public void setEvaluate() {
  119. // TODO Auto-generated method stub
  120. }
  121. }