diff options
| author | J08nY | 2016-11-02 21:05:56 +0100 |
|---|---|---|
| committer | J08nY | 2016-11-21 14:09:47 +0100 |
| commit | c2be46f5881a3a8e63c0815de28f0516ceeb7bcc (patch) | |
| tree | d7960b902066c009bc4546fe0aee257b665ac791 /src/applets/ECKeyGenerator.java | |
| parent | 6a68401612f5e61f966def58ed60eaff52b6f7f6 (diff) | |
| download | ECTester-c2be46f5881a3a8e63c0815de28f0516ceeb7bcc.tar.gz ECTester-c2be46f5881a3a8e63c0815de28f0516ceeb7bcc.tar.zst ECTester-c2be46f5881a3a8e63c0815de28f0516ceeb7bcc.zip | |
Implemented External curve setting on applet side
SimpleECCApplet: added TestEC_SupportExternal which receives an FP or
F2M elliptic curve parameters in an APDU, sets it and tries ECDH, ECDSA.
ECKeyGenerator: added setExternalCurve, which reads and sets external
parameters from one buffer, with data order:
field | a | b | g | r | k
Diffstat (limited to 'src/applets/ECKeyGenerator.java')
| -rw-r--r-- | src/applets/ECKeyGenerator.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/applets/ECKeyGenerator.java b/src/applets/ECKeyGenerator.java index 393c249..28b3ed3 100644 --- a/src/applets/ECKeyGenerator.java +++ b/src/applets/ECKeyGenerator.java @@ -70,6 +70,7 @@ public class ECKeyGenerator { } if (sw != ISO7816.SW_NO_ERROR) return sw; + //go through all params for (byte param = EC_Consts.PARAMETER_A; param <= EC_Consts.PARAMETER_K; param = (byte)(param << 1)) { length = EC_Consts.getCurveParameter(curve, param, buffer, offset); sw = setExternalParameter(KEY_BOTH, param, buffer, offset, length); @@ -159,6 +160,38 @@ public class ECKeyGenerator { return result; } + public short setExternalCurve(byte key, byte keyClass, byte[] buffer, short offset, short fieldLength, short aLength, short bLength, short gxLength, short gyLength, short rLength){ + short sw = ISO7816.SW_NO_ERROR; + if (keyClass == KeyPair.ALG_EC_FP) { + sw = setExternalParameter(key, EC_Consts.PARAMETER_FP, buffer, offset, fieldLength); + } else if (keyClass == KeyPair.ALG_EC_F2M) { + sw = setExternalParameter(key, EC_Consts.PARAMETER_F2M, buffer, offset, fieldLength); + } + if (sw != ISO7816.SW_NO_ERROR) return sw; + + offset += fieldLength; + + //go through all params + sw = setExternalParameter(key, EC_Consts.PARAMETER_A, buffer, offset, aLength); + if (sw != ISO7816.SW_NO_ERROR) return sw; + offset += aLength; + sw = setExternalParameter(key, EC_Consts.PARAMETER_B, buffer, offset, bLength); + if (sw != ISO7816.SW_NO_ERROR) return sw; + offset += bLength; + + sw = setExternalParameter(key, EC_Consts.PARAMETER_G, buffer, offset, (short) (gxLength + gyLength)); + if (sw != ISO7816.SW_NO_ERROR) return sw; + offset += gxLength + gyLength; + + + sw = setExternalParameter(key, EC_Consts.PARAMETER_R, buffer, offset, aLength); + if (sw != ISO7816.SW_NO_ERROR) return sw; + offset += rLength; + + sw = setExternalParameter(key, EC_Consts.PARAMETER_K, buffer, offset, (short) 2); + return sw; + } + public short exportParameter(byte key, short param, byte[] outputBuffer, short outputOffset) { if (key == KEY_BOTH) { return -1; |
