Skip to content

Commit 12fcb37

Browse files
committedSep 4, 2017
move of VerifyKeyPair where it belongs
1 parent 8e74070 commit 12fcb37

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed
 

‎MPCApplet/src/mpc/MPCCryptoOperations.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class MPCCryptoOperations {
4747
Bignat p_Bn = null;
4848

4949
byte[] m_shortByteArray = null; // used to return short represenated as array of 2 bytes
50-
50+
byte[] tmp_arr = null; // TODO: used as array for temporary result -> move to resource manager
51+
5152

5253
static final short SHIFT_BYTES_AAPROX = Consts.SHARE_DOUBLE_SIZE_CARRY;
5354
static short res2Len = (short) ((short) 97 - SHIFT_BYTES_AAPROX);
@@ -99,7 +100,8 @@ public class MPCCryptoOperations {
99100

100101
public MPCCryptoOperations(ECConfig eccfg) {
101102
temp_sign_counter = new Bignat((short) 2, JCSystem.MEMORY_TYPE_TRANSIENT_RESET, eccfg.bnh);
102-
103+
tmp_arr = JCSystem.makeTransientByteArray(Consts.SHARE_DOUBLE_SIZE_CARRY, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
104+
103105
placeholder = ECPointBuilder.createPoint(SecP256r1.KEY_LENGTH);
104106
placeholder.initializeECPoint_SecP256r1();
105107

@@ -510,4 +512,16 @@ public byte[] shortToByteArray(short s) {
510512
return m_shortByteArray;
511513
}
512514

515+
public boolean VerifyPair(byte[] Ys, short YsOffset, short YsLength, byte[] hash) {
516+
md.reset();
517+
md.doFinal(Ys, YsOffset, YsLength, tmp_arr, (short) 0);
518+
if (Util.arrayCompare(tmp_arr, (short) 0, hash,
519+
(short) 0, Consts.SHARE_BASIC_SIZE) != 0) {
520+
return false;
521+
} else {
522+
return true;
523+
}
524+
}
525+
526+
513527
}

‎MPCApplet/src/mpc/QuorumContext.java

+4-24
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class Player {
3636
//private byte[] privbytes = {(byte)0xB3, (byte)0x46, (byte)0x67, (byte)0x55, (byte)0x18, (byte)0x08, (byte)0x46, (byte)0x23, (byte)0xBC, (byte)0x11, (byte)0x1C, (byte)0xC5, (byte)0x3F, (byte)0xF6, (byte)0x15, (byte)0xB1, (byte)0x52, (byte)0xA3, (byte)0xF6, (byte)0xD1, (byte)0x58, (byte)0x52, (byte)0x78, (byte)0x37, (byte)0x0F, (byte)0xA1, (byte)0xBA, (byte)0x0E, (byte)0xA1, (byte)0x60, (byte)0x23, (byte)0x7E};
3737
public final byte[] privbytes_backdoored = {(byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55};
3838

39-
byte[] tmp_arr = null; // TODO: used as array for temporary result -> move to resource manager
40-
41-
4239
ECCurve theCurve = null;
4340
private KeyPair pair = null;
4441
private byte[] x_i_Bn = null; // share xi , which is a randomly sampled element from Zn
@@ -67,7 +64,6 @@ public QuorumContext(ECConfig eccfg, ECCurve curve, MPCCryptoOperations cryptoOp
6764

6865
this.pair = theCurve.newKeyPair(this.pair);
6966
x_i_Bn = JCSystem.makeTransientByteArray(Consts.SHARE_BASIC_SIZE, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
70-
tmp_arr = JCSystem.makeTransientByteArray(Consts.SHARE_DOUBLE_SIZE_CARRY, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
7167

7268
///////////
7369
//Arrays//
@@ -130,8 +126,8 @@ public final void Reset(short numPlayers, short cardID, boolean bPrepareDecrypti
130126
((ECPrivateKey) pair.getPrivate()).getS(x_i_Bn, (short) 0);
131127
// Compute and set corresponding public key (to backdoored private one)
132128
//CryptoOperations.placeholder.ScalarMultiplication(SecP256r1.G, (short) 0, (short) SecP256r1.G.length, privbytes_backdoored, tmp_arr);
133-
cryptoOps.placeholder.ScalarMultiplication(cryptoOps.GenPoint, privbytes_backdoored, tmp_arr);
134-
pub.setW(tmp_arr, (short) 0, (short) 65);
129+
cryptoOps.placeholder.ScalarMultiplication(cryptoOps.GenPoint, privbytes_backdoored, cryptoOps.tmp_arr);
130+
pub.setW(cryptoOps.tmp_arr, (short) 0, (short) 65);
135131
} else {
136132
// Legitimate generation of key as per protocol by non-compromised participants
137133
((ECPrivateKey) pair.getPrivate()).getS(x_i_Bn, (short) 0);
@@ -185,7 +181,7 @@ public void SetYs(short id, byte[] Y, short YOffset, short YLength) {
185181
if (!players[id].bHashValid) {
186182
ISOException.throwIt(Consts.SW_INVALIDHASH);
187183
}
188-
if (!VerifyPair(Y, YOffset, YLength, players[id].hash)) {
184+
if (!cryptoOps.VerifyPair(Y, YOffset, YLength, players[id].hash)) {
189185
ISOException.throwIt(Consts.SW_INVALIDHASH);
190186
}
191187

@@ -265,7 +261,7 @@ public ECPointBase GetY() {
265261
// State -1
266262
public void Invalidate(boolean bEraseAllArrays) {
267263
if (bEraseAllArrays) {
268-
Util.arrayFillNonAtomic(tmp_arr, (short) 0, (short) tmp_arr.length, (byte) 0);
264+
Util.arrayFillNonAtomic(cryptoOps.tmp_arr, (short) 0, (short) cryptoOps.tmp_arr.length, (byte) 0);
269265
Util.arrayFillNonAtomic(x_i_Bn, (short) 0, (short) x_i_Bn.length, (byte) 0);
270266
}
271267
// Invalidate all items
@@ -281,20 +277,4 @@ public void Invalidate(boolean bEraseAllArrays) {
281277
Y_EC_onTheFly_shares_count = 0;
282278
}
283279

284-
// State -1
285-
// /////////////////////////
286-
// Helper Functions
287-
// ////////////////////////
288-
289-
private boolean VerifyPair(byte[] Ys, short YsOffset, short YsLength, byte[] hash) {
290-
cryptoOps.md.reset();
291-
cryptoOps.md.doFinal(Ys, YsOffset, YsLength, tmp_arr, (short) 0);
292-
if (Util.arrayCompare(tmp_arr, (short) 0, hash,
293-
(short) 0, Consts.SHARE_BASIC_SIZE) != 0) {
294-
return false;
295-
} else {
296-
return true;
297-
}
298-
}
299-
300280
}

0 commit comments

Comments
 (0)
Please sign in to comment.