Skip to content

Commit 3869bf4

Browse files
committedOct 24, 2017
mpc shared clasess moved into separate folder
initial steps of MystHost app
1 parent d087b40 commit 3869bf4

16 files changed

+1014
-64
lines changed
 
+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
package mystlib;
2+
3+
import com.licel.jcardsim.io.CAD;
4+
import com.licel.jcardsim.io.JavaxSmartCardInterface;
5+
import java.util.ArrayList;
6+
import javacard.framework.AID;
7+
import javacard.framework.ISO7816;
8+
import javax.smartcardio.Card;
9+
import javax.smartcardio.CardChannel;
10+
import javax.smartcardio.CardException;
11+
import javax.smartcardio.CardTerminal;
12+
import javax.smartcardio.CommandAPDU;
13+
import javax.smartcardio.ResponseAPDU;
14+
import javax.smartcardio.TerminalFactory;
15+
16+
public class CardManagement {
17+
static Long m_lastTransmitTime = new Long(0);
18+
19+
// Card Logistics
20+
private static CardChannel Connect(MPCRunConfig runCfg) throws Exception {
21+
switch (runCfg.testCardType) {
22+
case PHYSICAL: {
23+
return ConnectPhysicalCard(runCfg.targetReaderIndex, runCfg.appletAID);
24+
}
25+
case JCOPSIM: {
26+
return ConnectJCOPSimulator(runCfg.targetReaderIndex, runCfg.appletAID);
27+
}
28+
case JCARDSIMLOCAL: {
29+
return ConnectJCardSimLocalSimulator(runCfg.appletToSimulate, runCfg.appletAID);
30+
}
31+
case JCARDSIMREMOTE: {
32+
return null; // Not implemented yet
33+
}
34+
default:
35+
return null;
36+
}
37+
38+
}
39+
40+
private static CardChannel ConnectPhysicalCard(int targetReaderIndex, byte[] appletAID) throws Exception {
41+
System.out.print("Looking for physical cards... ");
42+
return connectToCardByTerminalFactory(TerminalFactory.getDefault(), targetReaderIndex, appletAID);
43+
}
44+
45+
private static CardChannel ConnectJCOPSimulator(int targetReaderIndex, byte[] appletAID) throws Exception {
46+
// JCOP Simulators
47+
System.out.print("Looking for JCOP simulators...");
48+
int[] ports = new int[]{8050};
49+
return connectToCardByTerminalFactory(TerminalFactory.getInstance("JcopEmulator", ports), targetReaderIndex, appletAID);
50+
}
51+
52+
private static CardChannel ConnectJCardSimLocalSimulator(Class appletClass, byte[] appAID) throws Exception {
53+
System.setProperty("com.licel.jcardsim.terminal.type", "2");
54+
CAD cad = new CAD(System.getProperties());
55+
JavaxSmartCardInterface simulator = (JavaxSmartCardInterface) cad.getCardInterface();
56+
byte[] installData = new byte[0];
57+
AID appletAID = new AID(appAID, (short) 0, (byte) appAID.length);
58+
59+
AID appletAIDRes = simulator.installApplet(appletAID, appletClass, installData, (short) 0, (byte) installData.length);
60+
simulator.selectApplet(appletAID);
61+
return new SimulatedCardChannelLocal(simulator, appletAIDRes);
62+
}
63+
64+
private static CardChannel connectToCardByTerminalFactory(TerminalFactory factory, int targetReaderIndex, byte[] appAID) throws CardException {
65+
ArrayList<CardTerminal> terminals = new ArrayList<>();
66+
67+
boolean card_found = false;
68+
CardTerminal terminal = null;
69+
Card card = null;
70+
try {
71+
for (CardTerminal t : factory.terminals().list()) {
72+
terminals.add(t);
73+
if (t.isCardPresent()) {
74+
card_found = true;
75+
}
76+
}
77+
System.out.println("Success.");
78+
} catch (Exception e) {
79+
System.out.println("Failed.");
80+
}
81+
82+
if (card_found) {
83+
System.out.println("Cards found: " + terminals);
84+
85+
terminal = terminals.get(targetReaderIndex); // Prioritize physical card over simulations
86+
87+
System.out.print("Connecting...");
88+
card = terminal.connect("*"); // Connect with the card
89+
90+
System.out.println(" Done.");
91+
92+
System.out.print("Establishing channel...");
93+
CardChannel channel = card.getBasicChannel();
94+
95+
System.out.println(" Done.");
96+
97+
// Select applet (mpcapplet)
98+
System.out.println("Smartcard: Selecting applet...");
99+
100+
CommandAPDU cmd = new CommandAPDU(appAID);
101+
102+
ResponseAPDU response = transmit(channel, cmd);
103+
104+
} else {
105+
System.out.print("Failed to find physical card.");
106+
}
107+
108+
if (card != null) {
109+
return card.getBasicChannel();
110+
} else {
111+
return null;
112+
}
113+
}
114+
115+
public static void ConnectAllPhysicalCards(byte[] appletAID, ArrayList<CardChannel> cardsList) throws Exception {
116+
System.out.print("Looking for physical cards... ");
117+
connectToAllCardsByTerminalFactory(TerminalFactory.getDefault(), appletAID, cardsList);
118+
}
119+
120+
private static void connectToAllCardsByTerminalFactory(TerminalFactory factory, byte[] appAID, ArrayList<CardChannel> cardsList) throws CardException {
121+
ArrayList<CardTerminal> terminals = new ArrayList<>();
122+
123+
CardTerminal terminal = null;
124+
Card card = null;
125+
try {
126+
for (CardTerminal t : factory.terminals().list()) {
127+
terminals.add(t);
128+
if (t.isCardPresent()) {
129+
System.out.print("Connecting...");
130+
card = terminal.connect("*"); // Connect with the card
131+
132+
System.out.println(" Done.");
133+
134+
System.out.print("Establishing channel...");
135+
CardChannel channel = card.getBasicChannel();
136+
137+
System.out.println(" Done.");
138+
139+
// Select applet (mpcapplet)
140+
System.out.println("Smartcard: Selecting applet...");
141+
CommandAPDU cmd = new CommandAPDU(appAID);
142+
ResponseAPDU response = transmit(channel, cmd);
143+
144+
if (response.getSW() == (ISO7816.SW_NO_ERROR & 0xffff)) {
145+
cardsList.add(channel);
146+
}
147+
}
148+
}
149+
} catch (Exception e) {
150+
System.out.println("Failed.");
151+
}
152+
153+
System.out.println("Cards found: " + cardsList.size());
154+
}
155+
156+
157+
public static ResponseAPDU transmit(CardChannel channel, CommandAPDU cmd)
158+
throws CardException {
159+
log(cmd);
160+
161+
long elapsed = -System.currentTimeMillis();
162+
ResponseAPDU response = channel.transmit(cmd);
163+
elapsed += System.currentTimeMillis();
164+
m_lastTransmitTime = elapsed;
165+
log(response, elapsed);
166+
167+
return response;
168+
}
169+
170+
private static void log(CommandAPDU cmd) {
171+
System.out.printf("--> %s\n", Util.toHex(cmd.getBytes()),
172+
cmd.getBytes().length);
173+
}
174+
175+
private static void log(ResponseAPDU response, long time) {
176+
String swStr = String.format("%02X", response.getSW());
177+
byte[] data = response.getData();
178+
if (data.length > 0) {
179+
System.out.printf("<-- %s %s (%d)\n", Util.toHex(data), swStr,
180+
data.length);
181+
} else {
182+
System.out.printf("<-- %s\n", swStr);
183+
}
184+
if (time > 0) {
185+
System.out.printf(String.format("Elapsed time %d ms\n", time));
186+
}
187+
}
188+
189+
private static void log(ResponseAPDU response) {
190+
log(response, 0);
191+
}
192+
193+
public static boolean checkSW(ResponseAPDU response) {
194+
if (response.getSW() != (Consts.SW_SUCCESS & 0xffff)) {
195+
System.err.printf("Received error status: %02X.\n",
196+
response.getSW());
197+
return false;
198+
}
199+
return true;
200+
}
201+
202+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package mystlib;
2+
3+
import javax.smartcardio.CardChannel;
4+
5+
/**
6+
*
7+
* @author Petr Svenda
8+
*/
9+
public class CardProfile {
10+
short cardIndex = 0;
11+
CardChannel channel;
12+
}

‎MPCShared/src/mystlib/Consts.java

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
package mystlib;
2+
3+
/**
4+
*
5+
* @author Petr Svenda
6+
*/
7+
public class Consts {
8+
// Manually updated version of corresponding git commit
9+
public final static byte[] GIT_COMMIT_MANUAL = {(byte) 0x01, (byte) 0x14, (byte) 0x20, (byte) 0xaf};
10+
11+
// MAIN INSTRUCTION CLASS
12+
public final static byte CLA_MPC = (byte) 0xB0;
13+
14+
// INStructions
15+
// Card Management
16+
17+
public final static byte INS_QUORUM_SETUP_NEW = (byte) 0x01;
18+
public final static byte INS_PERSONALIZE_GETCARDINFO = (byte) 0x02;
19+
public final static byte INS_QUORUM_RESET = (byte) 0x03;
20+
public final static byte INS_PERF_SETSTOP = (byte) 0x04;
21+
public final static byte INS_SET_BACKDOORED_EXAMPLE = (byte) 0x05;
22+
public final static byte INS_TESTECC = (byte) 0x06;
23+
public final static byte INS_QUORUM_REMOVE = (byte) 0x07;
24+
25+
public final static byte INS_PERSONALIZE_INITIALIZE = (byte) 0x08;
26+
public final static byte INS_PERSONALIZE_SET_USER_AUTH_PUBKEY = (byte) 0x09;
27+
28+
29+
30+
31+
32+
// KeyGen Operations
33+
public final static byte INS_KEYGEN_INIT = (byte) 0x10;
34+
public final static byte INS_KEYGEN_RETRIEVE_COMMITMENT = (byte) 0x11;
35+
public final static byte INS_KEYGEN_STORE_COMMITMENT = (byte) 0x12;
36+
public final static byte INS_KEYGEN_STORE_PUBKEY = (byte) 0x13;
37+
public final static byte INS_KEYGEN_RETRIEVE_PUBKEY = (byte) 0x14;
38+
public final static byte BUGBUG_INS_KEYGEN_RETRIEVE_PRIVKEY = (byte) 0x15;
39+
public final static byte INS_KEYGEN_RETRIEVE_AGG_PUBKEY = (byte) 0x16;
40+
41+
public final static byte INS_KEYPROPAGATION_RETRIEVE_PRIVKEY_SHARES = (byte) 0x20;
42+
public final static byte INS_KEYPROPAGATION_SET_PRIVKEY_SHARES = (byte) 0x21;
43+
public final static byte INS_KEYPROPAGATION_RECONSTRUCT_PRIVATEKEY = (byte) 0x22;
44+
45+
46+
// Encryption/Decryption Operations
47+
public final static byte INS_ENCRYPT = (byte) 0x50;
48+
public final static byte INS_DECRYPT = (byte) 0x51;
49+
50+
51+
public final static byte INS_GENERATE_RANDOM = (byte) 0x55;
52+
53+
// Signing Operations
54+
// 0x60 to 0x6F and 0x90 to 0x9F are not allowed according to ISO 7816-3 and -4
55+
//public final static byte INS_SIGN_INIT = (byte) 0x70;
56+
//public final static byte INS_SIGN_RETRIEVE_HASH = (byte) 0x71;
57+
//public final static byte INS_SIGN_STORE_HASH = (byte) 0x72;
58+
//public final static byte INS_SIGN_STORE_RI = (byte) 0x73;
59+
//public final static byte INS_SIGN_STORE_RI_N_HASH = (byte) 0x74;
60+
public final static byte INS_SIGN_RETRIEVE_RI = (byte) 0x75;
61+
//public final static byte INS_SIGN_RETRIEVE_RI_N_HASH = (byte) 0x76;
62+
//public final static byte BUGBUG_INS_SIGN_RETRIEVE_KI = (byte) 0x77; // BUGBUG: only for testing, remove
63+
//public final static byte BUGBUG_INS_SIGN_RETRIEVE_R = (byte) 0x78; // BUGBUG: only for testing, remove
64+
public final static byte INS_SIGN = (byte) 0x79;
65+
public final static byte INS_SIGN_GET_CURRENT_COUNTER = (byte) 0x7a;
66+
67+
68+
//Low level Operations
69+
public final static byte INS_ADDPOINTS = (byte) 0x80;
70+
71+
// Custom error response codes
72+
public static final short SW_SUCCESS = (short) 0x9000;
73+
public static final short SW_TOOMANYPLAYERS = (short) 0x8000;
74+
public static final short SW_INCORRECTSTATE = (short) 0x8001;
75+
public static final short SW_INVALIDCOMMITMENT = (short) 0x8002;
76+
public static final short SW_INVALIDYSHARE = (short) 0x8003;
77+
public static final short SW_SHAREALREADYSTORED = (short) 0x8004;
78+
public static final short SW_CANTALLOCATE_BIGNAT = (short) 0x8005;
79+
public static final short SW_INVALIDPOINTTYPE = (short) 0x8006;
80+
public static final short SW_NOTSUPPORTEDYET = (short) 0x8007;
81+
public static final short SW_INTERNALSTATEMISMATCH = (short) 0x8008;
82+
public static final short SW_INVALIDPLAYERINDEX = (short) 0x8009;
83+
public static final short SW_UNKNOWNSTATE = (short) 0x800a;
84+
public static final short SW_UNKNOWNFUNCTION = (short) 0x800b;
85+
public static final short SW_COMMITMENTALREADYSTORED = (short) 0x800c;
86+
public static final short SW_INCORRECTSTATETRANSITION = (short) 0x800d;
87+
public static final short SW_FUNCTINNOTALLOWED = (short) 0x800e;
88+
public static final short SW_INVALIDPACKETSTRUCTURE = (short) 0x800d;
89+
public static final short SW_INVALIDQUORUMINDEX = (short) 0x800e;
90+
public static final short SW_INVALIDCOMMITMENTLENGTH = (short) 0x800f;
91+
public static final short SW_INVALIDMESSAGELENGTH = (short) 0x8010;
92+
public static final short SW_INVALIDCOUNTER = (short) 0x8011;
93+
public static final short SW_INCORRECTJCMATHLIBSETTINGS = (short) 0x8012;
94+
95+
96+
public static final short SIGN_COUNTER_LENGTH = (short) 2;
97+
98+
99+
100+
public static final short PACKET_PARAMS_OPCODE_OFFSET = (short) 0;
101+
public static final short PACKET_PARAMS_LENGTH_OFFSET = (short) (PACKET_PARAMS_OPCODE_OFFSET + 1);
102+
public static final short PACKET_PARAMS_CTXINDEX_OFFSET = (short) (PACKET_PARAMS_LENGTH_OFFSET + 2);
103+
104+
// SetupNewQuorum params
105+
public static final short PACKET_PARAMS_SETUPNEWQUORUM_NUMPLAYERS_OFFSET = (short) (PACKET_PARAMS_CTXINDEX_OFFSET + 2);
106+
public static final short PACKET_PARAMS_SETUPNEWQUORUM_THISPLAYERINDEX_OFFSET = (short) (PACKET_PARAMS_SETUPNEWQUORUM_NUMPLAYERS_OFFSET + 2);
107+
// KeyGen_StoreCommitment params
108+
public static final short PACKET_PARAMS_KEYGENSTORECOMMITMENT_PLAYERID_OFFSET = (short) (PACKET_PARAMS_CTXINDEX_OFFSET + 2);
109+
public static final short PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENTLENGTH_OFFSET = (short) (PACKET_PARAMS_KEYGENSTORECOMMITMENT_PLAYERID_OFFSET + 2);
110+
public static final short PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENT_OFFSET = (short) (PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENTLENGTH_OFFSET + 2);
111+
// KeyGen_StorePublicKey params
112+
public static final short PACKET_PARAMS_KEYGENSTOREPUBKEY_PLAYERID_OFFSET = (short) (PACKET_PARAMS_CTXINDEX_OFFSET + 2);
113+
public static final short PACKET_PARAMS_KEYGENSTOREPUBKEY_PUBKEYLENGTH_OFFSET = (short) (PACKET_PARAMS_KEYGENSTOREPUBKEY_PLAYERID_OFFSET + 2);
114+
public static final short PACKET_PARAMS_KEYGENSTOREPUBKEY_PUBKEY_OFFSET = (short) (PACKET_PARAMS_KEYGENSTOREPUBKEY_PUBKEYLENGTH_OFFSET + 2);
115+
// EncryptData params
116+
public static final short PACKET_PARAMS_ENCRYPT_DATALENGTH_OFFSET = (short) (PACKET_PARAMS_CTXINDEX_OFFSET + 2);
117+
public static final short PACKET_PARAMS_ENCRYPT_DATA_OFFSET = (short) (PACKET_PARAMS_ENCRYPT_DATALENGTH_OFFSET + 2);
118+
// DecryptData params
119+
public static final short PACKET_PARAMS_DECRYPT_DATALENGTH_OFFSET = (short) (PACKET_PARAMS_CTXINDEX_OFFSET + 2);
120+
public static final short PACKET_PARAMS_DECRYPT_DATA_OFFSET = (short) (PACKET_PARAMS_DECRYPT_DATALENGTH_OFFSET + 2);
121+
// Sign_RetrieveRandomRi params
122+
public static final short PACKET_PARAMS_SIGNRETRIEVERI_COUNTER_OFFSET = (short) (PACKET_PARAMS_CTXINDEX_OFFSET + 2);
123+
// Sign_RetrieveRandomRi params
124+
public static final short PACKET_PARAMS_SIGN_COUNTER_OFFSET = (short) (PACKET_PARAMS_CTXINDEX_OFFSET + 2);
125+
//public static final short PACKET_PARAMS_SIGN_COUNTER_OFFSET = (short) (PACKET_PARAMS_SIGN_COUNTERLENGTH_OFFSET + 2);
126+
public static final short PACKET_PARAMS_SIGN_DATALENGTH_OFFSET = (short) (PACKET_PARAMS_SIGN_COUNTER_OFFSET + SIGN_COUNTER_LENGTH);
127+
public static final short PACKET_PARAMS_SIGN_DATA_OFFSET = (short) (PACKET_PARAMS_SIGN_DATALENGTH_OFFSET + 2);
128+
129+
// Performance-related debugging response codes
130+
public static final short PERF_DECRYPT = (short) 0x7770;
131+
public static final short PERF_ENCRYPT = (short) 0x6660;
132+
public static final short PERF_SIGN = (short) 0x5550;
133+
134+
// Global applet settings
135+
public static final short MAX_NUM_PLAYERS = (short) 15; // Maximum number of allowed players
136+
137+
public final static boolean COMPUTE_Y_ONTHEFLY = true; // on-the-fly computation of aggregated pulic key is only option
138+
public final static boolean PLAYERS_IN_RAM = true; // if true, player (participant) info is stored in RAM => faster, consuming RAM and will NOT survive card reset
139+
public final static boolean IS_BACKDOORED_EXAMPLE = false; // if true, then applet will not follow protocol but generates backdoored applet instead
140+
141+
142+
// TLV types
143+
public final static byte TLV_TYPE_CARDUNIQUEDID = (byte) 0x40;
144+
public final static byte TLV_TYPE_KEYPAIR_STATE = (byte) 0x41;
145+
public final static byte TLV_TYPE_EPHIMERAL_STATE = (byte) 0x42;
146+
public final static byte TLV_TYPE_MEMORY = (byte) 0x43;
147+
public final static byte TLV_TYPE_COMPILEFLAGS = (byte) 0x44;
148+
public final static byte TLV_TYPE_GITCOMMIT = (byte) 0x45;
149+
public final static byte TLV_TYPE_EXAMPLEBACKDOOR = (byte) 0x46;
150+
public final static byte TLV_TYPE_MPCINPUTPACKET = (byte) 0x47;
151+
public final static byte TLV_TYPE_CARDINDEX = (byte) 0x48;
152+
153+
154+
// Lengths
155+
public static final byte CARD_ID_LONG_LENGTH = (byte) 16; // Length of unique card ID generated during applet install
156+
157+
public static final short BASIC_ECC_LENGTH = (short) 32; // 32 => 256b ECC
158+
public static final short SHARE_BASIC_SIZE = BASIC_ECC_LENGTH;
159+
public static final short SHARE_DOUBLE_SIZE = (short) (2 * SHARE_BASIC_SIZE); // intermediate result of multiplication operation with shares (double bit length)
160+
public static final short SHARE_DOUBLE_SIZE_CARRY = (short) (SHARE_DOUBLE_SIZE + 1); // double intermediate result + 1 byte carry
161+
public static final short PUBKEY_YS_SHARE_SIZE = SHARE_DOUBLE_SIZE_CARRY; // double intermediate result + 1 byte carry
162+
public static final short SECRET_SEED_SIZE = BASIC_ECC_LENGTH;
163+
164+
165+
public static final short MAX_QUORUMS = 1; // Maximum number of separate quorums this card can participate in
166+
167+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package mystlib;
2+
3+
import java.io.FileOutputStream;
4+
import java.util.ArrayList;
5+
import javax.smartcardio.CardChannel;
6+
7+
/**
8+
*
9+
* @author Petr Svenda
10+
*/
11+
public class MPCRunConfig {
12+
int targetReaderIndex = 0;
13+
int numPlayers = 4;
14+
public Class appletToSimulate;
15+
ArrayList<CardProfile> detectedCards;
16+
FileOutputStream perfFile;
17+
public String cardName;
18+
byte[] appletAID = {(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x0a, (byte) 0x4d, (byte) 0x50, (byte) 0x43, (byte) 0x41, (byte) 0x70, (byte) 0x70, (byte) 0x6c, (byte) 0x65, (byte) 0x74, (byte) 0x31};
19+
20+
public enum CARD_TYPE {
21+
PHYSICAL, JCOPSIM, JCARDSIMLOCAL, JCARDSIMREMOTE
22+
}
23+
public CARD_TYPE testCardType = CARD_TYPE.PHYSICAL;
24+
25+
public static MPCRunConfig getDefaultConfig() {
26+
MPCRunConfig runCfg = new MPCRunConfig();
27+
runCfg.targetReaderIndex = 0;
28+
runCfg.numPlayers = 4;
29+
runCfg.testCardType = CARD_TYPE.PHYSICAL;
30+
runCfg.cardName = "unknown";
31+
runCfg.detectedCards = new ArrayList<>();
32+
return runCfg;
33+
}
34+
}
+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package mystlib;
2+
3+
import java.nio.ByteBuffer;
4+
import java.nio.ByteOrder;
5+
import java.util.ArrayList;
6+
import javacard.framework.ISO7816;
7+
import javax.smartcardio.CardChannel;
8+
import javax.smartcardio.CommandAPDU;
9+
import javax.smartcardio.ResponseAPDU;
10+
11+
/**
12+
*
13+
* @author Petr Svenda
14+
*/
15+
public class MystOperations {
16+
public enum CryptoOps {
17+
KEYGEN,
18+
SIGN,
19+
DECRYPT
20+
}
21+
public void Execute(MPCRunConfig runCfg, String inputFile, String outputFile, CryptoOps cryptoOps) throws Exception {
22+
// Connect to all available readers and scan for MPC applets
23+
ArrayList<CardChannel> cardsList = new ArrayList<>();
24+
CardManagement.ConnectAllPhysicalCards(runCfg.appletAID, cardsList);
25+
// Create card contexts, fill cards IDs
26+
for (CardChannel channel : cardsList) {
27+
CardProfile cardProfile = new CardProfile();
28+
cardProfile.channel = channel;
29+
runCfg.detectedCards.add(cardProfile);
30+
}
31+
32+
// Run selected operation and store results
33+
switch (cryptoOps) {
34+
case KEYGEN: {
35+
break;
36+
}
37+
default: {
38+
System.out.println("ERROR: Unknown operation.");
39+
}
40+
}
41+
42+
// TODO: Cleanup
43+
}
44+
45+
void ScanAvailableCards(MPCRunConfig runCfg) {
46+
int numMPCCards = 0;
47+
48+
//CardChannel channel = Connect(runCfg);
49+
System.out.println(" Done.");
50+
51+
52+
//GetCardInfo(channel);
53+
54+
55+
runCfg.numPlayers = numMPCCards; // Number of detected cards
56+
}
57+
58+
private static boolean GetCardInfo(CardChannel channel, CardProfile cardProfile) throws Exception {
59+
CommandAPDU cmd = new CommandAPDU(Consts.CLA_MPC, Consts.INS_PERSONALIZE_GETCARDINFO, 0, 0);
60+
ResponseAPDU response = CardManagement.transmit(channel, cmd);
61+
62+
// Parse response
63+
if (response.getSW() == (ISO7816.SW_NO_ERROR & 0xffff)) {
64+
int offset = 0;
65+
byte[] data = response.getData();
66+
System.out.println("---CARD STATE -------");
67+
assert (data[offset] == Consts.TLV_TYPE_CARDUNIQUEDID);
68+
offset++;
69+
short len = Util.getShort(data, offset);
70+
offset += 2;
71+
System.out.println(String.format("CardIDLong:\t\t\t %s", Util.toHex(data, offset, len)));
72+
offset += len;
73+
74+
assert (data[offset] == Consts.TLV_TYPE_KEYPAIR_STATE);
75+
offset++;
76+
assert (Util.getShort(data, offset) == 2);
77+
offset += 2;
78+
System.out.println(String.format("KeyPair state:\t\t\t %d", Util.getShort(data, offset)));
79+
offset += 2;
80+
assert (data[offset] == Consts.TLV_TYPE_EPHIMERAL_STATE);
81+
offset++;
82+
assert (Util.getShort(data, offset) == 2);
83+
offset += 2;
84+
System.out.println(String.format("EphiKey state:\t\t\t %d", Util.getShort(data, offset)));
85+
offset += 2;
86+
87+
assert (data[offset] == Consts.TLV_TYPE_MEMORY);
88+
offset++;
89+
assert (Util.getShort(data, offset) == 6);
90+
offset += 2;
91+
System.out.println(String.format("MEMORY_PERSISTENT:\t\t %d bytes", Util.getShort(data, offset)));
92+
offset += 2;
93+
System.out.println(String.format("MEMORY_TRANSIENT_RESET:\t\t %d bytes", Util.getShort(data, offset)));
94+
offset += 2;
95+
System.out.println(String.format("MEMORY_TRANSIENT_DESELECT:\t %d bytes", Util.getShort(data, offset)));
96+
offset += 2;
97+
System.out.println("-----------------");
98+
99+
assert (data[offset] == Consts.TLV_TYPE_COMPILEFLAGS);
100+
offset++;
101+
assert (Util.getShort(data, offset) == 4);
102+
offset += 2;
103+
System.out.println(String.format("Consts.MAX_N_PLAYERS:\t\t %d", Util.getShort(data, offset)));
104+
offset += 2;
105+
System.out.println(String.format("DKG.PLAYERS_IN_RAM:\t\t %b", (data[offset] == 0) ? false : true));
106+
offset++;
107+
System.out.println(String.format("DKG.COMPUTE_Y_ONTHEFLY:\t\t %b ", (data[offset] == 0) ? false : true));
108+
offset++;
109+
System.out.println("-----------------");
110+
111+
assert (data[offset] == Consts.TLV_TYPE_GITCOMMIT);
112+
offset++;
113+
len = Util.getShort(data, offset);
114+
assert (len == 4);
115+
offset += 2;
116+
System.out.println(String.format("Git commit tag:\t\t\t 0x%s", Util.toHex(data, offset, len)));
117+
offset += len;
118+
System.out.println("-----------------");
119+
120+
assert (data[offset] == Consts.TLV_TYPE_EXAMPLEBACKDOOR);
121+
offset++;
122+
len = Util.getShort(data, offset);
123+
assert (len == 1);
124+
offset += 2;
125+
if (data[offset] == (byte) 0) {
126+
System.out.println("Applet is in normal (non-backdoored) state");
127+
} else {
128+
System.out.println("WARNING: Applet is in example 'backdoored' state with fixed private key");
129+
}
130+
offset += len;
131+
132+
System.out.println("-----------------");
133+
}
134+
135+
return CardManagement.checkSW(response);
136+
}
137+
138+
}
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package mystlib;
2+
3+
import javax.smartcardio.ATR;
4+
import javax.smartcardio.Card;
5+
import javax.smartcardio.CardChannel;
6+
import javax.smartcardio.CardException;
7+
8+
/**
9+
*
10+
* @author Petr Svenda
11+
*/
12+
public class SimulatedCard extends Card {
13+
14+
@Override
15+
public ATR getATR() {
16+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
17+
}
18+
19+
@Override
20+
public String getProtocol() {
21+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
22+
}
23+
24+
@Override
25+
public CardChannel getBasicChannel() {
26+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
27+
}
28+
29+
@Override
30+
public CardChannel openLogicalChannel() throws CardException {
31+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
32+
}
33+
34+
@Override
35+
public void beginExclusive() throws CardException {
36+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
37+
}
38+
39+
@Override
40+
public void endExclusive() throws CardException {
41+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
42+
}
43+
44+
@Override
45+
public byte[] transmitControlCommand(int i, byte[] bytes) throws CardException {
46+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
47+
}
48+
49+
@Override
50+
public void disconnect(boolean bln) throws CardException {
51+
// do nothing
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package mystlib;
2+
3+
import com.licel.jcardsim.io.JavaxSmartCardInterface;
4+
import java.nio.ByteBuffer;
5+
import javacard.framework.AID;
6+
import javax.smartcardio.ATR;
7+
import javax.smartcardio.Card;
8+
import javax.smartcardio.CardChannel;
9+
import javax.smartcardio.CardException;
10+
import javax.smartcardio.CommandAPDU;
11+
import javax.smartcardio.ResponseAPDU;
12+
13+
/**
14+
*
15+
* @author Petr Svenda
16+
*/
17+
public class SimulatedCardChannelLocal extends CardChannel {
18+
JavaxSmartCardInterface m_simulator;
19+
SimulatedCard m_card;
20+
AID m_appletAID;
21+
22+
SimulatedCardChannelLocal (JavaxSmartCardInterface simulator, AID appletAIDRes) {
23+
m_simulator = simulator;
24+
m_card = new SimulatedCard();
25+
m_appletAID = appletAIDRes;
26+
}
27+
28+
@Override
29+
public Card getCard() {
30+
return m_card;
31+
}
32+
33+
@Override
34+
public int getChannelNumber() {
35+
return 0;
36+
}
37+
38+
@Override
39+
public ResponseAPDU transmit(CommandAPDU apdu) throws CardException {
40+
ResponseAPDU responseAPDU = null;
41+
42+
try {
43+
responseAPDU = this.m_simulator.transmitCommand(apdu);
44+
// Add delay corresponding to real cards
45+
//int delay = OperationTimes.getCardOperationDelay(apdu);
46+
//Thread.sleep(delay);
47+
} catch (Exception ex) {
48+
ex.printStackTrace();
49+
}
50+
51+
return responseAPDU;
52+
}
53+
54+
@Override
55+
public int transmit(ByteBuffer bb, ByteBuffer bb1) throws CardException {
56+
throw new UnsupportedOperationException("Not supported yet.");
57+
}
58+
59+
@Override
60+
public void close() throws CardException {
61+
m_simulator.reset();
62+
m_simulator.deleteApplet(m_appletAID);
63+
}
64+
}
+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package mystlib;
2+
3+
import java.math.BigInteger;
4+
import java.security.MessageDigest;
5+
import java.security.NoSuchAlgorithmException;
6+
import java.security.SecureRandom;
7+
8+
import org.bouncycastle.math.ec.ECPoint;
9+
10+
import ds.ov2.bignat.Bignat;
11+
12+
/**
13+
*
14+
* @author Vasilios Mavroudis and Petr Svenda
15+
*/
16+
class SimulatedPlayer {
17+
18+
public short playerID;
19+
20+
//Key Pair
21+
public BigInteger priv_key_BI;
22+
public ECPoint pub_key_EC;
23+
public byte[] pub_key_Hash;
24+
25+
//Signing
26+
public byte[] secret_seed = new byte[32];//{ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
27+
public BigInteger k_Bn;
28+
public ECPoint Ri_EC;
29+
public byte[] Ri_Hash;
30+
31+
//For preloading
32+
public BigInteger k_Bn_pre;
33+
public ECPoint Ri_EC_pre;
34+
public byte[] Ri_Hash_pre;
35+
36+
public static ECPoint G;
37+
public static BigInteger n;
38+
39+
public SimulatedPlayer(short playerID) throws NoSuchAlgorithmException {
40+
this.playerID = playerID;
41+
this.KeyGen();
42+
SecureRandom random = new SecureRandom();
43+
byte[] secret_seed = new byte[32];
44+
random.nextBytes(secret_seed);
45+
46+
}
47+
48+
public final void SetPrivKey(BigInteger privkey) {
49+
priv_key_BI = privkey;
50+
pub_key_EC = G.multiply(priv_key_BI);
51+
}
52+
53+
public final void KeyGen() throws NoSuchAlgorithmException {
54+
// Keypair + hash
55+
SecureRandom rnd = new SecureRandom();
56+
priv_key_BI = new BigInteger(256, rnd);
57+
/*
58+
if (MPCTestClient._FIXED_PLAYERS_RNG) {
59+
System.out.println("WARNING: _FIXED_PLAYERS_RNG == true");
60+
// If true, don't generate random key, but use fixed one instead
61+
priv_key_BI = new BigInteger("B346675518084623BC111CC53FF615B152A3F6D1585278370FA1BA0EA160237E".getBytes());
62+
}
63+
*/
64+
pub_key_EC = G.multiply(priv_key_BI);
65+
MessageDigest md = MessageDigest.getInstance("SHA-256");
66+
md.update(pub_key_EC.getEncoded(false));
67+
pub_key_Hash = md.digest();
68+
}
69+
70+
/*
71+
public void Gen_Ri() throws NoSuchAlgorithmException{
72+
// Temp r for signing + hash
73+
SecureRandom rnd = new SecureRandom();
74+
k_Bn = new BigInteger(256, rnd);
75+
Ri_EC = G.multiply(k_Bn);
76+
MessageDigest md = MessageDigest.getInstance("SHA-256");
77+
md.reset();
78+
md.update(Ri_EC.getEncoded(false));
79+
Ri_Hash = md.digest();
80+
81+
//For preloading
82+
k_Bn_pre = new BigInteger(256, rnd);
83+
Ri_EC_pre = G.multiply(k_Bn_pre);
84+
md.reset();
85+
md.update(Ri_EC_pre.getEncoded(false));
86+
Ri_Hash_pre = md.digest();
87+
}*/
88+
/*
89+
public void Gen_next_Ri() throws NoSuchAlgorithmException{
90+
//Previously preloaded pair is now the current one
91+
k_Bn = k_Bn_pre;
92+
Ri_EC = Ri_EC_pre;
93+
Ri_Hash = Ri_Hash_pre;
94+
95+
//For preloading
96+
SecureRandom rnd = new SecureRandom();
97+
k_Bn_pre = new BigInteger(256, rnd);
98+
Ri_EC_pre = G.multiply(k_Bn_pre);
99+
MessageDigest md = MessageDigest.getInstance("SHA-256");
100+
md.reset();
101+
md.update(Ri_EC_pre.getEncoded(false));
102+
Ri_Hash_pre = md.digest();
103+
}
104+
*/
105+
public BigInteger Sign(Bignat i, ECPoint R_EC, byte[] plaintext) throws NoSuchAlgorithmException {
106+
//Gen e (e will be the same in all signature shares)
107+
MessageDigest md = MessageDigest.getInstance("SHA-256");
108+
//System.out.println("Simulated: Plaintext:" + client.bytesToHex(plaintext));
109+
//System.out.println("Simulated: Ri,n: " + client.bytesToHex(R_EC.getEncoded(false)));
110+
md.update(plaintext);
111+
md.update(R_EC.getEncoded(false)); // R_EC is the sum of the r_i's
112+
byte[] e = md.digest();
113+
BigInteger e_BI = new BigInteger(1, e);
114+
115+
//Gen s_i
116+
this.k_Bn = new BigInteger(PRF(i, secret_seed));
117+
118+
BigInteger s_i_BI = this.k_Bn.subtract(e_BI.multiply(this.priv_key_BI));
119+
s_i_BI = s_i_BI.mod(n);
120+
121+
/*I'm cheating a bit here, and use the e returned by the JC.
122+
Btw e is always the same, so it can actually be computed
123+
on the host if this helps with optimizing the applet */
124+
//System.out.println("Simulated: s: " + client.bytesToHex(s_i_BI.toByteArray()));
125+
//System.out.println("Simulated: e: " + client.bytesToHex(e) + "\n");
126+
return s_i_BI;
127+
}
128+
129+
public byte[] Gen_Rin(Bignat i) throws NoSuchAlgorithmException {
130+
ECPoint Rin = G.multiply(new BigInteger(PRF(i, this.secret_seed)));
131+
return Rin.getEncoded(false);
132+
}
133+
134+
public byte[] Gen_Rin(Bignat i, byte[] seed) throws NoSuchAlgorithmException {
135+
ECPoint Rin = G.multiply(new BigInteger(PRF(i, seed)));
136+
return Rin.getEncoded(false);
137+
}
138+
139+
public byte[] PRF(Bignat i, byte[] seed) throws NoSuchAlgorithmException {
140+
MessageDigest md = MessageDigest.getInstance("SHA-256");
141+
md.reset();
142+
md.update(i.as_byte_array());
143+
md.update(seed);
144+
return md.digest();
145+
}
146+
147+
}

‎MPCShared/src/mystlib/Util.java

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package mystlib;
2+
3+
import java.math.BigInteger;
4+
import java.nio.ByteBuffer;
5+
import java.nio.ByteOrder;
6+
import java.security.KeyPair;
7+
import java.security.KeyPairGenerator;
8+
import java.security.Security;
9+
import javacard.framework.ISO7816;
10+
import javax.smartcardio.ResponseAPDU;
11+
import org.bouncycastle.jce.ECNamedCurveTable;
12+
import org.bouncycastle.jce.interfaces.ECPublicKey;
13+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
14+
import org.bouncycastle.jce.spec.ECParameterSpec;
15+
import org.bouncycastle.math.ec.ECPoint;
16+
17+
/**
18+
*
19+
* @author Vasilios Mavroudis and Petr Svenda
20+
*/
21+
public class Util {
22+
23+
public static String toHex(byte[] bytes) {
24+
return toHex(bytes, 0, bytes.length);
25+
}
26+
27+
public static String toHex(byte[] bytes, int offset, int len) {
28+
// StringBuilder buff = new StringBuilder();
29+
String result = "";
30+
31+
for (int i = offset; i < offset + len; i++) {
32+
result += String.format("%02X", bytes[i]);
33+
}
34+
35+
return result;
36+
}
37+
38+
public static String bytesToHex(byte[] bytes) {
39+
char[] hexArray = "0123456789ABCDEF".toCharArray();
40+
char[] hexChars = new char[bytes.length * 2];
41+
for (int j = 0; j < bytes.length; j++) {
42+
int v = bytes[j] & 0xFF;
43+
hexChars[j * 2] = hexArray[v >>> 4];
44+
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
45+
}
46+
return new String(hexChars);
47+
}
48+
49+
50+
/* Utils */
51+
public static short getShort(byte[] buffer, int offset) {
52+
return ByteBuffer.wrap(buffer, offset, 2).order(ByteOrder.BIG_ENDIAN).getShort();
53+
}
54+
55+
public static short readShort(byte[] data, int offset) {
56+
return (short) (((data[offset] << 8)) | ((data[offset + 1] & 0xff)));
57+
}
58+
59+
public static byte[] shortToByteArray(int s) {
60+
return new byte[]{(byte) ((s & 0xFF00) >> 8), (byte) (s & 0x00FF)};
61+
}
62+
63+
64+
public static byte[] joinArray(byte[]... arrays) {
65+
int length = 0;
66+
for (byte[] array : arrays) {
67+
length += array.length;
68+
}
69+
70+
final byte[] result = new byte[length];
71+
72+
int offset = 0;
73+
for (byte[] array : arrays) {
74+
System.arraycopy(array, 0, result, offset, array.length);
75+
offset += array.length;
76+
}
77+
78+
return result;
79+
}
80+
81+
public static byte[] trimLeadingZeroes(byte[] array) {
82+
short startOffset = 0;
83+
for (int i = 0; i < array.length; i++) {
84+
if (array[i] != 0) {
85+
break;
86+
} else {
87+
// still zero
88+
startOffset++;
89+
}
90+
}
91+
92+
byte[] result = new byte[array.length - startOffset];
93+
System.arraycopy(array, startOffset, result, 0, array.length - startOffset);
94+
return result;
95+
}
96+
97+
public static byte[] concat(byte[] a, byte[] b) {
98+
int aLen = a.length;
99+
int bLen = b.length;
100+
byte[] c = new byte[aLen + bLen];
101+
System.arraycopy(a, 0, c, 0, aLen);
102+
System.arraycopy(b, 0, c, aLen, bLen);
103+
return c;
104+
}
105+
106+
public static byte[] concat(byte[] a, byte[] b, byte[] c) {
107+
byte[] tmp_conc = concat(a, b);
108+
return concat(tmp_conc, c);
109+
110+
}
111+
112+
113+
public static ECPoint randECPoint() throws Exception {
114+
Security.addProvider(new BouncyCastleProvider());
115+
116+
ECParameterSpec ecSpec_named = ECNamedCurveTable.getParameterSpec("secp256r1"); // NIST P-256
117+
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");
118+
kpg.initialize(ecSpec_named);
119+
KeyPair apair = kpg.generateKeyPair();
120+
ECPublicKey apub = (ECPublicKey) apair.getPublic();
121+
return apub.getQ();
122+
}
123+
124+
public static byte[] IntToBytes(int val) {
125+
byte[] data = new byte[5];
126+
if (val < 0) {
127+
data[0] = 0x01;
128+
} else {
129+
data[0] = 0x00;
130+
}
131+
132+
int unsigned = Math.abs(val);
133+
data[1] = (byte) (unsigned >>> 24);
134+
data[2] = (byte) (unsigned >>> 16);
135+
data[3] = (byte) (unsigned >>> 8);
136+
data[4] = (byte) unsigned;
137+
138+
return data;
139+
}
140+
141+
public static int BytesToInt(byte[] data) {
142+
int val = (data[1] << 24)
143+
| ((data[2] & 0xFF) << 16)
144+
| ((data[3] & 0xFF) << 8)
145+
| (data[4] & 0xFF);
146+
147+
if (data[0] == 0x01) {
148+
val = val * -1;
149+
}
150+
151+
return val;
152+
}
153+
154+
private static boolean checkSW(ResponseAPDU response) {
155+
if (response.getSW() != (ISO7816.SW_NO_ERROR & 0xffff)) {
156+
System.err.printf("Received error status: %02X.\n",
157+
response.getSW());
158+
return false;
159+
}
160+
return true;
161+
}
162+
163+
public static byte[] hexStringToByteArray(String s) {
164+
String sanitized = s.replace(" ", "");
165+
byte[] b = new byte[sanitized.length() / 2];
166+
for (int i = 0; i < b.length; i++) {
167+
int index = i * 2;
168+
int v = Integer.parseInt(sanitized.substring(index, index + 2), 16);
169+
b[i] = (byte) v;
170+
}
171+
return b;
172+
}
173+
}

‎MystHost/src/mysthost/MPCRunConfig.java

-40
This file was deleted.

‎MystHost/src/mysthost/MystHost.java

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package mysthost;
22

33
import java.io.IOException;
4+
import mystlib.MPCRunConfig;
5+
import mystlib.MystOperations;
46
import org.apache.commons.cli.*;
57

68
/**
@@ -30,22 +32,28 @@ private void run(String[] args) {
3032
return;
3133
}
3234

33-
if (cli.hasOption("sign")) {
34-
MystOperation operation = new MystOperation();
35+
MystOperations operation = new MystOperations();
36+
37+
String inputFilePath = cli.getOptionValue("input_file", "input.bin");
38+
String outputFilePath = cli.getOptionValue("output_file", "output.bin");
3539

36-
String inputFilePath = cli.getOptionValue("inputFile", "input.bin");
37-
String outputFilePath = cli.getOptionValue("outnputFile", "input.bin");
40+
MPCRunConfig runCfg = MPCRunConfig.getDefaultConfig();
41+
runCfg.testCardType = MPCRunConfig.CARD_TYPE.PHYSICAL;
3842

39-
MPCRunConfig runCfg = MPCRunConfig.getDefaultConfig();
40-
runCfg.testCardType = MPCRunConfig.CARD_TYPE.PHYSICAL;
41-
runCfg.numPlayers = 4; // TODO: Number of detected cards
42-
operation.execute(runCfg, inputFilePath, outputFilePath);
43+
if (cli.hasOption("keygen")) {
44+
operation.Execute(runCfg, inputFilePath, outputFilePath, MystOperations.CryptoOps.KEYGEN);
45+
}
46+
if (cli.hasOption("sign")) {
47+
operation.Execute(runCfg, inputFilePath, outputFilePath, MystOperations.CryptoOps.SIGN);
48+
}
49+
if (cli.hasOption("decrypt")) {
50+
operation.Execute(runCfg, inputFilePath, outputFilePath, MystOperations.CryptoOps.DECRYPT);
4351
}
4452
} catch (MissingArgumentException maex) {
4553
System.err.println("Option, " + maex.getOption().getOpt() + " requires an argument: " + maex.getOption().getArgName());
4654
} catch (NumberFormatException nfex) {
4755
System.err.println("Not a number. " + nfex.getMessage());
48-
} catch (ParseException | IOException ex) {
56+
} catch (ParseException /*| IOException*/ ex) {
4957
System.err.println(ex.getMessage());
5058
} finally {
5159
}
@@ -60,25 +68,17 @@ private void run(String[] args) {
6068
* parsing the command line tokens
6169
*/
6270
private CommandLine parseArgs(String[] args) throws ParseException {
63-
/*
64-
* Actions:
65-
* -st / --setTraps
66-
*
67-
* Options:
68-
* -bd / --baseDir [base_directory]
69-
* -mbd / --methodBaseName [name]
70-
* -tsc / --trapIDStartConst [start_constant] <b>
71-
*
72-
*/
7371
OptionGroup actions = new OptionGroup();
7472
actions.setRequired(true);
7573
actions.addOption(Option.builder("h").longOpt("help").desc("Print help.").build());
76-
actions.addOption(Option.builder("st").longOpt("setTraps").desc("Parse input source code files, search for template performance traps and generates both card-side and client-side files for performance profiling.").build());
74+
actions.addOption(Option.builder("g").longOpt("keygen").desc("Generate new distributed keypair").build());
75+
actions.addOption(Option.builder("s").longOpt("sign").desc("Sign data read from input file.").build());
76+
actions.addOption(Option.builder("d").longOpt("decrypt").desc("Decrypt data read from input file.").build());
77+
actions.addOption(Option.builder("e").longOpt("encrypt").desc("Encrypt data read from input file.").build());
7778
opts.addOptionGroup(actions);
7879

79-
opts.addOption(Option.builder("tsc").longOpt("trapIDStartConst").desc("Initial start value (short) for trapID constants.").hasArg().argName("start_constant").build());
80-
opts.addOption(Option.builder("bd").longOpt("baseDir").desc("Base directory with template files").hasArg().argName("base_directory").required(true).build());
81-
opts.addOption(Option.builder("mbd").longOpt("methodBaseName").desc("Base name of method to be profiled.").hasArg().argName("name").required(true).build());
80+
opts.addOption(Option.builder("in").longOpt("inputFile").desc("Input file for operation.").hasArg().argName("input_file").build());
81+
opts.addOption(Option.builder("out").longOpt("outputFile").desc("Output file for operation.").hasArg().argName("output_file").build());
8282

8383
CommandLineParser parser = new DefaultParser();
8484
return parser.parse(opts, args);
@@ -90,6 +90,6 @@ private CommandLine parseArgs(String[] args) throws ParseException {
9090
private void help() {
9191
HelpFormatter help = new HelpFormatter();
9292
help.setOptionComparator(null);
93-
help.printHelp("ECTester.jar", CLI_HEADER, opts, CLI_FOOTER, true);
93+
help.printHelp("MystHost.jar", CLI_HEADER, opts, CLI_FOOTER, true);
9494
}
9595
}

0 commit comments

Comments
 (0)
Please sign in to comment.