diff options
Diffstat (limited to 'src/applets')
| -rw-r--r-- | src/applets/ECKeyGenerator.java | 5 | ||||
| -rw-r--r-- | src/applets/SimpleECCApplet.java | 23 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/applets/ECKeyGenerator.java b/src/applets/ECKeyGenerator.java index c4b71c0..491cd86 100644 --- a/src/applets/ECKeyGenerator.java +++ b/src/applets/ECKeyGenerator.java @@ -22,7 +22,6 @@ public class ECKeyGenerator { public static final byte KEY_BOTH = KEY_PUBLIC | KEY_PRIVATE; - //TODO: add something like allocateGenerate, or modify allocate to auto-generate a key-pair if it returns null key references after allocating public short allocatePair(byte keyClass, short keyLength) { short result = ISO7816.SW_NO_ERROR; try { @@ -105,6 +104,10 @@ public class ECKeyGenerator { return sw; } + public short setCustomAnomalousCurve(short keyClass, short keyLength, byte[] buffer, short offset) { + return setCustomCurve(EC_Consts.getAnomalousCurve(keyClass, keyLength), buffer, offset); + } + public short setParameter(byte key, short param, byte[] data, short offset, short length) { short result = ISO7816.SW_NO_ERROR; try { diff --git a/src/applets/SimpleECCApplet.java b/src/applets/SimpleECCApplet.java index e63bcf2..ecdfa4e 100644 --- a/src/applets/SimpleECCApplet.java +++ b/src/applets/SimpleECCApplet.java @@ -359,7 +359,7 @@ public class SimpleECCApplet extends Applet { sw = SW_SKIPPED; if ((testFlags & FLAG_ECTEST_SET_ANOMALOUSCURVE) != (short) 0) { if (keyClass == KeyPair.ALG_EC_FP) { //Only FP supported at the moment - sw = ecKeyGenerator.setCustomCurve(EC_Consts.getAnomalousCurve(keyClass, keyLen), m_ramArray, (short) 0); + sw = ecKeyGenerator.setCustomAnomalousCurve(keyClass, keyLen, m_ramArray, (short) 0); } if (sw != ISO7816.SW_NO_ERROR) { testFlags &= ~FLAG_ECTEST_GENERATE_KEYPAIR_ANOMALOUSCUVE; @@ -915,21 +915,30 @@ public class SimpleECCApplet extends Applet { void GenerateAndReturnKey(APDU apdu) { byte[] apdubuf = apdu.getBuffer(); apdu.setIncomingAndReceive(); + + short offset = ISO7816.OFFSET_CDATA; + byte keyClass = apdubuf[offset]; + offset++; - short bitLen = Util.getShort(apdubuf, ISO7816.OFFSET_CDATA); + short keyLength = Util.getShort(apdubuf, offset); + offset+=2; - short offset = 0; + byte anomalous = apdubuf[offset]; + + offset = 0; switch (apdubuf[ISO7816.OFFSET_P1]) { case P1_SETCURVE: { - ecKeyGenerator.allocatePair(KeyPair.ALG_EC_FP, bitLen); + ecKeyGenerator.allocatePair(keyClass, keyLength); + if(anomalous != 0) { + ecKeyGenerator.setCustomAnomalousCurve(keyClass, keyLength, m_ramArray, (short) 0); + } else { + ecKeyGenerator.setCustomCurve(keyClass, keyLength, m_ramArray, (short) 0); + } ecKeyGenerator.generatePair(); ecPubKey = ecKeyGenerator.getPublicKey(); ecPrivKey = ecKeyGenerator.getPrivateKey(); - - // If required, initialize curve parameters first - ecKeyGenerator.setCustomCurve(KeyPair.ALG_EC_FP, bitLen, m_ramArray, (short) 0); break; } case P1_GENERATEKEYPAIR: { |
