Exemplo n.º 1
0
        private static BigInteger Validate(BigInteger y, DHParameters dhParams)
        {
            if (y == null)
            {
                throw new ArgumentNullException("y");
            }

            // TLS check
            if (y.CompareTo(BigInteger.Two) < 0 || y.CompareTo(dhParams.P.Subtract(BigInteger.Two)) > 0)
            {
                throw new ArgumentException("invalid DH public key", "y");
            }

            // we can't validate without Q.
            if (dhParams.Q != null &&
                !y.ModPow(dhParams.Q, dhParams.P).Equals(BigInteger.One))
            {
                throw new ArgumentException("y value does not appear to be in correct group", "y");
            }

            return(y);
        }
Exemplo n.º 2
0
 protected DHKeyParameters(
     bool isPrivate,
     DHParameters parameters)
     : this(isPrivate, parameters, PkcsObjectIdentifiers.DhKeyAgreement)
 {
 }
 internal static int GetStrength(
     DHParameters parameters)
 {
     return(parameters.L != 0 ? parameters.L : parameters.P.BitLength);
 }