From a870bd0c491a616c7b5afac1643e93e5fe12d8ff Mon Sep 17 00:00:00 2001 From: Luka Logar Date: Fri, 29 May 2020 10:49:36 +0200 Subject: [PATCH] Do not throw CryptoException if EC KeyBuilder.buildKey() does not match a known curve The curve parameters can in any case be set later via the ECKeyImpl.setX(). --- .../java/com/licel/jcardsim/crypto/ECKeyImpl.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java index 206d00bb..29678594 100644 --- a/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java @@ -60,7 +60,11 @@ public abstract class ECKeyImpl extends KeyImpl implements ECKey { public ECKeyImpl(byte keyType, short keySize) { this.size = keySize; this.type = keyType; - setDomainParameters(getDefaultsDomainParameters(type, size)); + try { + setDomainParameters(getDefaultsDomainParameters(type, size)); + } catch (CryptoException e) { + clearKeyInternal(); + } } /** @@ -79,18 +83,23 @@ public ECKeyImpl(ECKeyParameters parameters) { setDomainParameters(parameters.getParameters()); } - public void clearKey() { + private void clearKeyInternal() { a.clear(); b.clear(); g.clear(); r.clear(); fp.clear(); k = 0; + isKInitialized = false; e1 = 0; e2 = 0; e3 = 0; } + public void clearKey() { + clearKeyInternal(); + } + protected boolean isDomainParametersInitialized() { return (a.isInitialized() && b.isInitialized() && g.isInitialized() && r.isInitialized() && isKInitialized && (fp.isInitialized() || k != 0));