diff options
| author | J08nY | 2017-03-24 17:11:44 +0100 |
|---|---|---|
| committer | J08nY | 2017-03-24 17:11:44 +0100 |
| commit | a50b554fbc577df6873705738b379fa15980d2b7 (patch) | |
| tree | 68f5fcaa4eec1ceabcc40d5a1fc63eecb052a419 /src/cz/crcs/ectester/applet | |
| parent | dd0947b2dd33baa882279a50876806cc1f0471c4 (diff) | |
| download | ECTester-a50b554fbc577df6873705738b379fa15980d2b7.tar.gz ECTester-a50b554fbc577df6873705738b379fa15980d2b7.tar.zst ECTester-a50b554fbc577df6873705738b379fa15980d2b7.zip | |
Implemented ECDHC testing.
- also some work on ECDH/ECDHC compatibility testing
- new option -dhc / --ecdhc [count] the same as ecdh option,
except it does ECDHC algo
Diffstat (limited to 'src/cz/crcs/ectester/applet')
| -rw-r--r-- | src/cz/crcs/ectester/applet/ECKeyTester.java | 3 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/applet/ECTesterApplet.java | 23 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/applet/EC_Consts.java | 21 |
3 files changed, 35 insertions, 12 deletions
diff --git a/src/cz/crcs/ectester/applet/ECKeyTester.java b/src/cz/crcs/ectester/applet/ECKeyTester.java index 89fd617..057d357 100644 --- a/src/cz/crcs/ectester/applet/ECKeyTester.java +++ b/src/cz/crcs/ectester/applet/ECKeyTester.java @@ -93,8 +93,7 @@ public class ECKeyTester { * @param outputBuffer * @param outputOffset * @param corruption - * @return ISO7816.SW_NO_ERROR on correct operation, - * exception reason otherwise + * @return derived secret length */ public short testECDHC(ECPrivateKey privateKey, ECPublicKey publicKey, byte[] pubkeyBuffer, short pubkeyOffset, byte[] outputBuffer, short outputOffset, byte corruption) { short length = publicKey.getW(pubkeyBuffer, pubkeyOffset); diff --git a/src/cz/crcs/ectester/applet/ECTesterApplet.java b/src/cz/crcs/ectester/applet/ECTesterApplet.java index 4dafd21..e17d102 100644 --- a/src/cz/crcs/ectester/applet/ECTesterApplet.java +++ b/src/cz/crcs/ectester/applet/ECTesterApplet.java @@ -329,6 +329,7 @@ public class ECTesterApplet extends Applet { * P2 = byte privkey (KEYPAIR_*) * DATA = byte export (EXPORT_TRUE || EXPORT_FALSE) * byte corruption (00 = valid, !00 = invalid) + * byte type (EC_Consts.KA_* | ...) */ private void insECDH(APDU apdu) { apdu.setIncomingAndReceive(); @@ -338,8 +339,9 @@ public class ECTesterApplet extends Applet { byte privkey = apdubuf[ISO7816.OFFSET_P2]; byte export = apdubuf[ISO7816.OFFSET_CDATA]; byte corruption = apdubuf[(short) (ISO7816.OFFSET_CDATA + 1)]; + byte type = apdubuf[(short) (ISO7816.OFFSET_CDATA + 2)]; - short len = ecdh(pubkey, privkey, export, corruption, apdubuf, (short) 0); + short len = ecdh(pubkey, privkey, export, corruption, type, apdubuf, (short) 0); apdu.setOutgoingAndSend((short) 0, len); } @@ -513,17 +515,31 @@ public class ECTesterApplet extends Applet { * @param privkey keyPair to use for private key, (KEYPAIR_LOCAL || KEYPAIR_REMOTE) * @param export whether to export ECDH secret * @param corruption whether to invalidate the pubkey before ECDH + * @param type * @param buffer buffer to write sw to, and export ECDH secret {@code if(export == EXPORT_TRUE)} * @param offset output offset in buffer * @return length of data written to the buffer */ - private short ecdh(byte pubkey, byte privkey, byte export, byte corruption, byte[] buffer, short offset) { + private short ecdh(byte pubkey, byte privkey, byte export, byte corruption, byte type, byte[] buffer, short offset) { short length = 0; KeyPair pub = ((pubkey & KEYPAIR_LOCAL) != 0) ? localKeypair : remoteKeypair; KeyPair priv = ((privkey & KEYPAIR_LOCAL) != 0) ? localKeypair : remoteKeypair; - short secretLength = keyTester.testECDH((ECPrivateKey) priv.getPrivate(), (ECPublicKey) pub.getPublic(), ramArray, (short) 0, ramArray2, (short) 0, corruption); + short secretLength = 0; + switch (type) { + case EC_Consts.KA_ECDH: + secretLength = keyTester.testECDH((ECPrivateKey) priv.getPrivate(), (ECPublicKey) pub.getPublic(), ramArray, (short) 0, ramArray2, (short) 0, corruption); + break; + case EC_Consts.KA_ECDHC: + secretLength = keyTester.testECDHC((ECPrivateKey) priv.getPrivate(), (ECPublicKey) pub.getPublic(), ramArray, (short) 0, ramArray2, (short) 0, corruption); + break; + case EC_Consts.KA_BOTH: + // TODO + break; + default: + ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); + } Util.setShort(buffer, offset, keyTester.getSW()); length += 2; @@ -574,7 +590,6 @@ public class ECTesterApplet extends Applet { } /** - * * @param buffer * @param offset * @return diff --git a/src/cz/crcs/ectester/applet/EC_Consts.java b/src/cz/crcs/ectester/applet/EC_Consts.java index 64f8dca..cac5d79 100644 --- a/src/cz/crcs/ectester/applet/EC_Consts.java +++ b/src/cz/crcs/ectester/applet/EC_Consts.java @@ -26,7 +26,7 @@ public class EC_Consts { private static byte[] EC_F2M_F2M = null; //[short i1, short i2, short i3], f = x^m + x^i1 + x^i2 + x^i3 + 1 - + // EC domain parameter identifiers (bit flags) public static final short PARAMETER_FP = 0x0001; public static final short PARAMETER_F2M = 0x0002; @@ -53,10 +53,18 @@ public class EC_Consts { public static final short PARAMETERS_KEYPAIR = 0x0180; public static final short PARAMETERS_ALL = 0x01ff; + + // EC key identifiers public static final byte KEY_PUBLIC = 0x01; public static final byte KEY_PRIVATE = 0x02; public static final byte KEY_BOTH = KEY_PUBLIC | KEY_PRIVATE; + + // Key Agreement test identifiers + public static final byte KA_ECDH = 0x01; + public static final byte KA_ECDHC = 0x02; + public static final byte KA_BOTH = KA_ECDH | KA_ECDHC; + public static RandomData randomData = null; @@ -1298,21 +1306,22 @@ public class EC_Consts { size += xLength; short offset = outputOffset; + outputBuffer[offset] = 0; switch (form) { case X962_UNCOMPRESSED: - outputBuffer[offset] = 0x04; + outputBuffer[offset] = 4; break; + case X962_HYBRID: + outputBuffer[offset] = 4; case X962_COMPRESSED: byte yLSB = yBuffer[(short) (yOffset + yLength)]; byte yBit = (byte) (yLSB & 0x01); if (yBit == 1) { - outputBuffer[offset] = 3; + outputBuffer[offset] += 3; } else { - outputBuffer[offset] = 2; + outputBuffer[offset] += 2; } - case X962_HYBRID: - outputBuffer[offset] += 4; break; default: ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); |
