public void TestAdd() { var algebra = new EllipticCurveAlgebra(EllipticCurveID.Prime256v1); var generator = algebra.Generator; var groupHandle = ECGroupHandle.CreateByCurveNID((int)EllipticCurveID.Prime256v1); var ctx = BigNumberContextHandle.Create(); var kA = new BigInteger(27); var kB = new BigInteger(13); var pointA = new ECPoint(groupHandle); ECPointHandle.Multiply(groupHandle, pointA.Handle, new BigNumber(kA).Handle, ECPointHandle.Null, BigNumberHandle.Null, ctx); var pointB = new ECPoint(groupHandle); ECPointHandle.Multiply(groupHandle, pointB.Handle, new BigNumber(kB).Handle, ECPointHandle.Null, BigNumberHandle.Null, ctx); var expected = new ECPoint(groupHandle); ECPointHandle.Multiply(groupHandle, expected.Handle, new BigNumber(kA + kB).Handle, ECPointHandle.Null, BigNumberHandle.Null, ctx); var result = algebra.Add(pointA, pointB); Assert.That(result.Equals(expected)); }
public void TestNeutralElement() { var algebra = new EllipticCurveAlgebra(EllipticCurveID.Prime256v1); var neutralElement = algebra.NeutralElement; var result = algebra.Add(neutralElement, neutralElement); Assert.That(result.Equals(neutralElement)); }
public void TestNegate() { var algebra = new EllipticCurveAlgebra(EllipticCurveID.Prime256v1); var generator = algebra.Generator; var groupHandle = ECGroupHandle.CreateByCurveNID((int)EllipticCurveID.Prime256v1); var ctx = BigNumberContextHandle.Create(); var index = new BigInteger(3); var point = new ECPoint(groupHandle); ECPointHandle.Multiply(groupHandle, point.Handle, new BigNumber(index).Handle, ECPointHandle.Null, BigNumberHandle.Null, ctx); var result = algebra.Negate(point); var pointPlusNegated = algebra.Add(point, result); Assert.That(pointPlusNegated.Equals(algebra.NeutralElement)); }