summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2017-06-09 14:41:16 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2017-06-09 14:41:16 +0700
commit58b2040d36be9f1271b93a7fae752dc8975a881e (patch)
treed4a87d25909a7e9b5cf4a8b5baf7460e931bcc00
parentAdd explicit length check on OAEP input (diff)
downloadBouncyCastle.NET-ed25519-58b2040d36be9f1271b93a7fae752dc8975a881e.tar.xz
Add point validation to EC public key constructors
-rw-r--r--crypto/src/crypto/parameters/ECPublicKeyParameters.cs21
1 files changed, 18 insertions, 3 deletions
diff --git a/crypto/src/crypto/parameters/ECPublicKeyParameters.cs b/crypto/src/crypto/parameters/ECPublicKeyParameters.cs
index 1eb665da9..474e5d82c 100644
--- a/crypto/src/crypto/parameters/ECPublicKeyParameters.cs
+++ b/crypto/src/crypto/parameters/ECPublicKeyParameters.cs
@@ -9,6 +9,21 @@ namespace Org.BouncyCastle.Crypto.Parameters
     public class ECPublicKeyParameters
         : ECKeyParameters
     {
+        private static ECPoint Validate(ECPoint q)
+        {
+            if (q == null)
+                throw new ArgumentNullException("q");
+            if (q.IsInfinity)
+                throw new ArgumentException("point at infinity", "q");
+
+            q = q.Normalize();
+
+            if (!q.IsValid())
+                throw new ArgumentException("point not on curve", "q");
+
+            return q;
+        }
+
         private readonly ECPoint q;
 
         public ECPublicKeyParameters(
@@ -27,7 +42,7 @@ namespace Org.BouncyCastle.Crypto.Parameters
             if (q == null)
                 throw new ArgumentNullException("q");
 
-            this.q = q.Normalize();
+            this.q = Validate(q);
         }
 
         public ECPublicKeyParameters(
@@ -39,7 +54,7 @@ namespace Org.BouncyCastle.Crypto.Parameters
             if (q == null)
                 throw new ArgumentNullException("q");
 
-            this.q = q.Normalize();
+            this.q = Validate(q);
         }
 
         public ECPublicKeyParameters(
@@ -51,7 +66,7 @@ namespace Org.BouncyCastle.Crypto.Parameters
             if (q == null)
                 throw new ArgumentNullException("q");
 
-            this.q = q.Normalize();
+            this.q = Validate(q);
         }
 
         public ECPoint Q