SFE.BOAL
Class Gate

java.lang.Object
  extended by SFE.BOAL.Gate
All Implemented Interfaces:
java.io.Serializable

public class Gate
extends java.lang.Object
implements java.io.Serializable

This class holds information on a single gate

Author:
: Dahlia Malkhi and Yaron Sella
See Also:
Serialized Form

Field Summary
 int gate_index
           
static int INP_GATE
           
static int NBYTESG
           
static int REG_GATE
           
 
Constructor Summary
Gate(int g_idx, int n_ins, int type, boolean out_gate)
          Constructor for class Gate
 
Method Summary
 void evalGarbledGate(boolean alice_interpret, boolean bob_interpret)
          Evaluate this garbled gate and place result in member garbled_value.
 void evalGate()
          Evaluate this gate and place result in member 'value'.
 void generateEncGate()
          Fill in all encrypted values and perms of a gate
 byte[] generateEncOutput(int index, byte[] enc_key)
          Return an encrypted value corresponding to this gate for a given index into this gate's truth table.
 byte generateEncPerm(int index, byte enc_key)
          Return an encrypted permutation corresponding to this gate for a given index into this gate's truth table.
 byte[] genKey(int index, int permuted_index)
          Return an enc/dec mask corresponding to this gate for a given index into this gate's truth table If index is negative then the enc/dec mask is calculated based on this gate's evaluated garbled inputs.
 int genPermIndex(int index)
          Return a premutated index corresponding to this gate for a given index into this gate's truth table.
 byte[] getCode(int bit)
          Provide a garbeling code for the designated binary value.
 byte[] getGarbledValue()
          Return garbled value of this gate (after it was evaluated)
 byte[] getPackedCode(int bit)
          Provide a garbeling code for the designated binary value of code0/code1 concatenated with garbled perm (for the purpose of transferring both in a single OT)
 int getValue()
          Return the value of this gate (after it was evaluated)
 byte[] gextractEncPayload()
          Extract encrypted payload from an encrypted gate.
 byte[] gextractInpPayload()
          Extract input payload from an encrypted gate.
 byte[] gextractOutPayload()
          Extract output payload from an encrypted gate.
 byte[] gextractSecPayload()
          Extract secret payload from an encrypted gate.
 int ginjectEncPayload(byte[] info, int start)
          Inject encrypted payload into a gate.
 int ginjectInpPayload(byte[] info, int start)
          Inject input payload into a gate.
 int ginjectOutPayload(byte[] info, int start)
          Inject output payload into a gate.
 int ginjectSecPayload(byte[] info, int start)
          Inject secret payload into a gate.
 int gmeasureEncPayload()
          Measure size of encrypted payload in an encrypted gate
 int gmeasureInpPayload()
          Measure size of input payload in an encrypted gate
 int gmeasureOutPayload()
          Measure size of output payload in an encrypted gate
 int gmeasureSecPayload()
          Measure size of secret payload in an encrypted gate
 int interpretCode()
          Interpret a garbled code back to a bit (only for output gates) Note - different treatment for Alice and Bob outputs: evaluation for Alice output against a hash of the garbled value, evaluation for Bob output against the garbled value itself.
 boolean isAliceInput()
           
 boolean isAliceOutput()
           
 boolean isBobInput()
           
 boolean isBobOutput()
           
 boolean isCorrect()
           
 boolean isInput()
           
 boolean isOutput()
           
 void markAliceBob(boolean alice)
          Mark an input gate as being Alice's or Bob's
 void printGate()
          Print a gate (for debugging only).
 void setGarbledValue(byte[] gdataCode)
          Set the garbled value of this gate and interpret it (in practice - only for Bob output gates).
 void setInput(int ind, Gate in_gate)
          Record the specified input gate number at the designated input index.
 void setOutput(boolean out_gate)
           
 void setOutput(int ind, boolean val)
          Record the specified output value at the designated input index.
 void setPackedCode(byte[] packed_code)
          Force the specified value as output value of this gate.
 void setValue(int bit)
          Force the specified value as output value of this gate.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REG_GATE

public static final int REG_GATE
See Also:
Constant Field Values

INP_GATE

public static final int INP_GATE
See Also:
Constant Field Values

NBYTESG

public static final int NBYTESG
See Also:
Constant Field Values

gate_index

public int gate_index
Constructor Detail

Gate

public Gate(int g_idx,
            int n_ins,
            int type,
            boolean out_gate)
Constructor for class Gate

Parameters:
g_idx - index of gate within the circuit.
n_ins - number of input wires for this gate.
type - the type of this gate (e.g., input/regular).
out_gate - true if this gate goes to output.
Method Detail

setInput

public void setInput(int ind,
                     Gate in_gate)
Record the specified input gate number at the designated input index.

Parameters:
ind - Index of input wire
in_gate - Gate from which input is taken

setOutput

public void setOutput(int ind,
                      boolean val)
Record the specified output value at the designated input index.

Parameters:
ind - Index of input
val - binary output value

setValue

public void setValue(int bit)
Force the specified value as output value of this gate. It is used for setting the value of input gates.

Parameters:
bit - The output value to set.

markAliceBob

public void markAliceBob(boolean alice)
Mark an input gate as being Alice's or Bob's

Parameters:
alice - true if it's Alice's input

setPackedCode

public void setPackedCode(byte[] packed_code)
Force the specified value as output value of this gate. It is used for setting the value of input gates.

Parameters:
packed_code - The code value to set.

isInput

public boolean isInput()
Returns:
Is it an input gate?

isAliceInput

public boolean isAliceInput()
Returns:
Is it an input gate of Alice?

isBobInput

public boolean isBobInput()
Returns:
Is it an input gate of Bob?

isOutput

public boolean isOutput()
Returns:
Is it an output gate?

setOutput

public void setOutput(boolean out_gate)

isAliceOutput

public boolean isAliceOutput()
Returns:
Is it an output gate of Alice?

isBobOutput

public boolean isBobOutput()
Returns:
Is it an output gate of Bob?

isCorrect

public boolean isCorrect()
Returns:
Is this gate correct?

getPackedCode

public byte[] getPackedCode(int bit)
Provide a garbeling code for the designated binary value of code0/code1 concatenated with garbled perm (for the purpose of transferring both in a single OT)

Parameters:
bit - the desginated binary value (integer) to be garbled.
Returns:
a byte array containing the garbling code for the designated binary value concatenated with garbled perm

getCode

public byte[] getCode(int bit)
Provide a garbeling code for the designated binary value.

Parameters:
bit - the desginated binary value (integer) to be garbled.
Returns:
a byte array containing the garbling code for the designated binary value.

getValue

public int getValue()
Return the value of this gate (after it was evaluated)

Returns:
a 0/1 value which is the output of this gate.

getGarbledValue

public byte[] getGarbledValue()
Return garbled value of this gate (after it was evaluated)

Returns:
a garbeled value which is the garbeled output of this gate.

setGarbledValue

public void setGarbledValue(byte[] gdataCode)
Set the garbled value of this gate and interpret it (in practice - only for Bob output gates).

Parameters:
gdataCode - byte array containing garbeled value to set.

genPermIndex

public int genPermIndex(int index)
Return a premutated index corresponding to this gate for a given index into this gate's truth table. The calculation is based on the permutations of all the gates that contribute input to this gate.

Parameters:
index - - An index into the gate's truth table
Returns:
permuted index

genKey

public byte[] genKey(int index,
                     int permuted_index)
Return an enc/dec mask corresponding to this gate for a given index into this gate's truth table If index is negative then the enc/dec mask is calculated based on this gate's evaluated garbled inputs.

Parameters:
index - - An index into the truth table of the gate
permuted_index - - Like index, but permuted
Returns:
byte array of encryption key

generateEncPerm

public byte generateEncPerm(int index,
                            byte enc_key)
Return an encrypted permutation corresponding to this gate for a given index into this gate's truth table.

Parameters:
index - - An index into the gate's truth table
enc_key - - An encryption key (one time pad).
Returns:
encrypted perm

generateEncOutput

public byte[] generateEncOutput(int index,
                                byte[] enc_key)
Return an encrypted value corresponding to this gate for a given index into this gate's truth table.

Parameters:
index - - An index into the gate's truth table
enc_key - - encryption key for this entry
Returns:
byte array of encrypted value

generateEncGate

public void generateEncGate()
Fill in all encrypted values and perms of a gate


gmeasureEncPayload

public int gmeasureEncPayload()
Measure size of encrypted payload in an encrypted gate

Returns:
int - gate's encrypted payload size in bytes

gextractEncPayload

public byte[] gextractEncPayload()
Extract encrypted payload from an encrypted gate.

Returns:
a byte array with the relevant information.

ginjectEncPayload

public int ginjectEncPayload(byte[] info,
                             int start)
Inject encrypted payload into a gate.

Returns:
an integer specifying how many bytes this gate consumed

gmeasureSecPayload

public int gmeasureSecPayload()
Measure size of secret payload in an encrypted gate

Returns:
int - gate's secret payload size in bytes

gextractSecPayload

public byte[] gextractSecPayload()
Extract secret payload from an encrypted gate.

Returns:
a byte array with the relevant information.

ginjectSecPayload

public int ginjectSecPayload(byte[] info,
                             int start)
Inject secret payload into a gate.

Returns:
an integer specifying how many bytes this gate consumed

gmeasureInpPayload

public int gmeasureInpPayload()
Measure size of input payload in an encrypted gate

Returns:
int - gate's input payload size in bytes

gextractInpPayload

public byte[] gextractInpPayload()
Extract input payload from an encrypted gate.

Returns:
a byte array with the relevant information.

ginjectInpPayload

public int ginjectInpPayload(byte[] info,
                             int start)
Inject input payload into a gate.

Returns:
an integer specifying how many bytes this gate consumed

gmeasureOutPayload

public int gmeasureOutPayload()
Measure size of output payload in an encrypted gate

Returns:
int - gate's input payload size in bytes

gextractOutPayload

public byte[] gextractOutPayload()
Extract output payload from an encrypted gate.

Returns:
a byte array with the relevant information.

ginjectOutPayload

public int ginjectOutPayload(byte[] info,
                             int start)
Inject output payload into a gate.

Returns:
an integer specifying how many bytes this gate consumed

evalGate

public void evalGate()
Evaluate this gate and place result in member 'value'.


evalGarbledGate

public void evalGarbledGate(boolean alice_interpret,
                            boolean bob_interpret)
Evaluate this garbled gate and place result in member garbled_value.

Parameters:
alice_interpret - - interpret Alice garbled output
bob_interpret - - interpret Bob garbled output

printGate

public void printGate()
Print a gate (for debugging only).


interpretCode

public int interpretCode()
Interpret a garbled code back to a bit (only for output gates) Note - different treatment for Alice and Bob outputs: evaluation for Alice output against a hash of the garbled value, evaluation for Bob output against the garbled value itself.

Returns:
a bit (0/1)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object