Skip to content

Commit ca41092

Browse files
committed
OpenSsl library: Added helper functions for easy instantiation of CryptoGroup.
1 parent 8cd07ae commit ca41092

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

CompactCryptoGroupAlgebra.OpenSsl.Tests/EllipticCurveAlgebraTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ public void TestGetHashCodeSameForEqual()
279279
Assert.That(algebra.GetHashCode() == otherAlgebra.GetHashCode());
280280
}
281281

282+
[Test]
283+
public void TestCreateCryptoGroup()
284+
{
285+
var expectedGroupAlgebra = new EllipticCurveAlgebra(EllipticCurveID.Prime256v1);
286+
var group = EllipticCurveAlgebra.CreateCryptoGroup(EllipticCurveID.Prime256v1);
287+
Assert.That(group.Algebra.Equals(expectedGroupAlgebra));
288+
}
282289

283290
}
284291

CompactCryptoGroupAlgebra.OpenSsl.Tests/MultiplicativeGroupAlgebraTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,17 @@ public void TestDispose()
267267
Assert.DoesNotThrow(algebra.Dispose);
268268
}
269269

270+
[Test]
271+
public void TestCreateCryptoGroup()
272+
{
273+
var group = MultiplicativeGroupAlgebra.CreateCryptoGroup(
274+
prime, order, generator
275+
);
276+
var expectedGroupAlgebra = new MultiplicativeGroupAlgebra(
277+
prime, order, generator
278+
);
279+
Assert.That(group.Algebra.Equals(expectedGroupAlgebra));
280+
}
281+
270282
}
271283
}

CompactCryptoGroupAlgebra.OpenSsl/EllipticCurveAlgebra.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ public override int GetHashCode()
279279
return hashCode;
280280
}
281281

282+
/// <summary>
283+
/// Creates a <see cref="CryptoGroup{SecureBigNumber, ECPoint}" /> instance using a <see cref="EllipticCurveAlgebra" />
284+
/// for the given curve identifier.
285+
/// </summary>
286+
/// <param name="curveId">Identifier of the elliptic curve.</param>
287+
public static CryptoGroup<SecureBigNumber, ECPoint> CreateCryptoGroup(EllipticCurveID curveId)
288+
{
289+
return new CryptoGroup<SecureBigNumber, ECPoint>(new EllipticCurveAlgebra(curveId));
290+
}
291+
282292
}
283293

284294
}

CompactCryptoGroupAlgebra.OpenSsl/MultiplicativeGroupAlgebra.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ public override int GetHashCode()
174174
return hashCode;
175175
}
176176

177+
/// <summary>
178+
/// Creates a <see cref="CryptoGroup{SecureBigNumber, BigNumber}" /> instance using a <see cref="MultiplicativeGroupAlgebra" />
179+
/// instance with the given parameters.
180+
/// </summary>
181+
/// <param name="prime">The prime modulo of the group.</param>
182+
/// <param name="order">The order of the group</param>
183+
/// <param name="generator">The generator of the group.</param>
184+
public static CryptoGroup<SecureBigNumber, BigNumber> CreateCryptoGroup(
185+
BigPrime prime, BigPrime order, BigInteger generator
186+
)
187+
{
188+
return new CryptoGroup<SecureBigNumber, BigNumber>(new MultiplicativeGroupAlgebra(
189+
prime, order, generator
190+
));
191+
}
192+
177193
}
178194

179195
}

0 commit comments

Comments
 (0)