Skip to content

Commit

Permalink
Added CreateCryptoGroup for XOnlyMontgomeryCurveAlgebra
Browse files Browse the repository at this point in the history
  • Loading branch information
lumip committed Jul 19, 2020
1 parent 9af7f05 commit de97478
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ public void TestDiffieHellmanWithCurve25519Curve()
[Test]
public void TestDiffieHellmanWithXOnlyCurve25519Curve()
{
var group = new CryptoGroup<BigInteger>(
new EllipticCurves.XOnlyMontgomeryCurveAlgebra(
EllipticCurves.CurveParameters.Curve25519
)
var group = EllipticCurves.XOnlyMontgomeryCurveAlgebra.CreateCryptoGroup(
EllipticCurves.CurveParameters.Curve25519
);

DoDiffieHellman(group);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ public void TestGetHashCodeSameForEqual()
Assert.AreEqual(curve.GetHashCode(), otherCurve.GetHashCode());
}


[Test]
public void TestCreateCryptoGroup()
{
var expectedGroupAlgebra = new XOnlyMontgomeryCurveAlgebra(curveParameters);
var group = XOnlyMontgomeryCurveAlgebra.CreateCryptoGroup(curveParameters);
Assert.AreEqual(expectedGroupAlgebra, group.Algebra);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public sealed class CurveGroupAlgebra : CryptoGroupAlgebra<CurvePoint>
/// <summary>
/// Initializes a new instance of the <see cref="CurveGroupAlgebra"/> class.
/// </summary>
/// <param name="parameters">The parameters of the elliptic curve.</param>
public CurveGroupAlgebra(CurveParameters parameters)
: base(
parameters.Generator,
Expand Down Expand Up @@ -133,8 +134,9 @@ public override int GetHashCode()

/// <summary>
/// Creates a <see cref="CryptoGroup{CurvePoint}" /> instance using a <see cref="CurveGroupAlgebra" />
/// instance with the given <see cref="CurveEquation"/>.
/// instance with the given <see cref="CurveParameters"/>.
/// </summary>
/// <param name="parameters">The parameters of the elliptic curve.</param>
public static CryptoGroup<CurvePoint> CreateCryptoGroup(CurveParameters parameters)
{
return new CryptoGroup<CurvePoint>(new CurveGroupAlgebra(parameters));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class XOnlyMontgomeryCurveAlgebra : CryptoGroupAlgebra<BigInteger>
/// Initializes a new instance of <see cref="XOnlyMontgomeryCurveAlgebra"/>
/// with given curve parameters.
/// </summary>
/// <param name="parameters">Curve parameters.</param>
/// <param name="parameters">The parameters of the elliptic curve.</param>
public XOnlyMontgomeryCurveAlgebra(CurveParameters parameters)
: base(
parameters.Generator.X,
Expand Down Expand Up @@ -250,5 +250,17 @@ public override int GetHashCode()
var hashCode = -2051777468 + _parameters.GetHashCode();
return hashCode;
}

/// <summary>
/// Creates a <see cref="CryptoGroup{BigInteger}" /> instance using a <see cref="XOnlyMontgomeryCurveAlgebra" />
/// instance with the given <see cref="CurveParameters"/>.
/// </summary>
/// <param name="parameters">The parameters of the elliptic curve.</param>
public static CryptoGroup<BigInteger> CreateCryptoGroup(CurveParameters parameters)
{
return new CryptoGroup<BigInteger>(
new XOnlyMontgomeryCurveAlgebra(parameters)
);
}
}
}

0 comments on commit de97478

Please sign in to comment.