예제 #1
0
 public void TestPositive256WithExplicitParameters()
 {
     using (ECDsa ecdsa = ECDsaFactory.Create())
     {
         ecdsa.ImportParameters(ECDsaTestData.GetNistP256ExplicitTestData());
         Verify256(ecdsa, true);
     }
 }
예제 #2
0
        public static void TestExplicitImportValidationNegative()
        {
            unchecked
            {
                using (ECDsa ec = ECDsaFactory.Create())
                {
                    ECParameters p = ECDsaTestData.GetNistP256ExplicitTestData();
                    Assert.True(p.Curve.IsPrime);
                    ec.ImportParameters(p);

                    ECParameters temp = p;
                    temp.Q.X = null; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Q.X = new byte[] { }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Q.X = new byte[1] {
                        0x10
                    }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Q.X = (byte[])p.Q.X.Clone(); --temp.Q.X[0]; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));

                    temp     = p;
                    temp.Q.Y = null; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Q.Y = new byte[] { }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Q.Y = new byte[1] {
                        0x10
                    }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Q.Y = (byte[])p.Q.Y.Clone(); --temp.Q.Y[0]; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));

                    temp         = p;
                    temp.Curve.A = null; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.A = new byte[] { }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.A = new byte[1] {
                        0x10
                    }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.A = (byte[])p.Curve.A.Clone(); --temp.Curve.A[0]; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));

                    temp         = p;
                    temp.Curve.B = null; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.B = new byte[] { }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.B = new byte[1] {
                        0x10
                    }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.B = (byte[])p.Curve.B.Clone(); --temp.Curve.B[0]; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));

                    temp             = p;
                    temp.Curve.Order = null; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.Order = new byte[] { }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));

                    temp             = p;
                    temp.Curve.Prime = null; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.Prime = new byte[] { }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.Prime = new byte[1] {
                        0x10
                    }; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                    temp.Curve.Prime = (byte[])p.Curve.Prime.Clone(); --temp.Curve.Prime[0]; Assert.ThrowsAny <CryptographicException>(() => ec.ImportParameters(temp));
                }
            }
        }
예제 #3
0
        public static void TestGeneralExportWithExplicitParameters()
        {
            using (ECDsa ecdsa = ECDsaFactory.Create())
            {
                ECParameters param = ECDsaTestData.GetNistP256ExplicitTestData();
                param.Validate();
                ecdsa.ImportParameters(param);
                Assert.True(param.Curve.IsExplicit);

                param = ecdsa.ExportParameters(false);
                param.Validate();

                // We should have explicit values, not named, as this curve has no name.
                Assert.True(param.Curve.IsExplicit);
            }
        }