-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fulls test coverage & Equals method for CryptoGroupAlgebra
- Loading branch information
Showing
16 changed files
with
466 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Numerics; | ||
|
||
using NUnit.Framework; | ||
|
||
using CompactCryptoGroupAlgebra; | ||
|
||
namespace CompactCryptoGroupAlgebra.Tests | ||
{ | ||
[TestFixture] | ||
public class ECCryptoGroupTests | ||
{ | ||
private readonly ECParameters ecParams; | ||
|
||
public ECCryptoGroupTests() | ||
{ | ||
ecParams = new ECParameters() | ||
{ | ||
P = 23, | ||
A = -2, | ||
B = 2, | ||
Generator = new ECPoint(1, 1), | ||
Order = 16 | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// This indirectly tests <see cref="ECCryptoGroup.CreateGroupElement(byte[])"/>. | ||
/// </summary> | ||
[Test] | ||
public void TestFromBytes() | ||
{ | ||
var groupAlgebra = new ECGroupAlgebra(ecParams); | ||
var group = new ECCryptoGroup(groupAlgebra); | ||
|
||
var expectedRaw = new ECPoint(5, 5); | ||
var expected = new CryptoGroupElement<ECPoint>(expectedRaw, groupAlgebra); | ||
var bytes = expected.ToBytes(); | ||
var result = group.FromBytes(bytes); | ||
Assert.AreEqual(expected, result); | ||
} | ||
|
||
/// <summary> | ||
/// Indirectly also tests <see cref="ECCryptoGroup.CreateGroupElement(ECPoint)"/>. | ||
/// </summary> | ||
[Test] | ||
public void TestConstructorAlgebra() | ||
{ | ||
var groupAlgebra = new ECGroupAlgebra(ecParams); | ||
var group = new ECCryptoGroup(groupAlgebra); | ||
|
||
var expectedNeutralElement = new CryptoGroupElement<ECPoint>(ECPoint.PointAtInfinity, groupAlgebra); | ||
var expectedGenerator = new CryptoGroupElement<ECPoint>(ecParams.Generator, groupAlgebra); | ||
|
||
var resultNeutralElement = group.NeutralElement; | ||
var resultGenerator = group.Generator; | ||
|
||
Assert.AreEqual(expectedNeutralElement, resultNeutralElement, "verifying neutral element"); | ||
Assert.AreEqual(expectedGenerator, resultGenerator, "verifying generator"); | ||
Assert.AreEqual(ecParams.Order, group.Order, "verifying order"); | ||
} | ||
|
||
/// <summary> | ||
/// Indirectly also tests <see cref="ECCryptoGroup.CreateGroupElement(ECPoint)"/>. | ||
/// </summary> | ||
[Test] | ||
public void TestConstructorParameters() | ||
{ | ||
var groupAlgebra = new ECGroupAlgebra(ecParams); | ||
var group = new ECCryptoGroup(ecParams); | ||
|
||
var expectedNeutralElement = new CryptoGroupElement<ECPoint>(ECPoint.PointAtInfinity, groupAlgebra); | ||
var expectedGenerator = new CryptoGroupElement<ECPoint>(ecParams.Generator, groupAlgebra); | ||
|
||
var resultNeutralElement = group.NeutralElement; | ||
var resultGenerator = group.Generator; | ||
|
||
Assert.AreEqual(expectedNeutralElement, resultNeutralElement, "verifying neutral element"); | ||
Assert.AreEqual(expectedGenerator, resultGenerator, "verifying generator"); | ||
Assert.AreEqual(ecParams.Order, group.Order, "verifying order"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.