diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-06-09 14:56:27 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-06-09 14:56:27 +0700 |
commit | dab58845745b1936666d91c0f2ccc47d5cb5c8a4 (patch) | |
tree | b696207a48bb93af1f7ff4147c4b7da48904b673 | |
parent | Add point validation to EC public key constructors (diff) | |
download | BouncyCastle.NET-ed25519-dab58845745b1936666d91c0f2ccc47d5cb5c8a4.tar.xz |
Add validation to DSA public key constructor
-rw-r--r-- | crypto/src/crypto/parameters/DsaPublicKeyParameters.cs | 18 |
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 |