public void TestIsElementForPointAtInfinity() { var curve = new CurveGroupAlgebra(curveParameters); Assert.IsTrue(curve.IsPotentialElement(CurvePoint.PointAtInfinity), "IsPotentialElement not true for point at infinity!"); Assert.IsFalse(curve.IsSafeElement(CurvePoint.PointAtInfinity), "IsSafeElement not false for point at infinity!"); }
public void TestGetHashCodeSameForEqual() { var groupAlgebra = new CurveGroupAlgebra(curveParameters); var otherAlgebra = new CurveGroupAlgebra(curveParameters); Assert.AreEqual(groupAlgebra.GetHashCode(), otherAlgebra.GetHashCode()); }
public void TestCreateCryptoGroup() { var expectedGroupAlgebra = new CurveGroupAlgebra(curveParameters); var group = CurveGroupAlgebra.CreateCryptoGroup(curveParameters); Assert.AreEqual(expectedGroupAlgebra, group.Algebra); }
public void TestIsElementForValidPoint(int xRaw, int yRaw) { var curveAlgebra = new CurveGroupAlgebra(curveParameters); var point = new CurvePoint(xRaw, yRaw); Assert.IsTrue(curveAlgebra.IsPotentialElement(point), "IsPotentialElement not true for valid element!"); Assert.IsTrue(curveAlgebra.IsSafeElement(point), "IsSafeElement not true for valid element!"); }
public void TestIsElementForPointNotOnCurve(int xRaw, int yRaw) { var curveAlgebra = new CurveGroupAlgebra(curveParameters); var point = new CurvePoint(xRaw, yRaw); Assert.IsFalse(curveAlgebra.IsPotentialElement(point), "IsPotentialElement not true for point not on curve!"); Assert.IsFalse(curveAlgebra.IsSafeElement(point), "IsSafeElement not true for point not on curve!"); }
public void TestMultiplyScalarOrderResultsInNeutralElement() { var curve = new CurveGroupAlgebra(curveParameters); var p = new CurvePoint(5, 3); var result = curve.MultiplyScalar(p, 11); Assert.AreEqual(curve.NeutralElement, result); }
public void TestIsElementForValidPoint(int rawX, int rawY) { var curve = new CurveGroupAlgebra(curveParameters); var point = new CurvePoint(rawX, rawY); Assert.IsTrue(curve.IsPotentialElement(point), "IsPotentialElement not true for valid element!"); Assert.IsTrue(curve.IsSafeElement(point), "IsSafeElement not true for valid element!"); }
public void TestIsElementForPointNotOnCurve(int rawX, int rawY) { var curve = new CurveGroupAlgebra(curveParameters); var point = new CurvePoint(rawX, rawY); Assert.IsFalse(curve.IsPotentialElement(point), "IsPotentialElement not true for point not on curve!"); Assert.IsFalse(curve.IsSafeElement(point), "IsSafeElement not true for point not on curve!"); }
public void TestIsElementForLowOrderCurvePoint() { var curve = new CurveGroupAlgebra(curveParameters); var point = new CurvePoint(10, 0); Assert.IsTrue(curve.IsPotentialElement(point), "IsPotentialElement not true for low order point!"); Assert.IsFalse(curve.IsSafeElement(point), "IsSafeElement not false for low order point!"); }
public void TestIsElementForPointAtInfinity() { var curve = new CurveGroupAlgebra(curveParameters); curveEquationMock.Setup(eq => eq.Add(It.IsAny <CurvePoint>(), It.IsAny <CurvePoint>())).Returns(CurvePoint.PointAtInfinity); Assert.IsTrue(curve.IsPotentialElement(CurvePoint.PointAtInfinity), "IsPotentialElement not true for point at infinity!"); Assert.IsFalse(curve.IsSafeElement(CurvePoint.PointAtInfinity), "IsSafeElement not false for point at infinity!"); }
public void TestGenerate(BigInteger k, BigInteger expectedX) { var curve25519Algebra = new CurveGroupAlgebra(CurveParameters.Curve25519); var point = curve25519Algebra.GenerateElement(k); Assert.AreEqual(point.X, expectedX); }
public void TestEqualsFalseForNull() { var groupAlgebra = new CurveGroupAlgebra(curveParameters); bool result = groupAlgebra.Equals(null); Assert.IsFalse(result); }
public void TestFromBytesRejectsTooShortBuffer() { var curve = new CurveGroupAlgebra(largeParameters); var buffer = new byte[7]; Assert.Throws <ArgumentException>( () => curve.FromBytes(buffer) ); }
public void TestCurvePoint(BigInteger k, BigInteger expectedX, BigInteger expectedY) { var p256Algebra = new CurveGroupAlgebra(CurveParameters.NISTP256); var point = p256Algebra.GenerateElement(k); var expectedPoint = new CurvePoint(expectedX, expectedY); Assert.AreEqual(point, expectedPoint); }
public void TestEqualsFalseForOtherAlgebra() { var groupAlgebra = new CurveGroupAlgebra(curveParameters); var otherAlgebra = new CurveGroupAlgebra(largeParameters); bool result = groupAlgebra.Equals(otherAlgebra); Assert.IsFalse(result); }
public void TestEqualsFalseForUnrelatedObject() { var groupAlgebra = new CurveGroupAlgebra(curveParameters); var otherAlgebra = new object(); bool result = groupAlgebra.Equals(otherAlgebra); Assert.IsFalse(result); }
public void TestIsElementForPointNotOnCurve() { var curve = new CurveGroupAlgebra(curveParameters); curveEquationMock.Setup(eq => eq.IsPointOnCurve(It.IsAny <CurvePoint>())).Returns(false); var point = new CurvePoint(16, 1); Assert.IsFalse(curve.IsPotentialElement(point), "IsPotentialElement not true for point not on curve!"); Assert.IsFalse(curve.IsSafeElement(point), "IsSafeElement not true for point not on curve!"); }
public void TestNegateForZeroYPoint() { var curve = new CurveGroupAlgebra(curveParameters); var p = new CurvePoint(11, 0); var result = curve.Negate(p); Assert.AreEqual(p, result); Assert.AreNotSame(p, result); }
public void TestNegatePointAtInfinity() { var curve = new CurveGroupAlgebra(curveParameters); var p = CurvePoint.PointAtInfinity; var result = curve.Negate(p); Assert.AreEqual(p, result); Assert.AreNotSame(p, result); }
public void TestMultiplyScalar(int k, int x, int y, int expectedX, int expectedY) { var curveAlgebra = new CurveGroupAlgebra(curveParameters); var expected = new CurvePoint(new BigInteger(expectedX), new BigInteger(expectedY)); var p = new CurvePoint(new BigInteger(x), new BigInteger(y)); var result = curveAlgebra.MultiplyScalar(p, k); Assert.AreEqual(expected, result); }
public void TestFromBytes() { var curve = new CurveGroupAlgebra(largeParameters); var expected = new CurvePoint(5, 3); var buffer = new byte[] { 5, 0, 0, 0, 3, 0, 0, 0 }; var result = curve.FromBytes(buffer); Assert.AreEqual(expected, result); }
public void TestToBytes() { var curve = new CurveGroupAlgebra(largeParameters); var p = new CurvePoint(5, 3); var expected = new byte[] { 5, 0, 0, 0, 3, 0, 0, 0 }; var result = curve.ToBytes(p); CollectionAssert.AreEqual(expected, result); }
public void TestFromBytesWithLessThanOneByteLargeElements() { var curve = new CurveGroupAlgebra(curveParameters); var expected = new CurvePoint(5, 3); var buffer = new byte[] { 5, 3 }; var result = curve.FromBytes(buffer); Assert.AreEqual(expected, result); }
public void TestToBytesWithLessThanOneByteLargeElements() { var curve = new CurveGroupAlgebra(curveParameters); var p = new CurvePoint(5, 5); var expected = new byte[] { 5, 5 }; var result = curve.ToBytes(p); CollectionAssert.AreEqual(expected, result); }
public void TestMultiplyScalar(int kRaw, int expectedX, int expectedY) { var k = new BigInteger(kRaw); var curve = new CurveGroupAlgebra(curveParameters); var p = new CurvePoint(5, 5); var q = curve.MultiplyScalar(p, k); var expectedQ = new CurvePoint(expectedX, expectedY); Assert.AreEqual(expectedQ, q); }
public void TestNegate() { var curve = new CurveGroupAlgebra(curveParameters); var p = new CurvePoint(5, 5); var expected = new CurvePoint(5, 18); var result = curve.Negate(p); Assert.AreEqual(expected, result); }
public void TestIsElementForPointAtInfinityCofactorOne() { var parameters = new CurveParameters( curveParameters.Equation, curveParameters.Generator, curveParameters.Order, BigInteger.One ); var curve = new CurveGroupAlgebra(parameters); curveEquationMock.Setup(eq => eq.Add(It.IsAny <CurvePoint>(), It.IsAny <CurvePoint>())).Returns(CurvePoint.PointAtInfinity); Assert.IsTrue(curve.IsPotentialElement(CurvePoint.PointAtInfinity), "IsPotentialElement not true for point at infinity!"); Assert.IsFalse(curve.IsSafeElement(CurvePoint.PointAtInfinity), "IsSafeElement not false for point at infinity!"); }
public void TestMultiplyScalar() { var k = new BigInteger(5); var curve = new CurveGroupAlgebra(curveParameters); var point = new CurvePoint(5, 5); curveEquationMock.Reset(); curveEquationMock.Setup(eq => eq.Add(It.IsAny <CurvePoint>(), It.IsAny <CurvePoint>())) .Returns((CurvePoint p, CurvePoint q) => new CurvePoint(p.X + q.X, p.Y + q.Y)); var expectedQ = new CurvePoint(25, 25); var otherPoint = curve.MultiplyScalar(point, k); Assert.AreEqual(expectedQ, otherPoint); curveEquationMock.Verify(eq => eq.Add(It.IsAny <CurvePoint>(), It.IsAny <CurvePoint>()), Times.Exactly(2 * 4)); // 2 * Order bit length }
public void TestAdd() { var curve = new CurveGroupAlgebra(curveParameters); var point = new CurvePoint(5, 5); var other = new CurvePoint(15, 14); var expected = new CurvePoint(20, 19); curveEquationMock.Reset(); curveEquationMock.Setup(eq => eq.Add(It.IsAny <CurvePoint>(), It.IsAny <CurvePoint>())) .Returns((CurvePoint p, CurvePoint q) => new CurvePoint(p.X + q.X, p.Y + q.Y)); var result = curve.Add(point, other); Assert.AreEqual(expected, result); curveEquationMock.Verify(eq => eq.Add(It.IsAny <CurvePoint>(), It.IsAny <CurvePoint>()), Times.Once); }
public void TestCofactor() { var curve = new CurveGroupAlgebra(curveParameters); Assert.AreEqual(curveParameters.Cofactor, curve.Cofactor); }