diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-05 15:03:50 +0400 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-05 15:03:50 +0400 |
commit | 91de395300a9da83f1c9d9601ae7407c62d743a2 (patch) | |
tree | e8f1c01878b7bd311846bc507a1fda7d0715c0ec /core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java | |
parent | 369c1cd951428476fc619b1ec1e1e27b7f3fa6ed (diff) |
ECCurve now exposes the FiniteField that it is defined over via
getField() method.
ECAlgorithms now has isFpCurve and isF2mCurve to begin the process of
cleaning up various instanceof checks on ECCurve.Fp and ECCurve.F2m.
Some callsites changed to use new tests and access curve field.
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java b/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java index 017ab881..c3ddc892 100644 --- a/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java +++ b/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java @@ -18,11 +18,10 @@ import org.bouncycastle.crypto.params.ECDomainParameters; import org.bouncycastle.crypto.params.ECKeyGenerationParameters; import org.bouncycastle.crypto.params.ECPrivateKeyParameters; import org.bouncycastle.crypto.params.ECPublicKeyParameters; +import org.bouncycastle.math.ec.ECAlgorithms; import org.bouncycastle.math.ec.ECCurve; import org.bouncycastle.math.ec.ECFieldElement; import org.bouncycastle.math.ec.ECPoint; -import org.bouncycastle.math.ec.custom.sec.SecP256K1Curve; -import org.bouncycastle.math.ec.custom.sec.SecP256R1Curve; import org.bouncycastle.util.Arrays; import org.bouncycastle.util.BigIntegers; import org.bouncycastle.util.Integers; @@ -324,14 +323,13 @@ public class TlsECCUtils * used. */ boolean compressed = false; - if (curve instanceof ECCurve.F2m) + if (ECAlgorithms.isFpCurve(curve)) { - compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_char2); + compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_prime); } - // TODO: need a better indicator for a custom curve - else if (curve instanceof ECCurve.Fp || curve instanceof SecP256K1Curve || curve instanceof SecP256R1Curve) + else if (ECAlgorithms.isF2mCurve(curve)) { - compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_prime); + compressed = isCompressionPreferred(ecPointFormats, ECPointFormat.ansiX962_compressed_char2); } return point.getEncoded(compressed); } @@ -561,28 +559,11 @@ public class TlsECCUtils { ECCurve curve = ecParameters.getCurve(); - if (curve instanceof ECCurve.Fp) - { - TlsUtils.writeUint8(ECCurveType.explicit_prime, output); - - ECCurve.Fp fp = (ECCurve.Fp) curve; - writeECParameter(fp.getQ(), output); - } - // TODO: need a better indicator for a custom curve - else if (curve instanceof SecP256K1Curve) - { - TlsUtils.writeUint8(ECCurveType.explicit_prime, output); - - SecP256K1Curve fp = (SecP256K1Curve) curve; - writeECParameter(fp.getQ(), output); - } - // TODO: need a better indicator for a custom curve - else if (curve instanceof SecP256R1Curve) + if (ECAlgorithms.isFpCurve(curve)) { TlsUtils.writeUint8(ECCurveType.explicit_prime, output); - SecP256R1Curve fp = (SecP256R1Curve) curve; - writeECParameter(fp.getQ(), output); + writeECParameter(curve.getField().getCharacteristic(), output); } else if (curve instanceof ECCurve.F2m) { |