internal void Validate() { if (!this.publicExponent.TestBit(0)) { throw new ArgumentException("Public exponent must be an odd number: " + Algorithm.Name); } if (CryptoServicesRegistrar.IsInApprovedOnlyMode()) { if (this.keySize != 2048 && this.keySize != 3072) { throw new CryptoUnapprovedOperationError("Attempt to use RSA key size outside of accepted range - requested keySize " + keySize + " bits", Algorithm); } if (this.publicExponent.CompareTo(MIN_PUB_EXP) < 0) { throw new CryptoUnapprovedOperationError("Public exponent too small", Algorithm); } if (this.publicExponent.CompareTo(MAX_PUB_EXP) > 0) { throw new CryptoUnapprovedOperationError("Public exponent too large", Algorithm); } if (!this.publicExponent.TestBit(0)) { throw new CryptoUnapprovedOperationError("Public exponent must be an odd number", Algorithm); } if (this.certainty < PrimeCertaintyCalculator.GetDefaultCertainty(keySize)) { throw new CryptoUnapprovedOperationError("Prime generation certainty " + certainty + " inadequate for key of " + keySize + " bits", Algorithm); } } }
DomainGenParameters(FipsDigestAlgorithm digest, int L, int N, int certainty, BigInteger p, BigInteger q, byte[] seed, int usageIndex) : base(Alg) { if (CryptoServicesRegistrar.IsInApprovedOnlyMode()) { if (p == null && certainty < PrimeCertaintyCalculator.GetDefaultCertainty(L)) { throw new CryptoUnapprovedOperationError("Prime generation certainty " + certainty + " inadequate for parameters of " + L + " bits", this.Algorithm); } } if (usageIndex > 255) { throw new ArgumentException("Usage index must be in range 0 to 255 (or -1 to ignore)"); } this.mDigest = digest; this.mL = L; this.mN = N; this.mCertainty = certainty; this.mP = p; this.mQ = q; this.seed = seed; this.mUsageIndex = usageIndex; }
/// <summary> /// Base constructor - a default certainty will be calculated. /// </summary> /// <param name="publicExponent">The public exponent to use.</param> /// <param name="keySize">The key size (in bits)</param> public KeyGenerationParameters(BigInteger publicExponent, int keySize) : this(Alg, publicExponent, keySize, PrimeCertaintyCalculator.GetDefaultCertainty(keySize)) { }
/// <summary> /// Construct for a specific usage index - this has the effect of using verifiable canonical generation of G. /// </summary> /// <param name="L">Desired length of prime P in bits (the effective key size).</param> /// <param name="N">Desired length of prime Q in bits.</param> /// <param name="usageIndex">A valid usage index.</param> public DomainGenParameters(int L, int N, int usageIndex) : this(L, N, PrimeCertaintyCalculator.GetDefaultCertainty(L), null, null, null, usageIndex) { }
/// <summary> /// Construct without a usage index, this will do a random construction of G. /// </summary> /// <param name="L">Desired length of prime P in bits (the effective key size).</param> /// <param name="N">Desired length of prime Q in bits.</param> public DomainGenParameters(int L, int N) : this(L, N, PrimeCertaintyCalculator.GetDefaultCertainty(L), null, null, null, -1) { }
/// <summary> /// Construct just from strength (L) with a default value for N (160 for 1024, 256 for greater) /// and a default certainty. /// </summary> /// <param name="strength">Desired length of prime P in bits (the effective key size).</param> public DomainGenParameters(int strength) : this(strength, (strength > 1024) ? 256 : 160, PrimeCertaintyCalculator.GetDefaultCertainty(strength), null, null, null, -1) { // Valid N for 2048/3072 , N for 1024 }