Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-05 15:45:13 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-05 15:45:13 +0400
commit584df7351aa65334ac7ea87958bf4960ed5ae2d8 (patch)
tree5810a40a06cf3fe8c88ec2b047a0d2e0e7777f1c /core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java
parente9d488b2b13b381fc5b06c18288ed48a645e2048 (diff)
Use field info instead of casting to ECCurve.F2m
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.java26
1 files changed, 16 insertions, 10 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 c3ddc892..017618b3 100644
--- a/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java
+++ b/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java
@@ -22,6 +22,7 @@ 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.field.PolynomialExtensionField;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.BigIntegers;
import org.bouncycastle.util.Integers;
@@ -565,28 +566,33 @@ public class TlsECCUtils
writeECParameter(curve.getField().getCharacteristic(), output);
}
- else if (curve instanceof ECCurve.F2m)
+ else if (ECAlgorithms.isF2mCurve(curve))
{
+ PolynomialExtensionField field = (PolynomialExtensionField)curve.getField();
+ int[] exponents = field.getMinimalPolynomial().getExponentsPresent();
+
TlsUtils.writeUint8(ECCurveType.explicit_char2, output);
- ECCurve.F2m f2m = (ECCurve.F2m) curve;
- int m = f2m.getM();
+ int m = exponents[exponents.length - 1];
TlsUtils.checkUint16(m);
TlsUtils.writeUint16(m, output);
- if (f2m.isTrinomial())
+ if (exponents.length == 3)
{
TlsUtils.writeUint8(ECBasisType.ec_basis_trinomial, output);
- writeECExponent(f2m.getK1(), output);
+ writeECExponent(exponents[1], output);
}
- else
+ else if (exponents.length == 5)
{
TlsUtils.writeUint8(ECBasisType.ec_basis_pentanomial, output);
- writeECExponent(f2m.getK1(), output);
- writeECExponent(f2m.getK2(), output);
- writeECExponent(f2m.getK3(), output);
+ writeECExponent(exponents[1], output);
+ writeECExponent(exponents[2], output);
+ writeECExponent(exponents[3], output);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Only trinomial and pentomial curves are supported");
}
-
}
else
{