public void TestNegate(int elementInt) { var exponent = SecureBigNumber.FromBigNumber(new BigNumber(order - 1)); var x = new BigNumber(elementInt); var negated = groupAlgebra !.Negate(x); Assert.That(groupAlgebra !.Add(negated, x).Equals(BigNumber.One)); Assert.That(groupAlgebra !.Negate(x).Equals(groupAlgebra !.MultiplyScalar(x, exponent))); }
[TestCase(5, 13)] // this is not part of the actual (sub)group but the embedding group, we confirm that it works anyways public void TestMultiplyScalar(int scalarInt, int expectedInt) { var k = SecureBigNumber.FromBigNumber(new BigNumber(scalarInt)); var expected = new BigNumber(expectedInt); var x = new BigNumber(3); var result = groupAlgebra !.MultiplyScalar(x, k); Assert.That(result.Equals(expected)); }
public void TestGenerateElement() { var k = SecureBigNumber.FromBigNumber(new BigNumber(5)); var result = groupAlgebra !.GenerateElement(k); var groupGenerator = new BigNumber(generator); var groupModulo = new BigNumber(prime); var expected = groupGenerator.ModExp(k, groupModulo); Assert.That(result.Equals(expected)); }
public void TestGenerateElement() { var algebra = new EllipticCurveAlgebra(EllipticCurveID.Prime256v1); var generator = algebra.Generator; var groupHandle = ECGroupHandle.CreateByCurveNID((int)EllipticCurveID.Prime256v1); var ctx = BigNumberContextHandle.Create(); var index = SecureBigNumber.FromBigNumber(new BigNumber( BigInteger.Parse("97752369786356789875745735", System.Globalization.NumberStyles.Integer) )); var expected = new ECPoint(groupHandle); ECPointHandle.Multiply(groupHandle, expected.Handle, index.Handle, ECPointHandle.Null, BigNumberHandle.Null, ctx); var result = algebra.GenerateElement(index); Assert.That(result.Equals(expected)); }
public void TestMultipy() { var algebra = new EllipticCurveAlgebra(EllipticCurveID.Prime256v1); var generator = algebra.Generator; var groupHandle = ECGroupHandle.CreateByCurveNID((int)EllipticCurveID.Prime256v1); var ctx = BigNumberContextHandle.Create(); var factor = SecureBigNumber.FromBigNumber(new BigNumber(13)); var basePointFactor = new BigInteger(27); var point = new ECPoint(groupHandle); ECPointHandle.Multiply(groupHandle, point.Handle, new BigNumber(basePointFactor).Handle, ECPointHandle.Null, BigNumberHandle.Null, ctx); var expected = new ECPoint(groupHandle); ECPointHandle.Multiply(groupHandle, expected.Handle, BigNumberHandle.Null, point.Handle, factor.Handle, ctx); var result = algebra.MultiplyScalar(point, factor); Assert.That(result.Equals(expected)); }