Esempio n. 1
0
        public void CheckSanity()
        {
            // Get some bignum parameters
            BigNumber p1, q1, gcd, lambda;

            p1     = Rsa.SecretPrimeFactorP - 1; // p-1
            q1     = Rsa.SecretPrimeFactorQ - 1; // q-1
            gcd    = BigNumber.gcd(p1, q1);      // gcd of (p-1)(q-1)
            lambda = BigNumber.lcm(p1, q1, gcd); // lcm of (p-1)(q-1)

            // Check for sanity
            if (BigNumber.gcd(lambda, Rsa.PublicExponent) != 1) // check if e is coprime to lambda(n)
            {
                throw new Exception("Key not sane - e and lcm not coprime");
            }
            if (!(Rsa.PublicExponent < Rsa.PublicModulus - 1))
            {
                throw new Exception("Key not sane - not (e < n-1)");
            }

            // Ask OpenSSL if it's sane
            if (!Rsa.Check())
            {
                throw new Exception("Key not sane - openssl says so");
            }
        }