From 58b2040d36be9f1271b93a7fae752dc8975a881e Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Fri, 9 Jun 2017 14:41:16 +0700 Subject: Add point validation to EC public key constructors --- .../src/crypto/parameters/ECPublicKeyParameters.cs | 21 ++++++++++++++++++--- 1 file 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 -- cgit 1.4.1