summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
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