コード例 #1
0
        public void TestCreateCryptoGroup()
        {
            var expectedGroupAlgebra = new XOnlyMontgomeryCurveAlgebra(curveParameters);
            var group = XOnlyMontgomeryCurveAlgebra.CreateCryptoGroup(curveParameters);

            Assert.AreEqual(expectedGroupAlgebra, group.Algebra);
        }
コード例 #2
0
        public void TestEqualsFalseForDifferent()
        {
            var curve      = new XOnlyMontgomeryCurveAlgebra(curveParameters);
            var otherCurve = new XOnlyMontgomeryCurveAlgebra(largeParameters);

            Assert.IsFalse(curve.Equals(otherCurve));
        }
コード例 #3
0
        public void TestGetHashCodeSameForEqual()
        {
            var curve      = new XOnlyMontgomeryCurveAlgebra(curveParameters);
            var otherCurve = new XOnlyMontgomeryCurveAlgebra(curveParameters);

            Assert.AreEqual(curve.GetHashCode(), otherCurve.GetHashCode());
        }
コード例 #4
0
        public void TestEqualsTrueForEqual()
        {
            var curve      = new XOnlyMontgomeryCurveAlgebra(curveParameters);
            var otherCurve = new XOnlyMontgomeryCurveAlgebra(curveParameters);

            Assert.IsTrue(curve.Equals(otherCurve));
        }
コード例 #5
0
        public void TestXOnlyGenerate(BigInteger k, BigInteger expectedX)
        {
            var curve25519Algebra = new XOnlyMontgomeryCurveAlgebra(CurveParameters.Curve25519);

            var point = curve25519Algebra.GenerateElement(k);

            Assert.AreEqual(point, expectedX);
        }
コード例 #6
0
        public void TestXOnlyMultiplyScalar(BigInteger k, BigInteger inputX, BigInteger expectedX)
        {
            var curve25519Algebra = new XOnlyMontgomeryCurveAlgebra(CurveParameters.Curve25519);

            var point = curve25519Algebra.MultiplyScalar(inputX, k);

            Assert.AreEqual(point, expectedX);
        }
コード例 #7
0
        public void TestIsElementForLowOrderElements()
        {
            var curve = new XOnlyMontgomeryCurveAlgebra(curveParameters);
            var p     = new BigInteger(0);

            Assert.IsTrue(curve.IsPotentialElement(p));
            Assert.IsFalse(curve.IsSafeElement(p));
        }
コード例 #8
0
        public void TestNegateThrowsNotSupported()
        {
            var point   = new BigInteger(2);
            var algebra = new XOnlyMontgomeryCurveAlgebra(curveParameters);

            Assert.Throws <NotSupportedException>(
                () => algebra.Negate(point)
                );
        }
コード例 #9
0
        public void TestMultiplyScalar(int k, int x, int expectedX)
        {
            var algebra = new XOnlyMontgomeryCurveAlgebra(curveParameters);

            var p      = new BigInteger(x);
            var result = algebra.MultiplyScalar(p, k);

            Assert.AreEqual(new BigInteger(expectedX), result);
        }
コード例 #10
0
        public void TestConstructorAndProperties()
        {
            var algebra = new XOnlyMontgomeryCurveAlgebra(curveParameters);

            Assert.AreEqual(curveParameters.Generator.X, algebra.Generator);
            Assert.AreEqual(curveParameters.Order, algebra.Order);
            Assert.AreEqual(curveParameters.Cofactor, algebra.Cofactor);
            Assert.AreEqual(NumberLength.GetLength(curveParameters.Equation.Field.Modulo).InBits, algebra.ElementBitLength);
            Assert.AreEqual(algebra.OrderBitLength / 2, algebra.SecurityLevel);
        }
コード例 #11
0
        public void TestToBytesWithLessThanOneByteLargeElements()
        {
            var curve    = new XOnlyMontgomeryCurveAlgebra(curveParameters);
            var p        = new BigInteger(5);
            var expected = new byte[] { 5 };

            var result = curve.ToBytes(p);

            CollectionAssert.AreEqual(expected, result);
        }
コード例 #12
0
        public void TestFromBytesWithLessThanOneByteLargeElements()
        {
            var curve    = new XOnlyMontgomeryCurveAlgebra(curveParameters);
            var expected = new BigInteger(5);
            var buffer   = new byte[] { 5 };

            var result = curve.FromBytes(buffer);

            Assert.AreEqual(expected, result);
        }
コード例 #13
0
        public void TestEqualsFalseForNull()
        {
            var curve = new XOnlyMontgomeryCurveAlgebra(curveParameters);

            Assert.IsFalse(curve.Equals(null));
        }