This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove Interface static * Create math instance methods * Fix name * Remove statics from IMillerLoopDriver * Avoid losing different public extensions * Add AggressiveInlining * Prevent to lose some public static methods
- Loading branch information
Showing
10 changed files
with
134 additions
and
27 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
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 |
---|---|---|
@@ -1,37 +1,59 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Neo.Cryptography.BLS12_381; | ||
|
||
interface INumber<T> where T : unmanaged, INumber<T> | ||
{ | ||
static abstract int Size { get; } | ||
static abstract ref readonly T Zero { get; } | ||
static abstract ref readonly T One { get; } | ||
//static abstract int Size { get; } | ||
//static abstract ref readonly T Zero { get; } | ||
//static abstract ref readonly T One { get; } | ||
|
||
//static abstract T operator -(in T x); | ||
//static abstract T operator +(in T x, in T y); | ||
//static abstract T operator -(in T x, in T y); | ||
//static abstract T operator *(in T x, in T y); | ||
|
||
static abstract T operator -(in T x); | ||
static abstract T operator +(in T x, in T y); | ||
static abstract T operator -(in T x, in T y); | ||
static abstract T operator *(in T x, in T y); | ||
T Negate(); | ||
T Sum(in T value); | ||
T Subtract(in T value); | ||
T Multiply(in T value); | ||
|
||
abstract T Square(); | ||
} | ||
|
||
static class NumberExtensions | ||
{ | ||
public static T PowVartime<T>(this T self, ulong[] by) where T : unmanaged, INumber<T> | ||
private static T PowVartime<T>(T one, T self, ulong[] by) where T : unmanaged, INumber<T> | ||
{ | ||
// Although this is labeled "vartime", it is only | ||
// variable time with respect to the exponent. | ||
var res = T.One; | ||
var res = one; | ||
for (int j = by.Length - 1; j >= 0; j--) | ||
{ | ||
for (int i = 63; i >= 0; i--) | ||
{ | ||
res = res.Square(); | ||
if (((by[j] >> i) & 1) == 1) | ||
{ | ||
res *= self; | ||
res = res.Multiply(self); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Fp PowVartime(this Fp self, ulong[] by) => PowVartime(Fp.One, self, by); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Fp2 PowVartime(this Fp2 self, ulong[] by) => PowVartime(Fp2.One, self, by); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Fp6 PowVartime(this Fp6 self, ulong[] by) => PowVartime(Fp6.One, self, by); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Fp12 PowVartime(this Fp12 self, ulong[] by) => PowVartime(Fp12.One, self, by); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Scalar PowVartime(this Scalar self, ulong[] by) => PowVartime(Scalar.One, self, by); | ||
} |
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