1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // Copyright (C) 2014 by Xiao Shaun Wang <wangxiao@cs.umd.edu>
- package com.oblivm.backend.flexsc;
- import com.oblivm.backend.network.Network;
- import com.oblivm.backend.util.Utils;
- public class CVCompEnv extends BooleanCompEnv {
- public CVCompEnv(Network channel, Party p) {
- super(channel, p, Mode.VERIFY);
- this.party = p;
- }
- @Override
- public Boolean inputOfAlice(boolean in) {
- Boolean res = null;
- res = in;
- if (party == Party.Alice)
- channel.writeInt(in ? 1 : 0);
- else {
- int re = channel.readInt();
- res = re == 1;
- }
- channel.flush();
- return res;
- }
- @Override
- public Boolean inputOfBob(boolean in) {
- Boolean res = null;
- channel.flush();
- res = in;
- if (party == Party.Bob)
- channel.writeInt(in ? 1 : 0);
- else {
- int re = channel.readInt();
- res = re == 1;
- }
- channel.flush();
- return res;
- }
- @Override
- public boolean outputToAlice(Boolean out) {
- return out;
- }
- public boolean outputToBob(Boolean out) {
- return out;
- }
- @Override
- public Boolean and(Boolean a, Boolean b) {
- ++Flag.sw.ands;
- ++numOfAnds;
- return a && b;
- }
- @Override
- public Boolean xor(Boolean a, Boolean b) {
- return a ^ b;
- }
- @Override
- public Boolean not(Boolean a) {
- return !a;
- }
- public Boolean[] inputOfAlice(boolean[] in) {
- Boolean[] res = new Boolean[in.length];
- for (int i = 0; i < res.length; ++i)
- res[i] = inputOfAlice(in[i]);
- return res;
- }
- @Override
- public Boolean[] inputOfBob(boolean[] in) {
- Boolean[] res = new Boolean[in.length];
- for (int i = 0; i < res.length; ++i)
- res[i] = inputOfBob(in[i]);
- return res;
- }
- @Override
- public boolean[] outputToAlice(Boolean[] out) {
- return Utils.tobooleanArray(out);
- }
- @Override
- public boolean[] outputToBob(Boolean[] out) {
- return Utils.tobooleanArray(out);
- }
- @Override
- public void setEvaluate() {
- // TODO Auto-generated method stub
- }
- }
|