summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2017-06-09 14:56:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2017-06-09 14:56:27 +0700
commitdab58845745b1936666d91c0f2ccc47d5cb5c8a4 (patch)
treeb696207a48bb93af1f7ff4147c4b7da48904b673 /crypto/src
parentAdd point validation to EC public key constructors (diff)
downloadBouncyCastle.NET-ed25519-dab58845745b1936666d91c0f2ccc47d5cb5c8a4.tar.xz
Add validation to DSA public key constructor
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/crypto/parameters/DsaPublicKeyParameters.cs18
1 files changed, 17 insertions, 1 deletions
diff --git a/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs b/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs

index f11f858f3..3a81bfdd0 100644 --- a/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs +++ b/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs
@@ -7,6 +7,22 @@ namespace Org.BouncyCastle.Crypto.Parameters public class DsaPublicKeyParameters : DsaKeyParameters { + private static BigInteger Validate(BigInteger y, DsaParameters parameters) + { + // we can't validate without params, fortunately we can't use the key either... + if (parameters != null) + { + if (y.CompareTo(BigInteger.Two) < 0 + || y.CompareTo(parameters.P.Subtract(BigInteger.Two)) > 0 + || !y.ModPow(parameters.Q, parameters.P).Equals(BigInteger.One)) + { + throw new ArgumentException("y value does not appear to be in correct group"); + } + } + + return y; + } + private readonly BigInteger y; public DsaPublicKeyParameters( @@ -17,7 +33,7 @@ namespace Org.BouncyCastle.Crypto.Parameters if (y == null) throw new ArgumentNullException("y"); - this.y = y; + this.y = Validate(y, parameters); } public BigInteger Y