diff -ru --exclude='*/PF/*' Fairplay/source/SFE/BOAL/Alice.java FairplayPF/source/SFE/BOAL/Alice.java --- Fairplay/source/SFE/BOAL/Alice.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/BOAL/Alice.java 2008-01-31 12:39:27.000000000 -0600 @@ -1,26 +1,15 @@ -// Alice.java - Alice's part of the 2-party SFE protocol. -// Copyright (C) 2004 Dahlia Malkhi, Yaron Sella. -// See full Copyright license terms in file ../GPL.txt +//Alice.java - Alice's part of the 2-party SFE protocol. +//Copyright (C) 2004 Dahlia Malkhi, Yaron Sella. +//See full Copyright license terms in file ../GPL.txt package SFE.BOAL; -import org.apache.log4j.*; - +import SFE.Compiler.*; +import SFE.GUI.*; import java.io.*; - -import java.math.*; - import java.net.*; - import java.util.*; - -import java.util.regex.*; - -import SFE.BOAL.*; - -import SFE.Compiler.*; - -import SFE.GUI.*; +import org.apache.log4j.*; /** Alice * @author: Dahlia Malkhi and Yaron Sella @@ -29,332 +18,333 @@ //--------------------------------------------------------------- /** - * This class implements Alice - the chooser in the two-party - * SFE protocol. - * - * @author Dahlia Malkhi and Yaron Sella. + * Alice + * @author : Dahlia Malkhi and Yaron Sella */ public class Alice { - private static final Logger logger = Logger.getLogger(Alice.class); - private static final int num_of_circuits = 2; - Formatter f = null; - - //--------------------------------------------------------------- - - /** - * Alice Constructor - * - * @param circuit_filename - circuit filename - * @param fmt_filename - format filename - * @param hostname - where to find Bob - * @param num_iterations - how many iterations to do - * @param stats - print run statistics in the end - */ - public Alice(String circuit_filename, String fmt_filename, String sseed, - String hostname, int num_iterations, boolean stats) throws Exception { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int i, j; - int ot_type; - int cc_num; - int[] bob_io_size = new int[2]; - Parser p = null; - OT ot; - Socket sock = null; - ObjectInputStream fromBob = null; - ObjectOutputStream toBob = null; - Vector bob_results; - long sum1=0, sum2=0, sum3=0, sum4=0; - - // Preparations - MyUtil.init(sseed); - - // Connect to Bob - try { - sock = new Socket(hostname, 3496); - fromBob = new ObjectInputStream(sock.getInputStream()); - toBob = new ObjectOutputStream(sock.getOutputStream()); - } catch (UnknownHostException e) { - System.err.println("Alice: Don't know host " + hostname); - System.exit(-1); - } catch (IOException e) { - System.err.println( - "Alice: Couldn't get I/O for the connection with Bob"); - System.exit(-1); - } - - MyUtil.sendInt(toBob, (num_iterations << 8) + num_of_circuits, true); - ot_type = MyUtil.receiveInt(fromBob); - ot = new OT(ot_type); - - Vector vEncPayload = new Vector (num_of_circuits); - byte[] EncPayload; - byte[] SecPayload; - byte[] InpPayload; - byte[] OutPayload; - int EncPayloadSize=0; - int SecPayloadSize=0; - int InpPayloadSize; - int OutPayloadSize; - Circuit c; - - for (i = 0; i < num_iterations; i++) { - - MyUtil.deltaTime (true); - - logger.info("Iteration no = " + i); - - // Parse the IOformat file and prepare the inputs - try { - // Preparations - FileReader fmt = new FileReader(fmt_filename); - StreamTokenizer fmtst = new StreamTokenizer(fmt); - - // IO Formatting - f = new Formatter(fmtst); - f.parse(); - - // Cleanup - fmt.close(); - } catch (IOException e) { - logger.error("Alice: cannot open/close " + fmt_filename + " - " + - e.getMessage()); - } catch (FormatterError e) { - logger.error("Alice: parsing " + fmt_filename + " failed."); - } catch (Exception e) { - logger.error("Alice: exception - " + e.getMessage()); - } - - // Parse the circuit file - try { - // Preparations - FileReader fr = new FileReader(circuit_filename); - StreamTokenizer st = new StreamTokenizer(fr); - - // Parsing - p = new Parser(st); - p.parse(); - - // Cleanup - fr.close(); - } catch (IOException e) { - logger.error("Alice: cannot open/close " + circuit_filename + - " - " + e.getMessage()); - System.exit(1); - } catch (Exception e) { - logger.error("Alice: exception - " + e.getMessage()); - System.exit(1); - } - - c = p.getCircuit(); // Obtain a circuit object - f.markIO (c, bob_io_size); // Mark its inputs & outputs - InpPayloadSize = bob_io_size[0]; - OutPayloadSize = bob_io_size[1]; - c.generateEncCircuit(); // Encrypt it (dummy) - EncPayloadSize = c.cmeasureEncPayload(); - SecPayloadSize = c.cmeasureSecPayload(); - - sum1 += MyUtil.deltaTime (false); - - // Run the SFE protocol - // ==================== - - // Receive encrypted circuits payload from Bob - for (j = 0; j < num_of_circuits ; j++) { - EncPayload = new byte[EncPayloadSize]; - MyUtil.receiveBytes (fromBob, EncPayload, EncPayloadSize); - vEncPayload.add (EncPayload); - } - - // Choose a circuit to evaluate and tell Bob - cc_num = MyUtil.randomByte() ; - if (cc_num < 0) cc_num += 256 ; - cc_num = cc_num % num_of_circuits; - logger.debug("Alice: chose circuit number " + cc_num + " for evaluation"); - MyUtil.sendInt(toBob, cc_num, true); - - // Receive encrypted circuits with secrets - // (except the chosen one) from Bob - for (j = 0; j < num_of_circuits ; j++) { - if (j != cc_num) { - EncPayload = (byte[]) vEncPayload.elementAt(j); - c.cinjectEncPayload (EncPayload); - SecPayload = new byte[SecPayloadSize]; - MyUtil.receiveBytes (fromBob, SecPayload, SecPayloadSize); - c.cinjectSecPayload (SecPayload); - if (!c.isCorrect()) { - logger.error("Alice: caught Bob cheating!"); - System.exit(1); - } - } - } - - // Receive Bob's inputs for the chosen circuit and place them in it - InpPayload = new byte[InpPayloadSize]; - MyUtil.receiveBytes (fromBob, InpPayload, InpPayloadSize); - f.finjectInpPayload (c, InpPayload, false); - - sum2 += MyUtil.deltaTime (false); - - // Read Alice's inputs - f.getAliceInput(c, br); - - // OTs - Alice is the chooser + - // place Alice's inputs in the chosen circuit - OT.ChooserOTs(c, f, ot, toBob, fromBob); - - sum3 += MyUtil.deltaTime (false); - - c.evalGarbledCircuit(true, false); - logger.info("circuit evaluation completed!"); - - // Send Bob his garbled results - OutPayload = f.fextractOutPayload (c, OutPayloadSize, false); - MyUtil.sendBytes (toBob, OutPayload, true); - - // print Alice's output - f.getAliceOutput(c); - - sum4 += MyUtil.deltaTime (false); - } - - if (stats) { - System.out.println("Initial calculations [sum1] = " + (float)sum1/1000.0); - System.out.println("Circuits communication [sum2] = " + (float)sum2/1000.0); - System.out.println("Oblivious Transfers [sum3] = " + (float)sum3/1000.0); - System.out.println("Evaluation & output [sum4] = " + (float)sum4/1000.0); + private static final Logger logger = Logger.getLogger(Alice.class); + private static final int num_of_circuits = 10; + Formatter f = null; + + //--------------------------------------------------------------- + + /** + * Alice Constructor + * + * @param circuit_filename - circuit filename + * @param fmt_filename - format filename + * @param hostname - where to find Bob + * @param num_iterations - how many iterations to do + * @param stats - print run statistics in the end + */ + public Alice(String circuit_filename, String fmt_filename, String sseed, + String hostname, int num_iterations, boolean stats) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int i, j; + int ot_type; + int cc_num; + int[] bob_io_size = new int[2]; + Parser p = null; + OT ot; + Socket sock = null; + ObjectInputStream fromBob = null; + ObjectOutputStream toBob = null; + Vector bob_results; + long sum1=0, sum2=0, sum3=0, sum4=0; + + // Preparations + MyUtil.init(sseed); + + // Connect to Bob + try { + sock = new Socket(hostname, 3496); + fromBob = new ObjectInputStream(sock.getInputStream()); + toBob = new ObjectOutputStream(sock.getOutputStream()); + } catch (UnknownHostException e) { + System.err.println("Alice: Don't know host " + hostname); + System.exit(-1); + } catch (IOException e) { + System.err.println( + "Alice: Couldn't get I/O for the connection with Bob"); + System.exit(-1); + } + + MyUtil.sendInt(toBob, (num_iterations << 8) + num_of_circuits, true); + ot_type = MyUtil.receiveInt(fromBob); + ot = new OT(ot_type); + + Vector vEncPayload = new Vector (num_of_circuits); + byte[] EncPayload; + byte[] SecPayload; + byte[] InpPayload; + byte[] OutPayload; + int EncPayloadSize=0; + int SecPayloadSize=0; + int InpPayloadSize; + int OutPayloadSize; + Circuit c; + + for (i = 0; i < num_iterations; i++) { + + MyUtil.deltaTime (true); + + logger.info("Iteration no = " + i); + + // Parse the IOformat file and prepare the inputs + try { + // Preparations + FileReader fmt = new FileReader(fmt_filename); + StreamTokenizer fmtst = new StreamTokenizer(fmt); + + // IO Formatting + f = new Formatter(fmtst); + f.parse(); + + // Cleanup + fmt.close(); + } catch (IOException e) { + logger.error("Alice: cannot open/close " + fmt_filename + " - " + + e.getMessage()); + } catch (FormatterError e) { + logger.error("Alice: parsing " + fmt_filename + " failed."); + } catch (Exception e) { + logger.error("Alice: exception - " + e.getMessage()); + } + + // Parse the circuit file + try { + // Preparations + FileReader fr = new FileReader(circuit_filename); + StreamTokenizer st = new StreamTokenizer(fr); + + // Parsing + p = new Parser(st); + p.parse(); + + // Cleanup + fr.close(); + } catch (IOException e) { + logger.error("Alice: cannot open/close " + circuit_filename + + " - " + e.getMessage()); + System.exit(1); + } catch (Exception e) { + logger.error("Alice: exception - " + e.getMessage()); + System.exit(1); + } + + c = p.getCircuit(); // Obtain a circuit object + f.markIO (c, bob_io_size); // Mark its inputs & outputs + InpPayloadSize = bob_io_size[0]; + OutPayloadSize = bob_io_size[1]; + c.generateEncCircuit(); // Encrypt it (dummy) + EncPayloadSize = c.cmeasureEncPayload(); + SecPayloadSize = c.cmeasureSecPayload(); + + sum1 += MyUtil.deltaTime (false); + + // Run the SFE protocol + // ==================== + + // Receive encrypted circuits payload from Bob + for (j = 0; j < num_of_circuits ; j++) { + EncPayload = new byte[EncPayloadSize]; + MyUtil.receiveBytes (fromBob, EncPayload, EncPayloadSize); + vEncPayload.add (EncPayload); + } + + // Choose a circuit to evaluate and tell Bob + cc_num = MyUtil.randomByte() ; + if (cc_num < 0) cc_num += 256 ; + cc_num = cc_num % num_of_circuits; + logger.debug("Alice: chose circuit number " + cc_num + " for evaluation"); + MyUtil.sendInt(toBob, cc_num, true); + + // Receive encrypted circuits with secrets + // (except the chosen one) from Bob + for (j = 0; j < num_of_circuits ; j++) { + if (j != cc_num) { + EncPayload = (byte[]) vEncPayload.elementAt(j); + c.cinjectEncPayload (EncPayload); + SecPayload = new byte[SecPayloadSize]; + MyUtil.receiveBytes (fromBob, SecPayload, SecPayloadSize); + c.cinjectSecPayload (SecPayload); + if (!c.isCorrect()) { + logger.error("Alice: caught Bob cheating!"); + System.exit(1); + } + } + } + + // UPDATED by Thomas Schneider + c.cinjectEncPayload((byte[]) vEncPayload.elementAt(cc_num)); + + // Receive Bob's inputs for the chosen circuit and place them in it + InpPayload = new byte[InpPayloadSize]; + MyUtil.receiveBytes (fromBob, InpPayload, InpPayloadSize); + f.finjectInpPayload (c, InpPayload, false); + + sum2 += MyUtil.deltaTime (false); + + // Read Alice's inputs + f.getAliceInput(c, br); + + // OTs - Alice is the chooser + + // place Alice's inputs in the chosen circuit + OT.ChooserOTs(c, f, ot, toBob, fromBob); + + sum3 += MyUtil.deltaTime (false); + + c.evalGarbledCircuit(true, false); + logger.info("circuit evaluation completed!"); + + // Send Bob his garbled results + OutPayload = f.fextractOutPayload (c, OutPayloadSize, false); + MyUtil.sendBytes (toBob, OutPayload, true); + + // print Alice's output + f.getAliceOutput(c); + + sum4 += MyUtil.deltaTime (false); + } + + if (stats) { + System.out.println("Initial calculations [sum1] = " + (float)sum1/1000.0); + System.out.println("Circuits communication [sum2] = " + (float)sum2/1000.0); + System.out.println("Oblivious Transfers [sum3] = " + (float)sum3/1000.0); + System.out.println("Evaluation & output [sum4] = " + (float)sum4/1000.0); + } + + // Cleanup + toBob.close(); + fromBob.close(); + sock.close(); } - // Cleanup - toBob.close(); - fromBob.close(); - sock.close(); - } - - //--------------------------------------------------------------- - - /** - * This routine is for debugging socket communication - */ - public void pongping(ObjectOutputStream toBob, ObjectInputStream fromBob, - int a) { - System.out.println("Sending " + a + " to Bob"); - MyUtil.sendInt(toBob, a, true); - System.out.println("Attempting to read num from Bob"); - - int u = MyUtil.receiveInt(fromBob); - System.out.println("Got Int from Bob " + u); - } - - //--------------------------------------------------------------- - - public static void aliceUsage(int err_code) { - System.out.println("Alice activation error code = " + err_code); - System.out.println("Usage: java SFE.BOAL.Alice -e|-c[n]|-r[n] "); - System.out.println(" -e = EDIT, -c = COMPILE, -r = RUN, [n] = NoOpt)"); - System.out.println(" ( , expected only with -r[n])"); - System.out.println(" Examples: 1. java SFE.Alice -c Maximum.txt"); - System.out.println(" 2. java SFE.Alice -r Maximum.txt Xb@&5H1m!p sands 100"); - System.exit(1); - } - - //--------------------------------------------------------------- - - /** - * Main program for activating Alice - * - * @param args - command line arguments. - * args[0] should be -e, -c[n] or -r[n] - * args[1] should be filename - * args[2] should be seed for RNG - * args[3] should be hostname (only with -r[n]) - * args[4] should be number of iterations (only with -r[n]) - */ - public static void main(String[] args) throws Exception { - String filename; - String circ_fname; - String fmt_fname; - int num_iterations; - boolean edit = false; - boolean compile = false; - boolean run_stats = false; - boolean run = false; - boolean opt = false; - - - // Load logging configuration file - PropertyConfigurator.configure(MyUtil.pathFile("SFE_logcfg.lcf")); - - // Various legality tests on command line parameters - - if ((args.length < 2) || (args.length > 5)) - aliceUsage(1); - - edit = args[0].equals("-e"); - compile = args[0].equals("-c") || args[0].equals("-cn"); - run_stats = args[0].equals("-s") ; - run = run_stats || args[0].equals("-r") || args[0].equals("-rn"); - opt = args[0].equals("-r") || args[0].equals("-c") || args[0].equals("-s"); - - if (!edit && !compile && !run && !run_stats) - aliceUsage(2); - - if (run && (args.length < 4)) - aliceUsage(3); - - filename = new String(args[1]); - if (opt) { - circ_fname = new String(filename + ".Opt.circuit"); - fmt_fname = new String(filename + ".Opt.fmt"); - } - else { - circ_fname = new String(filename + ".NoOpt.circuit"); - fmt_fname = new String(filename + ".NoOpt.fmt"); + //--------------------------------------------------------------- + + /** + * This routine is for debugging socket communication + */ + public void pongping(ObjectOutputStream toBob, ObjectInputStream fromBob, + int a) { + System.out.println("Sending " + a + " to Bob"); + MyUtil.sendInt(toBob, a, true); + System.out.println("Attempting to read num from Bob"); + + int u = MyUtil.receiveInt(fromBob); + System.out.println("Got Int from Bob " + u); } - if (compile) { - File f = new File(filename); + //--------------------------------------------------------------- - if (!f.exists()) { - System.out.println("Input file " + filename + " not found"); - aliceUsage(4); - } + public static void aliceUsage(int err_code) { + System.out.println("Alice activation error code = " + err_code); + System.out.println("Usage: java SFE.BOAL.Alice -e|-c[n]|-r[n] "); + System.out.println(" -e = EDIT, -c = COMPILE, -r = RUN, [n] = NoOpt)"); + System.out.println(" ( , expected only with -r[n])"); + System.out.println(" Examples: 1. java SFE.Alice -c Maximum.txt"); + System.out.println(" 2. java SFE.Alice -r Maximum.txt Xb@&5H1m!p sands 100"); + System.exit(1); } - if (run) { - File f1 = new File(circ_fname); - File f2 = new File(fmt_fname); - - if (!f1.exists() || !f2.exists()) { - if (!f1.exists()) - System.out.println("Input file " + circ_fname + " not found"); - if (!f2.exists()) - System.out.println("Input file " + fmt_fname + " not found"); - aliceUsage(5); - } - } - - // Do something (finally...) - - if (edit) { - GUIMain.guiMain(filename); - } - - if (compile) { - SFECompiler.compile(filename, opt); - } - - if (run) { - System.out.println("Running Alice..."); - try { - if (args.length < 5) - num_iterations = 1 ; - else - num_iterations = Integer.parseInt(args[4]); - Alice a = new Alice(circ_fname, fmt_fname, args[2], args[3], num_iterations, run_stats); - } catch (Exception e) { - System.out.println("Alice's main err: " + e.getMessage()); - e.printStackTrace(); - } - } - } + //--------------------------------------------------------------- + + /** + * Main program for activating Alice + * + * @param args - command line arguments. + * args[0] should be -e, -c[n] or -r[n] + * args[1] should be filename + * args[2] should be seed for RNG + * args[3] should be hostname (only with -r[n]) + * args[4] should be number of iterations (only with -r[n]) + */ + public static void main(String[] args) throws Exception { + String filename; + String circ_fname; + String fmt_fname; + int num_iterations; + boolean edit = false; + boolean compile = false; + boolean run_stats = false; + boolean run = false; + boolean opt = false; + + + // Load logging configuration file + PropertyConfigurator.configure(MyUtil.pathFile("SFE_logcfg.lcf")); + + // Various legality tests on command line parameters + + if ((args.length < 2) || (args.length > 5)) + aliceUsage(1); + + edit = args[0].equals("-e"); + compile = args[0].equals("-c") || args[0].equals("-cn"); + run_stats = args[0].equals("-s") ; + run = run_stats || args[0].equals("-r") || args[0].equals("-rn"); + opt = args[0].equals("-r") || args[0].equals("-c") || args[0].equals("-s"); + + if (!edit && !compile && !run && !run_stats) + aliceUsage(2); + + if (run && (args.length < 4)) + aliceUsage(3); + + filename = new String(args[1]); + if (opt) { + circ_fname = new String(filename + ".Opt.circuit"); + fmt_fname = new String(filename + ".Opt.fmt"); + } + else { + circ_fname = new String(filename + ".NoOpt.circuit"); + fmt_fname = new String(filename + ".NoOpt.fmt"); + } + + if (compile) { + File f = new File(filename); + + if (!f.exists()) { + System.out.println("Input file " + filename + " not found"); + aliceUsage(4); + } + } + + if (run) { + File f1 = new File(circ_fname); + File f2 = new File(fmt_fname); + + if (!f1.exists() || !f2.exists()) { + if (!f1.exists()) + System.out.println("Input file " + circ_fname + " not found"); + if (!f2.exists()) + System.out.println("Input file " + fmt_fname + " not found"); + aliceUsage(5); + } + } + + // Do something (finally...) + + if (edit) { + GUIMain.guiMain(filename); + } + + if (compile) { + SFECompiler.compile(filename, opt); + } + + if (run) { + System.out.println("Running Alice..."); + try { + if (args.length < 5) + num_iterations = 1 ; + else + num_iterations = Integer.parseInt(args[4]); + Alice a = new Alice(circ_fname, fmt_fname, args[2], args[3], num_iterations, run_stats); + } catch (Exception e) { + System.out.println("Alice's main err: " + e.getMessage()); + e.printStackTrace(); + } + } + } } diff -ru --exclude='*/PF/*' Fairplay/source/SFE/BOAL/Bob.java FairplayPF/source/SFE/BOAL/Bob.java --- Fairplay/source/SFE/BOAL/Bob.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/BOAL/Bob.java 2008-01-31 12:39:27.000000000 -0600 @@ -1,26 +1,15 @@ -// Bob.java - Bob's part of the 2-party SFE protocol. -// Copyright (C) 2004 Dahlia Malkhi, Yaron Sella. -// See full copyright license terms in file ../GPL.txt +//Bob.java - Bob's part of the 2-party SFE protocol. +//Copyright (C) 2004 Dahlia Malkhi, Yaron Sella. +//See full copyright license terms in file ../GPL.txt package SFE.BOAL; -import org.apache.log4j.*; - +import SFE.Compiler.*; +import SFE.GUI.*; import java.io.*; - -import java.math.*; - import java.net.*; - import java.util.*; - -import java.util.regex.*; - -import SFE.BOAL.*; - -import SFE.Compiler.*; - -import SFE.GUI.*; +import org.apache.log4j.*; /** Bob * @author: Dahlia Malkhi and Yaron Sella @@ -29,303 +18,303 @@ //--------------------------------------------------------------- /** - * This class implements Bob - the sender in the two-party - * SFE protocl. - * - * @author Dahlia Malkhi and Yaron Sella. + * Bob + * @author : Dahlia Malkhi and Yaron Sella */ public class Bob { - private static final Logger logger = Logger.getLogger(Bob.class); - Formatter f; + private static final Logger logger = Logger.getLogger(Bob.class); + Formatter f; + + //--------------------------------------------------------------- - //--------------------------------------------------------------- + /** + * Bob Constructor + * + * @param circuit_filename - circuit filename + * @param fmt_filename - format filename + * @param sot_type - type of OT to perform (String) + */ + public Bob(String circuit_filename, String fmt_filename, String sseed, String sot_type) + throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int i, j; + int num_of_iterations; + int num_of_circuits; + int ot_type = Integer.parseInt(sot_type); + int cc_num; + int[] bob_io_size = new int[2]; + Parser p = null; // the parser and builder of the circuit + OT ot; + ServerSocket SS = null; + Socket sock = null; + ObjectInputStream fromAlice = null; + ObjectOutputStream toAlice = null; + Vector bob_results; + + // Preparations + MyUtil.init(sseed); + + // Establish connection with Alice + try { + SS = new ServerSocket(3496); // create a server socket + logger.info("Bob: waiting for Alice to connect"); + sock = SS.accept(); // Accept Alice on this socket + toAlice = new ObjectOutputStream(sock.getOutputStream()); + fromAlice = new ObjectInputStream(sock.getInputStream()); + } catch (IOException e) { + System.out.println( + "Bob: establishing connection with Alice failed: " + + e.getMessage()); + System.exit(-1); + } + + MyUtil.sendInt(toAlice, ot_type, true); + ot = new OT(ot_type); + int aint = MyUtil.receiveInt(fromAlice); + num_of_circuits = aint & 0xff ; + num_of_iterations = aint >> 8 ; + + Vector vEncPayload = new Vector (num_of_circuits); + Vector vSecPayload = new Vector (num_of_circuits); + byte[] EncPayload; + byte[] SecPayload; + byte[] InpPayload; + byte[] OutPayload; + int EncPayloadSize=0; + int SecPayloadSize=0; + int InpPayloadSize; + int OutPayloadSize; + + Circuit c; + + for (i = 0; i < num_of_iterations; i++) { + logger.info("Iteration no = " + i); + + // Parse the IOformat file and prepare the inputs + try { + // Preparations + FileReader fmt = new FileReader(fmt_filename); + StreamTokenizer fmtst = new StreamTokenizer(fmt); + + // IO Formatting + f = new Formatter(fmtst); + f.parse(); + + // Cleanup + fmt.close(); + } catch (IOException e) { + logger.error("Bob: cannot open/close " + fmt_filename + " - " + + e.getMessage()); + } catch (FormatterError e) { + logger.error("Bob: parsing " + fmt_filename + " failed."); + } catch (Exception e) { + logger.error("Bob: exception - " + e.getMessage()); + } + + // Parse circuit file + try { + // Preparations + FileReader fr = new FileReader(circuit_filename); + StreamTokenizer st = new StreamTokenizer(fr); + + // Parsing + p = new Parser(st); + p.parse(); + + // Cleanup + fr.close(); + } catch (IOException e) { + logger.error("Bob: cannot open/close " + circuit_filename + + " - " + e.getMessage()); + System.exit(1); + } catch (Exception e) { + logger.error("Bob: exception - " + e.getMessage()); + System.exit(1); + } + + c = p.getCircuit(); // Obtain a circuit object + f.markIO (c, bob_io_size); // Mark its inputs & outputs + InpPayloadSize = bob_io_size[0]; + OutPayloadSize = bob_io_size[1]; + + // Run the SFE protocol + // ==================== + + // Repeatedly encrypt circuit, extract data from it and save + for (j = 0; j < num_of_circuits; j++) { + + c.generateEncCircuit(); // Encrypt it + + if (j == 0) { // Compute sizes only on first iteration + EncPayloadSize = c.cmeasureEncPayload(); + SecPayloadSize = c.cmeasureSecPayload(); + } + + EncPayload = c.cextractEncPayload(EncPayloadSize); + vEncPayload.add (EncPayload); + MyUtil.sendBytes(toAlice, EncPayload, false); + SecPayload = c.cextractSecPayload(SecPayloadSize); + vSecPayload.add (SecPayload); + } + toAlice.flush(); + + // Receive cc_num from Alice + cc_num = MyUtil.receiveInt(fromAlice); + + // Send encrypted circuits secrets (except the chosen one) to Alice + for (j = 0; j < num_of_circuits; j++) { + if (j != cc_num) { + SecPayload = (byte[]) vSecPayload.elementAt(j); + MyUtil.sendBytes (toAlice, SecPayload, false); + } + } + toAlice.flush(); + + // Upload the secrets of the chosen circuit + SecPayload = (byte[]) vSecPayload.elementAt(cc_num); + c.cinjectSecPayload(SecPayload); + + + + // Read Bob's inputs + update circuit accordingly + f.getBobInput(c, br); + + // Send Bob's inputs (garbled) to Alice + InpPayload = f.fextractInpPayload(c, InpPayloadSize, false); + MyUtil.sendBytes(toAlice, InpPayload, true); + + // OTs - Bob is the sender + OT.SenderOTs(c, f, ot, toAlice, fromAlice); + + // Get Bob garbled results from Alice & print them + OutPayload = new byte[OutPayloadSize]; + MyUtil.receiveBytes (fromAlice, OutPayload, OutPayloadSize); + f.finjectOutPayload (c, OutPayload, false); + f.getBobOutput(c); + } + + // Cleanup + toAlice.close(); + fromAlice.close(); + sock.close(); + SS.close(); + } + + //--------------------------------------------------------------- - /** - * Bob Constructor - * - * @param circuit_filename - circuit filename - * @param fmt_filename - format filename - * @param sot_type - type of OT to perform (String) - */ - public Bob(String circuit_filename, String fmt_filename, String sseed, String sot_type) - throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int i, j; - int num_of_iterations; - int num_of_circuits; - int ot_type = Integer.parseInt(sot_type); - int cc_num; - int[] bob_io_size = new int[2]; - Parser p = null; // the parser and builder of the circuit - OT ot; - ServerSocket SS = null; - Socket sock = null; - ObjectInputStream fromAlice = null; - ObjectOutputStream toAlice = null; - Vector bob_results; - - // Preparations - MyUtil.init(sseed); - - // Establish connection with Alice - try { - SS = new ServerSocket(3496); // create a server socket - logger.info("Bob: waiting for Alice to connect"); - sock = SS.accept(); // Accept Alice on this socket - toAlice = new ObjectOutputStream(sock.getOutputStream()); - fromAlice = new ObjectInputStream(sock.getInputStream()); - } catch (IOException e) { - System.out.println( - "Bob: establishing connection with Alice failed: " + - e.getMessage()); - System.exit(-1); - } - - MyUtil.sendInt(toAlice, ot_type, true); - ot = new OT(ot_type); - int aint = MyUtil.receiveInt(fromAlice); - num_of_circuits = aint & 0xff ; - num_of_iterations = aint >> 8 ; - - Vector vEncPayload = new Vector (num_of_circuits); - Vector vSecPayload = new Vector (num_of_circuits); - byte[] EncPayload; - byte[] SecPayload; - byte[] InpPayload; - byte[] OutPayload; - int EncPayloadSize=0; - int SecPayloadSize=0; - int InpPayloadSize; - int OutPayloadSize; - - Circuit c; - - for (i = 0; i < num_of_iterations; i++) { - logger.info("Iteration no = " + i); - - // Parse the IOformat file and prepare the inputs - try { - // Preparations - FileReader fmt = new FileReader(fmt_filename); - StreamTokenizer fmtst = new StreamTokenizer(fmt); - - // IO Formatting - f = new Formatter(fmtst); - f.parse(); - - // Cleanup - fmt.close(); - } catch (IOException e) { - logger.error("Bob: cannot open/close " + fmt_filename + " - " + - e.getMessage()); - } catch (FormatterError e) { - logger.error("Bob: parsing " + fmt_filename + " failed."); - } catch (Exception e) { - logger.error("Bob: exception - " + e.getMessage()); - } - - // Parse circuit file - try { - // Preparations - FileReader fr = new FileReader(circuit_filename); - StreamTokenizer st = new StreamTokenizer(fr); - - // Parsing - p = new Parser(st); - p.parse(); - - // Cleanup - fr.close(); - } catch (IOException e) { - logger.error("Bob: cannot open/close " + circuit_filename + - " - " + e.getMessage()); - System.exit(1); - } catch (Exception e) { - logger.error("Bob: exception - " + e.getMessage()); - System.exit(1); - } - - c = p.getCircuit(); // Obtain a circuit object - f.markIO (c, bob_io_size); // Mark its inputs & outputs - InpPayloadSize = bob_io_size[0]; - OutPayloadSize = bob_io_size[1]; - - // Run the SFE protocol - // ==================== - - // Repeatedly encrypt circuit, extract data from it and save - for (j = 0; j < num_of_circuits; j++) { - - c.generateEncCircuit(); // Encrypt it - - if (j == 0) { // Compute sizes only on first iteration - EncPayloadSize = c.cmeasureEncPayload(); - SecPayloadSize = c.cmeasureSecPayload(); - } - - EncPayload = c.cextractEncPayload(EncPayloadSize); - vEncPayload.add (EncPayload); - MyUtil.sendBytes(toAlice, EncPayload, false); - SecPayload = c.cextractSecPayload(SecPayloadSize); - vSecPayload.add (SecPayload); - } - toAlice.flush(); - - // Receive cc_num from Alice - cc_num = MyUtil.receiveInt(fromAlice); - - // Send encrypted circuits secrets (except the chosen one) to Alice - for (j = 0; j < num_of_circuits; j++) { - if (j != cc_num) { - SecPayload = (byte[]) vSecPayload.elementAt(j); - MyUtil.sendBytes (toAlice, SecPayload, false); - } - } - toAlice.flush(); - - // Upload the secrets of the chosen circuit - SecPayload = (byte[]) vSecPayload.elementAt(cc_num); - c.cinjectSecPayload(SecPayload); - - // Read Bob's inputs + update circuit accordingly - f.getBobInput(c, br); - - // Send Bob's inputs (garbled) to Alice - InpPayload = f.fextractInpPayload(c, InpPayloadSize, false); - MyUtil.sendBytes(toAlice, InpPayload, true); - - // OTs - Bob is the sender - OT.SenderOTs(c, f, ot, toAlice, fromAlice); - - // Get Bob garbled results from Alice & print them - OutPayload = new byte[OutPayloadSize]; - MyUtil.receiveBytes (fromAlice, OutPayload, OutPayloadSize); - f.finjectOutPayload (c, OutPayload, false); - f.getBobOutput(c); - } - - // Cleanup - toAlice.close(); - fromAlice.close(); - sock.close(); - SS.close(); - } - - //--------------------------------------------------------------- - - /** - * This routine is for debugging socket communication - */ - public void pingpong(ObjectOutputStream toAlice, - ObjectInputStream fromAlice, int a) { - System.out.println("Attempting to read num from Alice"); - - int u = MyUtil.receiveInt(fromAlice); - System.out.println("Got Int from Alice " + u); - System.out.println("Sending " + a + " to Alice"); - MyUtil.sendInt(toAlice, a, true); - } - - //--------------------------------------------------------------- - - public static void bobUsage(int err_code) { - System.out.println("Bob activation error code = " + err_code); - System.out.println("Usage: java SFE.BOAL.Bob -e|-c[n]|-r[n] "); - System.out.println(" -e = EDIT, -c = COMPILE, -r = RUN, [n] = NoOpt)"); - System.out.println(" (, expected only with -r[n])") ; - System.out.println(" Examples: 1. java SFE.Bob -c Maximum.txt"); - System.out.println(" 2. java SFE.Bob -r Maximum.txt bQ91:d_aV!|l 4"); - System.exit(1); - } - - //--------------------------------------------------------------- - - /** - * Main program for activating Bob - * - * @param args - command line arguments. - * args[0] should be -e, -c[n], -r[n] - * args[1] should be filename - * args[2] should be ot_type (only with -r[n]) - */ - public static void main(String[] args) throws Exception { - String filename; - String circ_fname; - String fmt_fname; - boolean edit = false; - boolean compile = false; - boolean run = false; - boolean opt = false; - - // Load logging configuration file - PropertyConfigurator.configure(MyUtil.pathFile("SFE_logcfg.lcf")); - - // Various legality tests on command line parameters - - if ((args.length < 2) || (args.length > 4)) - bobUsage(1); - - edit = args[0].equals("-e"); - compile = args[0].equals("-c") || args[0].equals("-cn"); - run = args[0].equals("-r") || args[0].equals("-rn"); - opt = args[0].equals("-r") || args[0].equals("-c"); - - if (!edit && !compile && !run) - bobUsage(2); - - if (run && (args.length < 4)) - bobUsage(3); - - filename = new String(args[1]); - if (opt) { - circ_fname = new String(filename + ".Opt.circuit"); - fmt_fname = new String(filename + ".Opt.fmt"); + /** + * This routine is for debugging socket communication + */ + public void pingpong(ObjectOutputStream toAlice, + ObjectInputStream fromAlice, int a) { + System.out.println("Attempting to read num from Alice"); + + int u = MyUtil.receiveInt(fromAlice); + System.out.println("Got Int from Alice " + u); + System.out.println("Sending " + a + " to Alice"); + MyUtil.sendInt(toAlice, a, true); } - else { - circ_fname = new String(filename + ".NoOpt.circuit"); - fmt_fname = new String(filename + ".NoOpt.fmt"); + + //--------------------------------------------------------------- + + public static void bobUsage(int err_code) { + System.out.println("Bob activation error code = " + err_code); + System.out.println("Usage: java SFE.BOAL.Bob -e|-c[n]|-r[n] "); + System.out.println(" -e = EDIT, -c = COMPILE, -r = RUN, [n] = NoOpt)"); + System.out.println(" (, expected only with -r[n])") ; + System.out.println(" Examples: 1. java SFE.Bob -c Maximum.txt"); + System.out.println(" 2. java SFE.Bob -r Maximum.txt bQ91:d_aV!|l 4"); + System.exit(1); } - if (compile) { - File f = new File(filename); + //--------------------------------------------------------------- - if (!f.exists()) { - System.out.println("Input file " + filename + " not found"); - bobUsage(4); - } - } - - if (run) { - File f1 = new File(circ_fname); - File f2 = new File(fmt_fname); - - if (!f1.exists() || !f2.exists()) { - if (!f1.exists()) - System.out.println("Input file " + circ_fname + " not found"); - if (!f2.exists()) - System.out.println("Input file " + fmt_fname + " not found"); - bobUsage(5); - } - } - - // Do something (finally...) - - if (edit) { - GUIMain.guiMain(filename); - } - - if (compile) { - SFECompiler.compile(filename, opt); - } - - if (run) { - System.out.println("Running Bob..."); - try { - Bob b = new Bob(circ_fname, fmt_fname, args[2], args[3]); - } catch (Exception e) { - System.out.println("Bob's main err: " + e.getMessage()); - e.printStackTrace(); - } - } - } + /** + * Main program for activating Bob + * + * @param args - command line arguments. + * args[0] should be -e, -c[n], -r[n] + * args[1] should be filename + * args[2] should be ot_type (only with -r[n]) + */ + public static void main(String[] args) throws Exception { + String filename; + String circ_fname; + String fmt_fname; + boolean edit = false; + boolean compile = false; + boolean run = false; + boolean opt = false; + + // Load logging configuration file + PropertyConfigurator.configure(MyUtil.pathFile("SFE_logcfg.lcf")); + + // Various legality tests on command line parameters + + if ((args.length < 2) || (args.length > 4)) + bobUsage(1); + + edit = args[0].equals("-e"); + compile = args[0].equals("-c") || args[0].equals("-cn"); + run = args[0].equals("-r") || args[0].equals("-rn"); + opt = args[0].equals("-r") || args[0].equals("-c"); + + if (!edit && !compile && !run) + bobUsage(2); + + if (run && (args.length < 4)) + bobUsage(3); + + filename = new String(args[1]); + if (opt) { + circ_fname = new String(filename + ".Opt.circuit"); + fmt_fname = new String(filename + ".Opt.fmt"); + } + else { + circ_fname = new String(filename + ".NoOpt.circuit"); + fmt_fname = new String(filename + ".NoOpt.fmt"); + } + + if (compile) { + File f = new File(filename); + + if (!f.exists()) { + System.out.println("Input file " + filename + " not found"); + bobUsage(4); + } + } + + if (run) { + File f1 = new File(circ_fname); + File f2 = new File(fmt_fname); + + if (!f1.exists() || !f2.exists()) { + if (!f1.exists()) + System.out.println("Input file " + circ_fname + " not found"); + if (!f2.exists()) + System.out.println("Input file " + fmt_fname + " not found"); + bobUsage(5); + } + } + + // Do something (finally...) + + if (edit) { + GUIMain.guiMain(filename); + } + + if (compile) { + SFECompiler.compile(filename, opt); + } + + if (run) { + System.out.println("Running Bob..."); + try { + Bob b = new Bob(circ_fname, fmt_fname, args[2], args[3]); + } catch (Exception e) { + System.out.println("Bob's main err: " + e.getMessage()); + e.printStackTrace(); + } + } + } } diff -ru --exclude='*/PF/*' Fairplay/source/SFE/BOAL/Circuit.java FairplayPF/source/SFE/BOAL/Circuit.java --- Fairplay/source/SFE/BOAL/Circuit.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/BOAL/Circuit.java 2008-01-31 12:39:27.000000000 -0600 @@ -1,6 +1,6 @@ -// Circuit.java - data structures and methods used for garbeled circuit preparation. -// Copyright (C) 2004 Dahlia Malkhi, Yaron Sella. -// See full copyright license terms in file ../GPL.txt +//Circuit.java - data structures and methods used for garbeled circuit preparation. +//Copyright (C) 2004 Dahlia Malkhi, Yaron Sella. +//See full copyright license terms in file ../GPL.txt package SFE.BOAL; @@ -8,10 +8,6 @@ import java.io.*; -import java.math.*; - -import java.security.*; - import java.util.*; @@ -61,184 +57,184 @@

This continues until we enumerate all (2^n)-1 combination of (c1 c2 .. cn) @author Dahlia Malkhi and Yaron Sella -*/ + */ //--------------------------------------------------------------- public class Circuit implements Serializable { - private static final Logger logger = Logger.getLogger(Circuit.class); - Vector circuit = new Vector(1000, 1000); - - //--------------------------------------------------------------- + private static final long serialVersionUID = -2450654631500631967L; + private static final Logger logger = Logger.getLogger(Circuit.class); + protected Vector circuit = new Vector(1000, 1000); + + //--------------------------------------------------------------- + + /** + * Add a new gate with the specified number of input wires to + * the gates vector. + * + * @param n_ins the number of input wires of the gate. + * @param type the type of gate (e.g., regular/input/output) + * @return the new gate. + */ + public Gate addGate(int n_ins, int type, boolean out_gate) { + int csize = circuit.size(); + Gate newgate = new Gate(csize, n_ins, type, out_gate); + circuit.add(newgate); + logger.info("add gate #" + csize + " with " + n_ins + + " inputs"); - /** - * Add a new gate with the specified number of input wires to - * the gates vector. - * - * @param n_ins the number of input wires of the gate. - * @param type the type of gate (e.g., regular/input/output) - * @return the new gate. - */ - public Gate addGate(int n_ins, int type, boolean out_gate) { - int csize = circuit.size(); - Gate newgate = new Gate(csize, n_ins, type, out_gate); - circuit.add(newgate); - logger.info("add gate #" + csize + " with " + n_ins + - " inputs"); - - return newgate; - } - - //--------------------------------------------------------------- + return newgate; + } - /** - * Get a gate from a circuit - */ - Gate getGate(int gate_num) { - assert ((gate_num >= 0) && (gate_num < circuit.size())) : "getGate: bad gate_num = " + - gate_num; + //--------------------------------------------------------------- - return (Gate) circuit.elementAt(gate_num); - } + /** + * Get a gate from a circuit + */ + public Gate getGate(int gate_num) { + assert ((gate_num >= 0) && (gate_num < circuit.size())) : "getGate: bad gate_num = " + + gate_num; - //--------------------------------------------------------------- + return (Gate) circuit.elementAt(gate_num); + } - /** - * Turn all gates in a circuit to encrypted gates - */ - public void generateEncCircuit() { + //--------------------------------------------------------------- - for (int i = 0; i < circuit.size(); i++) - getGate(i).generateEncGate(); - } + /** + * Turn all gates in a circuit to encrypted gates + */ + public void generateEncCircuit() { - //--------------------------------------------------------------- + for (int i = 0; i < circuit.size(); i++) + getGate(i).generateEncGate(); + } - /** - * Measure size of encrypted payload in an encrypted circuit - * - * @return int - circuit's encrypted payload size in bytes - */ - public int cmeasureEncPayload () { - int total_size = 0; + //--------------------------------------------------------------- - for (int i = 0; i < circuit.size(); i++) - total_size += getGate(i).gmeasureEncPayload (); + /** + * Measure size of encrypted payload in an encrypted circuit + * + * @return int - circuit's encrypted payload size in bytes + */ + public int cmeasureEncPayload () { + int total_size = 0; - return (total_size); - } + for (int i = 0; i < circuit.size(); i++) + total_size += getGate(i).gmeasureEncPayload (); - //--------------------------------------------------------------- + return (total_size); + } - /** - * Extract encrypyed payload from an encrypted circuit (for the - * purpose of communicating it in minimal overhead). - * - * @param total_size total size of the circuit's payload in bytes. - * @return a byte array with the relevant information. - */ - public byte[] cextractEncPayload (int total_size) { - int i, j, k = 0 ; - byte[] small_byte_arr; - byte[] big_byte_arr = new byte[total_size]; + //--------------------------------------------------------------- - // Extract relevant data from all the circuit's gates, - // and store it in the result array + /** + * Extract encrypyed payload from an encrypted circuit (for the + * purpose of communicating it in minimal overhead). + * + * @param total_size total size of the circuit's payload in bytes. + * @return a byte array with the relevant information. + */ + public byte[] cextractEncPayload (int total_size) { + int i, j, k = 0 ; + byte[] small_byte_arr; + byte[] big_byte_arr = new byte[total_size]; + + // Extract relevant data from all the circuit's gates, + // and store it in the result array + + for (i = 0; i < circuit.size(); i++) { + small_byte_arr = getGate(i).gextractEncPayload(); + if (small_byte_arr != null) { + for (j = 0; j < small_byte_arr.length ; j++, k++) + big_byte_arr[k] = small_byte_arr[j]; + } + } - for (i = 0; i < circuit.size(); i++) { - small_byte_arr = getGate(i).gextractEncPayload(); - if (small_byte_arr != null) { - for (j = 0; j < small_byte_arr.length ; j++, k++) - big_byte_arr[k] = small_byte_arr[j]; - } + return (big_byte_arr); } - return (big_byte_arr); - } - - //--------------------------------------------------------------- - - /** - * Inject encrypyed payload into a circuit. - * - * @param info byte array with data to inject - */ - public void cinjectEncPayload(byte[] info) { - int i, consumed_bytes, k; + //--------------------------------------------------------------- - for (i = k = 0; i < circuit.size(); i++) { - Gate g = getGate(i) ; - consumed_bytes = g.ginjectEncPayload(info, k); - k += consumed_bytes; + /** + * Inject encrypyed payload into a circuit. + * + * @param info byte array with data to inject + */ + public void cinjectEncPayload(byte[] info) { + int i, consumed_bytes, k; + + for (i = k = 0; i < circuit.size(); i++) { + Gate g = getGate(i) ; + consumed_bytes = g.ginjectEncPayload(info, k); + k += consumed_bytes; + } } - } - - //--------------------------------------------------------------- - /** - * Measure size of secret payload in an encrypted circuit - * - * @return int - circuit's secret payload size in bytes - */ - public int cmeasureSecPayload () { + //--------------------------------------------------------------- - return (circuit.size() * getGate(0).gmeasureSecPayload()); - } + /** + * Measure size of secret payload in an encrypted circuit + * + * @return int - circuit's secret payload size in bytes + */ + public int cmeasureSecPayload () { - //--------------------------------------------------------------- + return (circuit.size() * getGate(0).gmeasureSecPayload()); + } - /** - * Extract secret payload from an encrypted circuit (for the - * purpose of communicating it in minimal overhead). - * - * @param total_size total size of the circuit's payload in bytes. - * @return a byte array with the relevant information. - */ - public byte[] cextractSecPayload (int total_size) { - int i, j, k = 0 ; - byte[] small_byte_arr; - byte[] big_byte_arr = new byte[total_size]; + //--------------------------------------------------------------- - // Extract relevant data from all the circuit's gates, - // and store it in the result array + /** + * Extract secret payload from an encrypted circuit (for the + * purpose of communicating it in minimal overhead). + * + * @param total_size total size of the circuit's payload in bytes. + * @return a byte array with the relevant information. + */ + public byte[] cextractSecPayload (int total_size) { + int i, j, k = 0 ; + byte[] small_byte_arr; + byte[] big_byte_arr = new byte[total_size]; + + // Extract relevant data from all the circuit's gates, + // and store it in the result array + + for (i = 0; i < circuit.size(); i++) { + small_byte_arr = getGate(i).gextractSecPayload(); + if (small_byte_arr != null) { + for (j = 0; j < small_byte_arr.length ; j++, k++) + big_byte_arr[k] = small_byte_arr[j]; + } + } - for (i = 0; i < circuit.size(); i++) { - small_byte_arr = getGate(i).gextractSecPayload(); - if (small_byte_arr != null) { - for (j = 0; j < small_byte_arr.length ; j++, k++) - big_byte_arr[k] = small_byte_arr[j]; - } + return (big_byte_arr); } - return (big_byte_arr); - } - - //--------------------------------------------------------------- + //--------------------------------------------------------------- - /** - * Inject secret payload into a circuit. - * - * @param info byte array with data to inject - */ - public void cinjectSecPayload(byte[] info) { - int i, consumed_bytes, k; - - for (i = k = 0; i < circuit.size(); i++) { - Gate g = getGate(i) ; - consumed_bytes = g.ginjectSecPayload(info, k); - k += consumed_bytes; + /** + * Inject secret payload into a circuit. + * + * @param info byte array with data to inject + */ + public void cinjectSecPayload(byte[] info) { + int i, consumed_bytes, k; + + for (i = k = 0; i < circuit.size(); i++) { + Gate g = getGate(i) ; + consumed_bytes = g.ginjectSecPayload(info, k); + k += consumed_bytes; + } } - } - - //--------------------------------------------------------------- - /** - * Extract input payload from an encrypted circuit (for the - * purpose of communicating it in minimal overhead). - * - * @param total_size total size of the circuit's payload in bytes. - * @param alice_inputs true for alice, false for bob - * @return a byte array with the relevant information. - * + //--------------------------------------------------------------- + + /** + * Extract input payload from an encrypted circuit (for the + * purpose of communicating it in minimal overhead). + * + * @param total_size total size of the circuit's payload in bytes. + * @param alice_inputs true for alice, false for bob + * @return a byte array with the relevant information. public byte[] cextractInpPayload (int total_size, boolean alice_inputs) { int i, j, k = 0 ; byte[] small_byte_arr; @@ -257,16 +253,16 @@ return (big_byte_arr); } - */ - - //--------------------------------------------------------------- - - /** - * Inject input payload into a circuit. - * - * @param alice_inputs true for alice, false for bob - * @param info byte array with data to inject - * + */ + + //--------------------------------------------------------------- + + /** + * Inject input payload into a circuit. + * + * @param alice_inputs true for alice, false for bob + * @param info byte array with data to inject + * public void cinjectInpPayload(byte[] info, boolean alice_inputs) { int i, consumed_bytes, k; @@ -276,84 +272,84 @@ k += consumed_bytes; } } - */ + */ - //--------------------------------------------------------------- - - /** - * Verify that an exposed garbled circuit is correct - * (done by Alice in order to prevent cheating by Bob). - * - * @return true if the circuit is correct. - */ - public boolean isCorrect () { - - for (int i = 0; i < circuit.size(); i++) { - logger.debug("isCorrect: checking gate in line number " + i); - if (!getGate(i).isCorrect()) { - getGate(i).printGate(); - return false; - } - } + //--------------------------------------------------------------- - return true; - } + /** + * Verify that an exposed garbled circuit is correct + * (done by Alice in order to prevent cheating by Bob). + * + * @return true if the circuit is correct. + */ + public boolean isCorrect () { + + for (int i = 0; i < circuit.size(); i++) { + logger.debug("isCorrect: checking gate in line number " + i); + if (!getGate(i).isCorrect()) { + getGate(i).printGate(); + return false; + } + } - //--------------------------------------------------------------- + return true; + } - /** - * Evaluate a circuit - */ - public void evalCircuit() { - logger.info("evalCircuit: having " + circuit.size() + " gates"); - - for (int i = 0; i < circuit.size(); i++) { - logger.debug("evalCircuit: evaluating gate in line number " + i); - getGate(i).evalGate(); - } - } + //--------------------------------------------------------------- - //--------------------------------------------------------------- + /** + * Evaluate a circuit + */ + public void evalCircuit() { + logger.info("evalCircuit: having " + circuit.size() + " gates"); + + for (int i = 0; i < circuit.size(); i++) { + logger.debug("evalCircuit: evaluating gate in line number " + i); + getGate(i).evalGate(); + } + } - /** - * Evaluate a garbled circuit - * - * @param alice_interpret - interpret Alice garbled outputs - * @param bob_interpret - interpret Bob garbled outputs - */ - public void evalGarbledCircuit(boolean alice_interpret, boolean bob_interpret) { - logger.info("evalGarbledCircuit: having " + circuit.size() + " gates"); - - for (int i = 0; i < circuit.size(); i++) { - logger.debug("evalGarbledCircuit: evaluating gate in line number " + - i); - getGate(i).evalGarbledGate(alice_interpret, bob_interpret); - } - } + //--------------------------------------------------------------- - //--------------------------------------------------------------- + /** + * Evaluate a garbled circuit + * + * @param alice_interpret - interpret Alice garbled outputs + * @param bob_interpret - interpret Bob garbled outputs + */ + public void evalGarbledCircuit(boolean alice_interpret, boolean bob_interpret) { + logger.info("evalGarbledCircuit: having " + circuit.size() + " gates"); + + for (int i = 0; i < circuit.size(); i++) { + logger.debug("evalGarbledCircuit: evaluating gate in line number " + + i); + getGate(i).evalGarbledGate(alice_interpret, bob_interpret); + } + } + + //--------------------------------------------------------------- - /** - * For debugging purposes. - */ - public void printCircuit() { - for (int i = 0; i < circuit.size(); i++) { - System.out.print("Gate number " + i + ":"); - Gate g = getGate(i); - if (g == null) - System.out.println("null"); - else - g.printGate(); + /** + * For debugging purposes. + */ + public void printCircuit() { + for (int i = 0; i < circuit.size(); i++) { + System.out.print("Gate number " + i + ":"); + Gate g = getGate(i); + if (g == null) + System.out.println("null"); + else + g.printGate(); + } } - } - //--------------------------------------------------------------- - - /** Obsolete - * Clean all the gates in the circuit from secret information. - * - * @return a circuit that contains the secret, cleaned information. - * + //--------------------------------------------------------------- + + /** Obsolete + * Clean all the gates in the circuit from secret information. + * + * @return a circuit that contains the secret, cleaned information. + * public Circuit cleanSecretInfo() { Circuit c = new Circuit(); @@ -366,31 +362,31 @@ return (c); } - */ - - //--------------------------------------------------------------- - - /** Obsolete - * Restore the secret data of a circuit from a given circuit. - * - * @param c a circuit to restore the secret data from. - * + */ + + //--------------------------------------------------------------- + + /** Obsolete + * Restore the secret data of a circuit from a given circuit. + * + * @param c a circuit to restore the secret data from. + * public void restoreSecretInfo(Circuit c) { for (int i = 0; i < circuit.size(); i++) getGate(i).restoreGate(c.getGate(i)) ; } - */ - - //--------------------------------------------------------------- - - /** Obsolete - * Copy garbled inputs of either Bob or Alice from one circuit - * to another - * - * @param c1 a circuit to copy the garbled inputs from. - * @param alice_inputs true for alice, false for bob - * + */ + + //--------------------------------------------------------------- + + /** Obsolete + * Copy garbled inputs of either Bob or Alice from one circuit + * to another + * + * @param c1 a circuit to copy the garbled inputs from. + * @param alice_inputs true for alice, false for bob + * public void copyGarbledInputs(Circuit c1, boolean alice_inputs) { for (int i = 0; i < this.circuit.size(); i++) { @@ -407,16 +403,16 @@ g.copyGarbledInfo (g1); } } - */ + */ + + //--------------------------------------------------------------- - //--------------------------------------------------------------- - - /** Obsolete - * Verify that two circuits are logically equivalent - * - * @param gc a garbled circuit with inputs to compare to. - * @return true if the circuits are logically equivalent. - * + /** Obsolete + * Verify that two circuits are logically equivalent + * + * @param gc a garbled circuit with inputs to compare to. + * @return true if the circuits are logically equivalent. + * public boolean isEquivalent(Circuit gc) { if (circuit.size() != gc.circuit.size()) return false; @@ -426,5 +422,5 @@ return true; } - */ + */ } diff -ru --exclude='*/PF/*' Fairplay/source/SFE/BOAL/Formatter.java FairplayPF/source/SFE/BOAL/Formatter.java --- Fairplay/source/SFE/BOAL/Formatter.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/BOAL/Formatter.java 2008-01-31 12:39:27.000000000 -0600 @@ -4,13 +4,9 @@ package SFE.BOAL; -import org.apache.log4j.*; - import java.io.*; - -import java.math.*; - import java.util.*; +import org.apache.log4j.*; /** Formatter @@ -59,22 +55,18 @@ @author: Dahlia Malkhi and Yaron Sella */ /** - * This class parses an input file containing I/O format specification, and - * provides routines that interact with the user, and convert input/output - * to/from internal bit-representation. + * Formatter The format file describes the I/O with Alice and Bob in the following format:

Input line:
Alice/Bob input type "prompt-string" [ line-num1 .. line-numk ]

This line has the following interpretation: First, it designated this as Alice or Bob's input. The 'type' specifies the type of input, e.g., integer. The input will be provided by prompting Alice using "prompt-string". The input value is internally translated into k bits, LSB to MSB. These bits are given as input bits to gates in the designated lines.

Output line:
Alice/Bob output type "output-prefix" [ line-num1 .. line-numk ]

This line has the following interpretation: First, it designated this as Alice or Bob's output. The 'type' specifies the type of output, e.g., integer. The output will be gathered from k output gates, LSB to MSB, in the designated output gate lines. These output bits are translated into a value of the designated type, and printed with the designated "output-prefix"

Example file is:
Alice input integer "Enter # employees (up to 3): " [ 1 2 ] Bob input integer "Enter # employees (up to 3): " [ 3 4 ] Alice output integer "Total # employees: " [ 100 101 102 ] Bob output integer "Total # employees: " [ 100 101 102 ] This indicates that Alice should be prompted for an integer no greater than 3, which appears as input wires 1 and 2. Similarly, Bob should be prompted for his integer value for input wires 3 and 4. The output for Alice is an integer built off of output wires 100,101,102; likewise is Bob's output. + * @author : Dahlia Malkhi and Yaron Sella */ public class Formatter implements Serializable { private static final Logger logger = Logger.getLogger(Formatter.class); - static final int EOF_INDICATOR = -2; // Input file ended - static final int WORD_INDICATOR = -1; // Token read was a WORD - StreamTokenizer st; - String s = null; // Stores WORD tokens - boolean is_alice_line = false; // indicates Alice/Bob line - IO curIO = null; // IO object for current line - Vector FMT = new Vector(10, 10); // keeps all IO information - - public Formatter() { - } + protected static final int EOF_INDICATOR = -2; // Input file ended + protected static final int WORD_INDICATOR = -1; // Token read was a WORD + protected StreamTokenizer st; + protected String s = null; // Stores WORD tokens + protected boolean is_alice_line = false; // indicates Alice/Bob line + protected IO curIO = null; // IO object for current line + protected Vector FMT = new Vector(10, 10); // keeps all IO information public Formatter(StreamTokenizer st) { this.st = st; @@ -111,7 +103,7 @@ for (int j = 0; j < io.getNLines(); j++) { int line_num = io.getLinenum(j); Gate g = c.getGate(line_num); - g.markAliceBob (io.isAlice()); + g.markAliceBob (io.isAlice()); if (g.isBobInput()) tsize[0] += g.gmeasureInpPayload(); if (g.isBobOutput()) tsize[1] += g.gmeasureOutPayload(); } @@ -383,7 +375,6 @@ * and it consumes the entire input file while building an * internal representation of the I/O format * - * @param args - file name to parse expected in args[0]. * @exception - FormatterError. */ public void parse() throws FormatterError { @@ -406,7 +397,7 @@ * * @exception - FormatterError (bad line name) */ - private void parseLineName() throws FormatterError { + protected void parseLineName() throws FormatterError { int rc = parseToken(false); boolean inp_line = s.equals("input"); boolean out_line = s.equals("output"); @@ -461,7 +452,7 @@ * * @exception - FormatterError (bad input) */ - private void parseNumbers() throws FormatterError { + protected void parseNumbers() throws FormatterError { while (parseLineNum()) ; } @@ -537,7 +528,7 @@ * @exception - FormatterError upon StreamTokenizer/IO problem * @side-effect - puts WORD token in string s. */ - private int parseToken(boolean eof_ok) throws FormatterError { + protected int parseToken(boolean eof_ok) throws FormatterError { int status; int rc; @@ -577,7 +568,7 @@ * @param s1 - string to be parsed. * @exception - FormatterError (expected string not found) */ - private void parseString(String s1) throws FormatterError { + protected void parseString(String s1) throws FormatterError { parseToken(false); if (!s.equals(s1)) { diff -ru --exclude='*/PF/*' Fairplay/source/SFE/BOAL/FormatterError.java FairplayPF/source/SFE/BOAL/FormatterError.java --- Fairplay/source/SFE/BOAL/FormatterError.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/BOAL/FormatterError.java 2008-01-31 12:39:27.000000000 -0600 @@ -4,7 +4,7 @@ package SFE.BOAL; -class FormatterError extends Exception { +public class FormatterError extends Exception { public FormatterError(String s) { super(s); diff -ru --exclude='*/PF/*' Fairplay/source/SFE/BOAL/Gate.java FairplayPF/source/SFE/BOAL/Gate.java --- Fairplay/source/SFE/BOAL/Gate.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/BOAL/Gate.java 2008-01-31 12:39:27.000000000 -0600 @@ -4,28 +4,24 @@ package SFE.BOAL; -import org.apache.log4j.*; - import java.io.*; - -import java.security.*; - import java.util.*; - +import org.apache.log4j.*; /** -* This class holds information on a single gate -* @author: Dahlia Malkhi and Yaron Sella -*/ -class Gate implements Serializable { - private static final Logger logger = Logger.getLogger(Gate.class); + * This class holds information on a single gate + * @author : Dahlia Malkhi and Yaron Sella + */ +public class Gate implements Serializable { + private static final long serialVersionUID = -3834046572803832410L; + private static final Logger logger = Logger.getLogger(Gate.class); public static final int REG_GATE = 1; public static final int INP_GATE = 2; public static final int NBYTESG = 10; final int PPOS = 19; final int MAX_INPUTS = 20; int n_inputs; // # of inputs - int gate_index; // index in the circuit + public int gate_index; // index in the circuit int gate_type; boolean alice_io; boolean bob_io; @@ -65,20 +61,20 @@ this.gate_type = type; this.out_gate = out_gate; - alice_io = false; - bob_io = false; + alice_io = false; + bob_io = false; - gate_index = g_idx; + gate_index = g_idx; n_inputs = n_ins; in_gates = new Gate[MAX_INPUTS]; truth_table = new BitSet(1 << n_inputs); value = -1; - // Fill in garbling related data + // Fill in garbling related code0 = new byte[NBYTESG]; code1 = new byte[NBYTESG]; - hcode0 = null; - hcode1 = null; + hcode0 = null; + hcode1 = null; MyUtil.randomBytes(code0); MyUtil.randomBytes(code1); @@ -142,7 +138,7 @@ */ public void markAliceBob(boolean alice) { alice_io = alice; - bob_io = !alice; + bob_io = !alice; } //--------------------------------------------------------------- @@ -201,6 +197,10 @@ public boolean isOutput() { return (out_gate); } + + public void setOutput(boolean out_gate) { + this.out_gate=out_gate; + } //--------------------------------------------------------------- @@ -377,8 +377,8 @@ garbled_value = new byte[NBYTESG]; - for (int i = 0 ; i < gdataCode.length ; i++) - garbled_value[i] = gdataCode[i]; + for (int i = 0 ; i < gdataCode.length ; i++) + garbled_value[i] = gdataCode[i]; value = interpretCode(); } @@ -510,6 +510,10 @@ int permuted_index; byte[] enc_key; + MyUtil.randomBytes(code0); + MyUtil.randomBytes(code1); + perm = (byte) (MyUtil.randomByte() & 0x01); + if (isInput()) { return; } @@ -540,10 +544,10 @@ permuted_index + "] = " + encrypted_perm[permuted_index]); } - if (isAliceOutput()) { + if (isAliceOutput()) { hcode0 = MyUtil.hash(code0, NBYTESG); hcode1 = MyUtil.hash(code1, NBYTESG); - } + } } //--------------------------------------------------------------- @@ -561,7 +565,7 @@ return 0; } - n_ent = encrypted_truth_table.size() ; + n_ent = encrypted_truth_table.size(); // Count garbled perm bytes total_size = n_ent ; @@ -570,7 +574,7 @@ temp = (byte[]) encrypted_truth_table.elementAt(0) ; total_size += n_ent * temp.length ; - if (isAliceOutput()) // Count hashed codes bytes + if (isAliceOutput()) // Count hashed codes bytes total_size += hcode0.length + hcode1.length; return (total_size); @@ -683,7 +687,6 @@ */ public byte[] gextractSecPayload() { int i, k = 0 ; - byte[] temp; // Create a result byte array with the appropriate size @@ -748,7 +751,6 @@ public byte[] gextractInpPayload() { int i, k = 0 ; int total_size; - byte[] temp; total_size = gmeasureInpPayload(); if (total_size == 0) return null; @@ -979,10 +981,10 @@ */ public int interpretCode() { int i, count; - byte[] code; + byte[] code; // Evaluation for Alice output against a hash of the garbled value - if (isAliceOutput()) { + if (isAliceOutput()) { code = MyUtil.hash (garbled_value, NBYTESG); for (i = count = 0; i < hcode0.length; i++) @@ -992,7 +994,7 @@ for (i = count = 0; i < hcode1.length; i++) if (code[i] == hcode1[i]) count += 1; if (count == hcode1.length) return (1); - } + } // Evaluation for Bob output against the garbled value itself else if (isBobOutput()) { code = garbled_value; @@ -1012,6 +1014,18 @@ return (-1); // Can never be reached } + public String toString() { + String s="index="+gate_index+" n_inputs="+n_inputs+" gate_type="+gate_type+" ["; + for(int i=0; i (running line number) [output] input

or

(running line number) [output] gate arity n table [ 0..(2^n)-1 enumeration of 0/1 outputs ] inputs [ line-num1 .. line-numn ]
// outputs for each possible n-bit input
// n inputs, designated by line-number

Note: a line with a "gate name", of the form:
(running line) and line-num1 line-num2
is simply a macro, that expands into:

(running line) gate arity 2 table [ 0 0 0 1 ] inputs [ line-num1 line-num2 ]
Explanation: The gate has 2 inputs; The output enumeration is:
00 : output 0
01 : output 0
10 : output 0
11 : output 1 + * @author : Dahlia Malkhi and Yaron Sella */ public class Parser { - private static final Logger logger = Logger.getLogger(Parser.class); - static final int EOF_INDICATOR = -2; // Input file ended - static final int WORD_INDICATOR = -1; // Token read was a WORD - static final int INPUT_LINE = -2; // Line encountered of type input-line - static final int GATE_LINE = -1; // Line encountered of type gate-line + protected static final Logger logger = Logger.getLogger(Parser.class); + protected static final int EOF_INDICATOR = -2; // Input file ended + protected static final int WORD_INDICATOR = -1; // Token read was a WORD + protected static final int INPUT_LINE = -2; // Line encountered of type input-line + protected static final int GATE_LINE = -1; // Line encountered of type gate-line private StreamTokenizer st; private String s = null; // Stores WORD tokens - private int line_num = -1; // Current line number - private int ninputs = 0; // Num of inputs in a gate-line + protected int line_num = -1; // Current line number + protected int ninputs = 0; // Num of inputs in a gate-line private int args_ind = 1; private Circuit circuit; @@ -148,7 +142,7 @@ * @return true if parsing should continue (a new line encountered). * @exception - ParseError (bad line number) */ - private boolean parseLineNum() throws ParseError { + protected boolean parseLineNum() throws ParseError { int ln = parseToken(true); if (ln == EOF_INDICATOR) { @@ -172,7 +166,7 @@ * @return indicator for type of line encountered (input or gate) * @exception - ParseError (bad line name) */ - private int parseLineName() throws ParseError { + protected int parseLineName() throws ParseError { int rc = parseToken(false); boolean inp_line = s.equals("input"); boolean gate_line = s.equals("gate"); @@ -223,7 +217,7 @@ * @param s1 - string to be parsed. * @exception - ParseError (expected string not found) */ - private void parseString(String s1) throws ParseError { + protected void parseString(String s1) throws ParseError { parseToken(false); if (!s.equals(s1)) { @@ -240,7 +234,7 @@ * @param s1 - string to be optionally parsed. * @return true if specific optional string was found */ - private boolean parseOptString(String s1) throws ParseError { + protected boolean parseOptString(String s1) throws ParseError { parseToken(false); boolean rc = s.equals(s1); @@ -260,7 +254,7 @@ * @return - number of inputs that this gate has. * @exception - ParseError (bad # of inputs) */ - private int parseNumInputs() throws ParseError { + protected int parseNumInputs() throws ParseError { final int MAX_INS = 4; ninputs = parseToken(false); @@ -298,7 +292,7 @@ * @return the wire number parsed from input. * @exception - ParseError (bad wire #) */ - private int parseWireNum() throws ParseError { + protected int parseWireNum() throws ParseError { int wire_num = parseToken(false); // Verify input line-number makes sense @@ -353,7 +347,7 @@ * @exception - ParseError upon StreamTokenizer/IO problem * @side-effect - puts WORD token in string s. */ - private int parseToken(boolean eof_ok) throws ParseError { + protected int parseToken(boolean eof_ok) throws ParseError { int status; int rc; @@ -404,22 +398,22 @@ * args[1] should be format filename */ public static void main(String[] args) { - Parser p = null; // the parser and builder of the circuit - Formatter f = null; // the parser and builder of the IO - BufferedReader br = null; // Reads from stdio - int[] dumm = new int[2]; - - // Load logging configuration file - PropertyConfigurator.configure(MyUtil.pathFile("SFE_logcfg.lcf")); - - if (args.length != 2) - parserUsage(); - - String circuit_filename = args[0] + ".Opt.circuit"; - String fmt_filename = args[0] + ".Opt.fmt"; - String sseed = args[1]; + Parser p = null; // the parser and builder of the circuit + Formatter f = null; // the parser and builder of the IO + BufferedReader br = null; // Reads from stdio + int[] dumm = new int[2]; + + // Load logging configuration file + PropertyConfigurator.configure(MyUtil.pathFile("SFE_logcfg.lcf")); + + if (args.length != 2) + parserUsage(); + + String circuit_filename = args[0] + ".Opt.circuit"; + String fmt_filename = args[0] + ".Opt.fmt"; + String sseed = args[1]; - // Parse the circuit file and prepare the circuit + // Parse the circuit file and prepare the circuit FileReader fr = null; StreamTokenizer st = null; @@ -444,7 +438,7 @@ } catch (Exception e) { logger.error("main: exception - " + e.getMessage()); } - + // Parse the IOformat file and prepare the inputs // FileReader fmt = null; @@ -472,7 +466,7 @@ // now do something with the circuit! Circuit c = p.getCircuit(); - f.markIO (c, dumm); + f.markIO (c, dumm); c.generateEncCircuit(); br = new BufferedReader(new InputStreamReader(System.in)); @@ -489,7 +483,7 @@ f.getBobOutput(c); // print Bob's output } - class ParseError extends Exception { + public class ParseError extends Exception { public ParseError(String s) { super(s); logger.error(s); diff -ru --exclude='*/PF/*' Fairplay/source/SFE/Compiler/BitLvalue.java FairplayPF/source/SFE/Compiler/BitLvalue.java --- Fairplay/source/SFE/Compiler/BitLvalue.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/Compiler/BitLvalue.java 2008-01-31 12:39:27.000000000 -0600 @@ -26,10 +26,10 @@ * @param varLvalue the given VarLvalue. * @param bit the bit offset in the VarLvalue. */ - public BitLvalue(Lvalue base, int bit) { - this.base = base; + public BitLvalue(Lvalue varLvalue, int bit) { + this.base = varLvalue; this.bit = bit; - this.isOutput = base.isOutput(); + this.isOutput = varLvalue.isOutput(); } //~ Methods ---------------------------------------------------------------- diff -ru --exclude='*/PF/*' Fairplay/source/SFE/Compiler/Function.java FairplayPF/source/SFE/Compiler/Function.java --- Fairplay/source/SFE/Compiler/Function.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/Compiler/Function.java 2008-01-31 12:39:27.000000000 -0600 @@ -192,8 +192,8 @@ } /** - * Adds a statement to this function. - * @param statement the new statement. + * Adds statements to this function. + * @param statements the new statements. */ public void addStatements(Vector statements) { body.addAll(statements); diff -ru --exclude='*/PF/*' Fairplay/source/SFE/Compiler/Optimizer.java FairplayPF/source/SFE/Compiler/Optimizer.java --- Fairplay/source/SFE/Compiler/Optimizer.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/Compiler/Optimizer.java 2008-01-31 12:39:27.000000000 -0600 @@ -63,7 +63,7 @@ /** * Adds an AssignmentStatement to the usage data structure. - * @param as the AssignmentStatement to be added. + * @param s the AssignmentStatement to be added. */ public static void putUsedStatement(Statement s) { usedStatements.put(s, null); diff -ru --exclude='*/PF/*' Fairplay/source/SFE/Compiler/PrimitiveOperator.java FairplayPF/source/SFE/Compiler/PrimitiveOperator.java --- Fairplay/source/SFE/Compiler/PrimitiveOperator.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/Compiler/PrimitiveOperator.java 2008-01-31 12:39:27.000000000 -0600 @@ -28,7 +28,6 @@ * Construct a new PrimitiveOperator from a given int that * represents the operator. * @param truthTable the int that represents the truth table. - * @param midSize the size of the operand in case of unary operator. */ public PrimitiveOperator(int truthTable) throws IllegalArgumentException { this(PRIMITIVE_TRUTH_TABLES[truthTable]); @@ -394,8 +393,6 @@ /** * Returns a string representing this object as it appear at the * output circuit. - * @return a string representing this object as it appear at the - * output circuit. */ public void toCircuit(PrintWriter circuit) { circuit.print("gate arity " + arity() + " table [ "); @@ -408,6 +405,8 @@ /** * Returns a string representation of the object. + * @return a string representing this object as it appear at the + * output circuit. */ public String toString() { String str = "gate arity " + arity() + " table [ "; diff -ru --exclude='*/PF/*' Fairplay/source/SFE/Compiler/Program.java FairplayPF/source/SFE/Compiler/Program.java --- Fairplay/source/SFE/Compiler/Program.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/Compiler/Program.java 2008-01-31 12:39:27.000000000 -0600 @@ -80,13 +80,11 @@ /** * Returns a string representing this object as it appear at the * output circuit. - * @return a string representing this object as it appear at the - * output circuit. */ public void toCircuit(PrintWriter circuit, boolean opt) { System.out.println("Writing to circuit file."); - // assgn new line numbers to the program (in case it was optimized) + // assign new line numbers to the program (in case it was optimized) resetCounter(); // start with the two constant gate false and true. diff -ru --exclude='*/PF/*' Fairplay/source/SFE/Compiler/UnaryOpExpression.java FairplayPF/source/SFE/Compiler/UnaryOpExpression.java --- Fairplay/source/SFE/Compiler/UnaryOpExpression.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/Compiler/UnaryOpExpression.java 2008-01-31 12:39:27.000000000 -0600 @@ -114,8 +114,6 @@ /** * Returns a string representing this object as it appear at the * output circuit. - * @return a string representing this object as it appear at the - * output circuit. */ public void toCircuit(PrintWriter circuit) { if (((PrimitiveOperator) op).isID() && diff -ru --exclude='*/PF/*' Fairplay/source/SFE/GPL.txt FairplayPF/source/SFE/GPL.txt --- Fairplay/source/SFE/GPL.txt 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/GPL.txt 2008-01-31 12:39:27.000000000 -0600 @@ -12,4 +12,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -Contacts: ysella at cs.huji.ac.il, dalia at cs.huji.ac.il +Contacts Fairplay: ysella at cs.huji.ac.il, dalia at cs.huji.ac.il + +Contact FairplayPF: thomaschneider at gmail.com diff -ru --exclude='*/PF/*' Fairplay/source/SFE/GUI/Statement.java FairplayPF/source/SFE/GUI/Statement.java --- Fairplay/source/SFE/GUI/Statement.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/GUI/Statement.java 2008-01-31 12:39:27.000000000 -0600 @@ -65,7 +65,7 @@ * * @param level Indentation level * @param nextLevel The level of the following line - * @parma code The code line + * @param code The code line * @param output Wether to output this line in the code */ public Statement(int level, int nextLevel, String code, boolean output) { diff -ru --exclude='*/PF/*' Fairplay/source/SFE/GUI/Type.java FairplayPF/source/SFE/GUI/Type.java --- Fairplay/source/SFE/GUI/Type.java 2008-01-31 13:00:27.000000000 -0600 +++ FairplayPF/source/SFE/GUI/Type.java 2008-01-31 12:39:27.000000000 -0600 @@ -34,7 +34,7 @@ public String nArray = ""; // Number of elements public String enumVals = null; // Enum elements public DefaultListModel structVars = null; // Struct members - public boolean enum = false; + public boolean _enum = false; public boolean struct = false; private boolean primitive = false; private boolean must = false; @@ -105,7 +105,7 @@ */ public Type(String name, String vals) { nameDoc = new ProgramDocument(name); - enum = true; + _enum = true; enumVals = vals; if (this.nameDoc.length() == 0) { @@ -144,7 +144,7 @@ nBits = DEFAULT_INT_BITS; nArray = ""; this.type = type; - enum = false; + _enum = false; enumVals = null; struct = false; structVars = null; @@ -159,7 +159,7 @@ nBits = bits; nArray = ""; type = INT; - enum = false; + _enum = false; enumVals = null; struct = false; structVars = null; @@ -176,7 +176,7 @@ nBits = bits; nArray = array; this.type = type; - enum = false; + _enum = false; enumVals = null; struct = false; structVars = null; @@ -191,7 +191,7 @@ nBits = DEFAULT_INT_BITS; nArray = ""; type = null; - enum = true; + _enum = true; enumVals = enumData; struct = false; structVars = null; @@ -206,7 +206,7 @@ nBits = DEFAULT_INT_BITS; nArray = ""; type = null; - enum = false; + _enum = false; enumVals = null; struct = true; structVars = vars; @@ -262,7 +262,7 @@ * Is type an enumerated type */ public boolean isEnum() { - return enum; + return _enum; } /** @@ -274,8 +274,6 @@ /** * Get Type name - * - * @param Type name */ public String getName() { if (nameDoc.getDoc().length() == 0) { @@ -311,7 +309,7 @@ } // enum - if (enum) { + if (_enum) { return res + "enum {" + enumVals + "}"; } // struct Only in FairplayPF/source/SFE: PF