AesDemo implements Application<List<Boolean>, ProtocolBuilderBinary> { public static <ResourcePoolT extends ResourcePool> void main(String[] args) throws IOException { CmdLineUtil<ResourcePoolT, ProtocolBuilderBinary> util = new CmdLineUtil<>(); util.addOption(Option.builder("in") .desc("The input to use for encryption. " + "A " + INPUT_LENGTH + " char hex string. Required for player 1 and 2. " + "For player 1 this is interpreted as the AES key. " + "For player 2 this is interpreted as the plaintext block to encrypt.") .longOpt("input").hasArg().build()); CommandLine cmd = util.parse(args); Boolean[] input; int myId = util.getNetworkConfiguration().getMyId(); if (myId == 1 || myId == 2) { if (!cmd.hasOption("in")) { throw new IllegalArgumentException("Player 1 and 2 must submit input"); } else { if (cmd.getOptionValue("in").length() != INPUT_LENGTH) { throw new IllegalArgumentException( "bad input hex string: must be hex string of length " + INPUT_LENGTH); } input = ByteAndBitConverter.toBoolean(cmd.getOptionValue("in")); } } else { if (cmd.hasOption("in")) { throw new IllegalArgumentException("Only player 1 and 2 should submit input"); } input = ByteAndBitConverter.toBoolean("00000000000000000000000000000000"); } ProtocolSuite<ResourcePoolT, ProtocolBuilderBinary> psConf = util.getProtocolSuite(); SecureComputationEngine<ResourcePoolT, ProtocolBuilderBinary> sce = new SecureComputationEngineImpl<>(psConf, util.getEvaluator()); ResourcePoolT resourcePool = util.getResourcePool(); AesDemo aes = new AesDemo(util.getNetworkConfiguration().getMyId(), input); List<Boolean> aesResult = sce.runApplication(aes, resourcePool, util.getNetwork()); util.closeNetwork(); sce.shutdownSCE(); boolean[] res = new boolean[BLOCK_SIZE]; for (int i = 0; i < BLOCK_SIZE; i++) { res[i] = aesResult.get(i); } System.out.println("The resulting ciphertext is: " + ByteAndBitConverter.toHex(res)); } AesDemo(int id, Boolean[] in); static void main(String[] args); @Override DRes<List<Boolean>> buildComputation(ProtocolBuilderBinary producer);  }
@Test public void testAESCmdLine() throws Exception { Runnable p1 = () -> { try { AesDemo.main( new String[]{"-i", "1", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-s", "dummyBool", "-in", "000102030405060708090a0b0c0d0e0f"}); } catch (IOException e) { throw new RuntimeException("Error", e); } }; Runnable p2 = () -> { try { AesDemo.main( new String[]{"-i", "2", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-s", "dummyBool", "-in", "00112233445566778899aabbccddeeff"}); } catch (IOException e) { throw new RuntimeException("Error", e); } }; Thread t1 = new Thread(p1); Thread t2 = new Thread(p2); t1.start(); t2.start(); t1.join(); t2.join(); }
@Test public void testAESCmdLine3Party() throws Exception { Runnable p1 = () -> { try { AesDemo.main( new String[]{"-i", "1", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-p", "3:localhost:8083", "-s", "dummyBool", "-in", "000102030405060708090a0b0c0d0e0f"}); } catch (IOException e) { throw new RuntimeException("Error", e); } }; Runnable p2 = () -> { try { AesDemo.main( new String[]{"-i", "2", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-p", "3:localhost:8083", "-s", "dummyBool", "-in", "00112233445566778899aabbccddeeff"}); } catch (IOException e) { throw new RuntimeException("Error", e); } }; Runnable p3 = () -> { try { AesDemo.main( new String[]{"-i", "3", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-p", "3:localhost:8083", "-s", "dummyBool"}); } catch (IOException e) { throw new RuntimeException("Error", e); } }; Thread t1 = new Thread(p1); Thread t2 = new Thread(p2); Thread t3 = new Thread(p3); t1.start(); t2.start(); t3.start(); t1.join(); t2.join(); t3.join(); }
@Test(expected=IllegalArgumentException.class) public void testAESCmdLineBadLength() throws Exception { AesDemo.main( new String[]{"-i", "1", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-s", "dummyBool", "-in", "000102030405060708090a0b0c0d0"}); fail(); }
@Test(expected=IllegalArgumentException.class) public void testAESCmdLineNoInput() throws Exception { AesDemo.main( new String[]{"-i", "1", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-s", "dummyBool"}); fail(); }
@Test(expected=IllegalArgumentException.class) public void testAESCmdLine3PartyInput() throws Exception { AesDemo.main( new String[]{"-i", "3", "-p", "1:localhost:8081", "-p", "2:localhost:8082", "-p", "3:localhost:8083", "-s", "dummyBool", "-in", "000102030405060708090a0b0c0d0"}); fail(); }