Skip to content

Commit e63192c

Browse files
committed
Code style/formatting improvements
1 parent 8e1b358 commit e63192c

File tree

10 files changed

+39
-40
lines changed

10 files changed

+39
-40
lines changed

CompactCryptoGroupAlgebra/BigPrime.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static BigPrime Create(BigInteger primeValue, RandomNumberGenerator rando
8888
/// <param name="p">The first <see cref="BigPrime"/> to add.</param>
8989
/// <param name="x">The second <see cref="BigInteger"/> to add.</param>
9090
/// <returns>The <see cref="BigInteger"/> that is the sum of the values of <c>p</c> and <c>x</c>.</returns>
91-
public static BigInteger operator+(BigPrime p, BigInteger x)
91+
public static BigInteger operator +(BigPrime p, BigInteger x)
9292
{
9393
return p._value + x;
9494
}
@@ -100,7 +100,7 @@ public static BigPrime Create(BigInteger primeValue, RandomNumberGenerator rando
100100
/// <param name="x">The first <see cref="BigInteger"/> to add.</param>
101101
/// <param name="p">The second <see cref="BigPrime"/> to add.</param>
102102
/// <returns>The <see cref="BigInteger"/> that is the sum of the values of <c>x</c> and <c>p</c>.</returns>
103-
public static BigInteger operator+(BigInteger x, BigPrime p)
103+
public static BigInteger operator +(BigInteger x, BigPrime p)
104104
{
105105
return p + x;
106106
}
@@ -112,7 +112,7 @@ public static BigPrime Create(BigInteger primeValue, RandomNumberGenerator rando
112112
/// <param name="p">The <see cref="CompactCryptoGroupAlgebra.BigPrime"/> to subtract from (the minuend).</param>
113113
/// <param name="x">The <see cref="System.Numerics.BigInteger"/> to subtract (the subtrahend).</param>
114114
/// <returns>The <see cref="System.Numerics.BigInteger"/> that is <c>p</c> minus <c>x</c>.</returns>
115-
public static BigInteger operator-(BigPrime p, BigInteger x)
115+
public static BigInteger operator -(BigPrime p, BigInteger x)
116116
{
117117
return p._value - x;
118118
}
@@ -124,7 +124,7 @@ public static BigPrime Create(BigInteger primeValue, RandomNumberGenerator rando
124124
/// <param name="x">The <see cref="System.Numerics.BigInteger"/> to subtract from (the minuend).</param>
125125
/// <param name="p">The <see cref="CompactCryptoGroupAlgebra.BigPrime"/> to subtract (the subtrahend).</param>
126126
/// <returns>The <see cref="System.Numerics.BigInteger"/> that is <c>x</c> minus <c>p</c>.</returns>
127-
public static BigInteger operator-(BigInteger x, BigPrime p)
127+
public static BigInteger operator -(BigInteger x, BigPrime p)
128128
{
129129
return x - p._value;
130130
}
@@ -134,7 +134,7 @@ public static BigPrime Create(BigInteger primeValue, RandomNumberGenerator rando
134134
/// </summary>
135135
/// <param name="p">The <see cref="BigPrime"/> to negate.</param>
136136
/// <returns>The <see cref="BigInteger"/> that is the negation of <c>p</c></returns>.
137-
public static BigInteger operator-(BigPrime p)
137+
public static BigInteger operator -(BigPrime p)
138138
{
139139
return -p._value;
140140
}
@@ -146,7 +146,7 @@ public static BigPrime Create(BigInteger primeValue, RandomNumberGenerator rando
146146
/// <param name="x">The <see cref="System.Numerics.BigInteger"/> to multiply.</param>
147147
/// <param name="p">The <see cref="CompactCryptoGroupAlgebra.BigPrime"/> to multiply.</param>
148148
/// <returns>The <see cref="System.Numerics.BigInteger"/> that is <c>x</c> * <c>p</c>.</returns>
149-
public static BigInteger operator*(BigInteger x, BigPrime p)
149+
public static BigInteger operator *(BigInteger x, BigPrime p)
150150
{
151151
return x * p._value;
152152
}
@@ -158,7 +158,7 @@ public static BigPrime Create(BigInteger primeValue, RandomNumberGenerator rando
158158
/// <param name="p">The <see cref="CompactCryptoGroupAlgebra.BigPrime"/> to multiply.</param>
159159
/// <param name="x">The <see cref="System.Numerics.BigInteger"/> to multiply.</param>
160160
/// <returns>The <see cref="System.Numerics.BigInteger"/> that is <c>p</c> * <c>x</c>.</returns>
161-
public static BigInteger operator*(BigPrime p, BigInteger x)
161+
public static BigInteger operator *(BigPrime p, BigInteger x)
162162
{
163163
return x * p._value;
164164
}

CompactCryptoGroupAlgebra/CryptoGroupElement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace CompactCryptoGroupAlgebra
3838
/// <typeparam name="TElement">
3939
/// The data type used for raw group elements the algebraic operations operate on.
4040
/// </typeparam>
41-
public class CryptoGroupElement<TScalar, TElement> where TScalar : notnull where TElement: notnull
41+
public class CryptoGroupElement<TScalar, TElement> where TScalar : notnull where TElement : notnull
4242
{
4343
/// <summary>
4444
/// Accessor to the <see cref="ICryptoGroupAlgebra{TScalar, TElement}"/> that provides
@@ -64,7 +64,7 @@ public class CryptoGroupElement<TScalar, TElement> where TScalar : notnull where
6464
protected internal CryptoGroupElement(TElement value, ICryptoGroupAlgebra<TScalar, TElement> groupAlgebra)
6565
{
6666
Algebra = groupAlgebra;
67-
67+
6868
if (!Algebra.IsPotentialElement(value))
6969
throw new ArgumentException("The provided value is not a valid element of the group.", nameof(value));
7070
Value = value;

CompactCryptoGroupAlgebra/EllipticCurves/CurveGroupAlgebra.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace CompactCryptoGroupAlgebra.EllipticCurves
2525
{
26-
26+
2727
/// <summary>
2828
/// Cryptographic group based on point addition in elliptic curves.
2929
///
@@ -35,7 +35,7 @@ namespace CompactCryptoGroupAlgebra.EllipticCurves
3535
/// </summary>
3636
public sealed class CurveGroupAlgebra : CryptoGroupAlgebra<CurvePoint>
3737
{
38-
38+
3939
private readonly CurveEquation _curveEquation;
4040
private BigIntegerField Field { get { return _curveEquation.Field; } }
4141

@@ -58,7 +58,7 @@ public CurveGroupAlgebra(CurveParameters parameters)
5858
_curveEquation = parameters.Equation;
5959
if (!IsSafeElement(Generator))
6060
throw new ArgumentException("The point given as generator is " +
61-
"not a valid point on the curve.", nameof(parameters));
61+
"not a valid point on the curve.", nameof(parameters));
6262
}
6363

6464
/// <summary>

CompactCryptoGroupAlgebra/EllipticCurves/CurveParameters.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ BigInteger cofactor
9191
0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
9292
0x00 // extra 0 to ensure positivity
9393
})), // 115792089210356248762697446949407573530086143415290314195533631308867097853951
94-
a: new BigInteger(-3),
95-
b: new BigInteger(new byte[] {
94+
a: new BigInteger(-3),
95+
b: new BigInteger(new byte[] {
9696
0x4b, 0x60, 0xd2, 0x27, 0x3e, 0x3c, 0xce, 0x3b,
9797
0xf6, 0xb0, 0x53, 0xcc, 0xb0, 0x06, 0x1d, 0x65,
9898
0xbc, 0x86, 0x98, 0x76, 0x55, 0xbd, 0xeb, 0xb3,
@@ -276,8 +276,8 @@ BigInteger cofactor
276276
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
277277
0x00 // extra 0 to ensure positivity
278278
})), // 2^255 - 19
279-
a: new BigInteger(486662),
280-
b: BigInteger.One
279+
a: new BigInteger(486662),
280+
b: BigInteger.One
281281
),
282282
generator: new CurvePoint(
283283
new BigInteger(9),
@@ -373,7 +373,7 @@ BigInteger cofactor
373373
generator: new CurvePoint(
374374
new BigInteger(5),
375375
new BigInteger(new byte[] {
376-
0xa5, 0x6f, 0x05, 0xaf, 0x64, 0x0a, 0xe3, 0x95,
376+
0xa5, 0x6f, 0x05, 0xaf, 0x64, 0x0a, 0xe3, 0x95,
377377
0xa8, 0x93, 0x20, 0x54, 0xca, 0xdb, 0xf1, 0xe9,
378378
0xab, 0x40, 0x59, 0x45, 0xc4, 0x8a, 0x30, 0x49,
379379
0xbf, 0x3d, 0xa4, 0xe8, 0x29, 0x94, 0x2b, 0x42,

CompactCryptoGroupAlgebra/EllipticCurves/CurvePoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public CurvePoint Clone()
8989
{
9090
return new CurvePoint(X, Y, IsAtInfinity);
9191
}
92-
92+
9393
/// <summary>
9494
/// Creates a string representation of this point for displaying.
9595
/// </summary>

CompactCryptoGroupAlgebra/EllipticCurves/MontgomeryCurveEquation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public override CurvePoint Add(CurvePoint left, CurvePoint right)
4949
BigInteger lambda;
5050
if (left.Equals(right))
5151
{
52-
lambda = Field.Mod((3 * Field.Square(x1) + 2 * A * x1+ 1) * Field.InvertMult(2 * B * y1));
52+
lambda = Field.Mod((3 * Field.Square(x1) + 2 * A * x1 + 1) * Field.InvertMult(2 * B * y1));
5353
}
5454
else
5555
{

CompactCryptoGroupAlgebra/EllipticCurves/WeierstrassCurveEquation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public override CurvePoint Add(CurvePoint left, CurvePoint right)
4949
BigInteger lambda;
5050
if (left.Equals(right))
5151
{
52-
lambda = Field.Mod((3 * Field.Square(x1) + A) * Field.InvertMult(2 * y1));;
52+
lambda = Field.Mod((3 * Field.Square(x1) + A) * Field.InvertMult(2 * y1));
5353
}
5454
else
5555
{

CompactCryptoGroupAlgebra/EllipticCurves/XOnlyMontgomeryCurveAlgebra.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace CompactCryptoGroupAlgebra.EllipticCurves
2525
{
26-
26+
2727
/// <summary>
2828
/// Cryptographic group based on point addition in elliptic curves in Montgomery form
2929
/// using x-coordinate-only arithmetics on projected coordinates.
@@ -162,8 +162,8 @@ private MontgomeryCurvePoint RenormalizePoint(MontgomeryCurvePoint point)
162162
public override BigInteger Add(BigInteger left, BigInteger right)
163163
{
164164
throw new NotSupportedException("An x-only Montgomery curve " +
165-
"has no definition for the standard addition. Use the " +
166-
"standard Montgomery curve implementation instead.");
165+
"has no definition for the standard addition. Use the " +
166+
"standard Montgomery curve implementation instead.");
167167
}
168168

169169
/// <inheritdoc/>
@@ -182,15 +182,15 @@ public override byte[] ToBytes(BigInteger element)
182182
public override BigInteger Negate(BigInteger point)
183183
{
184184
throw new NotSupportedException("An x-only Montgomery curve " +
185-
"has no definition for the standard negation. Use the " +
186-
"standard Montgomery curve implementation instead.");
185+
"has no definition for the standard negation. Use the " +
186+
"standard Montgomery curve implementation instead.");
187187
}
188188

189189
/// <inheritdoc/>
190190
protected override bool IsElementDerived(BigInteger point)
191191
{
192192
return Field.IsElement(point);
193-
193+
194194
// In Montgomery form, every x coordinate corresponds to a valid
195195
// point either on the curve or on its twist, i.e., another valid
196196
// curve. We do not really care about which of these two we compute

CompactCryptoGroupAlgebra/Multiplicative/MultiplicativeGroupAlgebra.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public static int ComputeSecurityLevel(BigPrime prime, BigPrime order)
6666
// (cf.L. Grémy, Sieve Algorithms for the Discrete Logarithm in Medium Characteristic Finite Fields,
6767
// https://tel.archives-ouvertes.fr/tel-01647623/document )
6868

69-
double natLogSieveLevel = sieveConstant * Math.Pow(natLogPrime, 1.0/3.0) * Math.Pow(Math.Log(natLogPrime), 2.0/3.0);
70-
int sieveLevel = (int)(natLogSieveLevel/Math.Log(2));
69+
double natLogSieveLevel = sieveConstant * Math.Pow(natLogPrime, 1.0 / 3.0) * Math.Pow(Math.Log(natLogPrime), 2.0 / 3.0);
70+
int sieveLevel = (int)(natLogSieveLevel / Math.Log(2));
7171

7272
// pollard rho strength
7373
int rhoLevel = NumberLength.GetLength(order).InBits * 2;
@@ -88,18 +88,18 @@ public static NumberLength ComputePrimeLengthForSecurityLevel(int securityLevel)
8888
{
8989
// find minimum bit length l for Number field sieve
9090
// 1. solve number field sieve for z = ln ln (2^l) via Newton method
91-
double c = Math.Log(2)*securityLevel/1.9;
91+
double c = Math.Log(2) * securityLevel / 1.9;
9292
Func<double, double> f = (double z) =>
93-
c - Math.Exp((1.0/3.0) * z) * Math.Pow(z, 2.0/3.0);
94-
Func<double, double> df1 = (double z) =>
95-
-Math.Exp((1.0/3.0) * z) * ((1.0/3.0) * Math.Pow(z, 2.0/3.0) + 2.0/(3.0 * Math.Pow(z, 1.0/3.0)));
93+
c - Math.Exp((1.0 / 3.0) * z) * Math.Pow(z, 2.0 / 3.0);
94+
Func<double, double> df1 = (double z) =>
95+
-Math.Exp((1.0 / 3.0) * z) * ((1.0 / 3.0) * Math.Pow(z, 2.0 / 3.0) + 2.0 / (3.0 * Math.Pow(z, 1.0 / 3.0)));
9696

9797
double[] z = new double[] { Math.Log(20 * securityLevel), double.PositiveInfinity };
9898
int i = 0;
99-
while (Math.Abs(z[1-i] - z[i]) > 1e-7)
99+
while (Math.Abs(z[1 - i] - z[i]) > 1e-7)
100100
{
101-
z[1 - i] = z[i] - f(z[i]) / df1(z[i]);
102-
i = 1-i;
101+
z[1 - i] = z[i] - f(z[i]) / df1(z[i]);
102+
i = 1 - i;
103103
}
104104
// 2. compute l from z
105105
int l = (int)Math.Ceiling(Math.Exp(z[i]) / Math.Log(2));
@@ -230,6 +230,6 @@ public static CryptoGroup<BigInteger, BigInteger> CreateCryptoGroup(int security
230230

231231
return new CryptoGroup<BigInteger, BigInteger>(groupAlgebra);
232232
}
233-
233+
234234
}
235235
}

CompactCryptoGroupAlgebra/PrimalityTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,18 @@ public static bool IsCompositeWitness(BigInteger a, BigInteger q, int k)
6565

6666
/// <summary>
6767
/// Checks whether a given <paramref name="n"/> is a prime number.
68-
///
68+
///
6969
/// Implements the Miller-Rabin primality test, which is a probabilistic
7070
/// algorithm. If the given <paramref name="n"/> is a prime,
7171
/// <see cref="IsProbablyPrime(BigInteger, RandomNumberGenerator, double)"/>
7272
/// will always return <c>true</c>, but if <paramref name="n"/> is
7373
/// a composite number, the algorithm may return <c>true</c> with probability
7474
/// less than <paramref name="errorProbability"/>.
7575
/// </summary>
76-
/// <returns><c>true</c>, if probably prime was ???, <c>false</c> otherwise.</returns>
7776
/// <param name="n">The number to check for primality.</param>
7877
/// <param name="randomNumberGenerator">Random number generator instance.</param>
79-
/// <param name="errorProbability">Acceptable probability of <c>true</c>
80-
/// being returns if <paramref name="n"/> is composite.</param>
78+
/// <param name="errorProbability">Acceptable probability of <c>true</c> being returned when <paramref name="n"/> is actually not a prime.</param>
79+
/// <returns><c>true</c>, if <paramref name="n"/> is prime with probability 1 - <paramref name="errorProbability"/>, <c>false</c> otherwise.</returns>
8180
public static bool IsProbablyPrime(
8281
this BigInteger n, RandomNumberGenerator randomNumberGenerator, double errorProbability = 1e-10
8382
)

0 commit comments

Comments
 (0)