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
path: root/core/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-05-19 17:21:47 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-05-19 17:21:47 +0400
commitbd6b39bf60e6609e377becaaefc632c0097e4796 (patch)
tree84bb111df7a6ad55905899d8a1927639c3cb6f19 /core/src
parent49555ece84b685bddbbbb5e48d3f7715452aab2f (diff)
Check the low-bit of y is consistent with the header byte in hybrid EC point encodings
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/ECCurve.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/ECCurve.java b/core/src/main/java/org/bouncycastle/math/ec/ECCurve.java
index 066c950b..78577b78 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/ECCurve.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/ECCurve.java
@@ -331,16 +331,33 @@ public abstract class ECCurve
break;
}
case 0x04: // uncompressed
+ {
+ if (encoded.length != (2 * expectedLength + 1))
+ {
+ throw new IllegalArgumentException("Incorrect length for uncompressed encoding");
+ }
+
+ BigInteger X = BigIntegers.fromUnsignedByteArray(encoded, 1, expectedLength);
+ BigInteger Y = BigIntegers.fromUnsignedByteArray(encoded, 1 + expectedLength, expectedLength);
+
+ p = createPoint(X, Y);
+ break;
+ }
case 0x06: // hybrid
case 0x07: // hybrid
{
if (encoded.length != (2 * expectedLength + 1))
{
- throw new IllegalArgumentException("Incorrect length for uncompressed/hybrid encoding");
+ throw new IllegalArgumentException("Incorrect length for hybrid encoding");
}
BigInteger X = BigIntegers.fromUnsignedByteArray(encoded, 1, expectedLength);
BigInteger Y = BigIntegers.fromUnsignedByteArray(encoded, 1 + expectedLength, expectedLength);
+
+ if (Y.testBit(0) != (encoded[0] == 0x07))
+ {
+ throw new IllegalArgumentException("Inconsistent Y coordinate in hybrid encoding");
+ }
p = createPoint(X, Y);
break;