Skip to content

Commit 2a3ab50

Browse files
Add a new modinv constant for field elements
1 parent f54ce29 commit 2a3ab50

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Src/Autarkysoft.Bitcoin/Cryptography/EllipticCurve/ModInv32ModInfo.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ public ModInv32ModInfo(in ModInv32Signed30 mod, uint modinv30)
1616
public readonly ModInv32Signed30 modulus;
1717
public readonly uint modulus_inv30;
1818

19-
private static readonly ModInv32ModInfo _const = new ModInv32ModInfo(
19+
private static readonly ModInv32ModInfo _scConst = new ModInv32ModInfo(
2020
new ModInv32Signed30(0x10364141, 0x3F497A33, 0x348A03BB, 0x2BB739AB, -0x146, 0, 0, 0, 65536),
2121
0x2A774EC1U);
22-
// secp256k1_const_modinfo_scalar
23-
internal static ref readonly ModInv32ModInfo Constant => ref _const;
22+
/// <summary>
23+
/// secp256k1_const_modinfo_scalar
24+
/// </summary>
25+
internal static ref readonly ModInv32ModInfo ScalarConstant => ref _scConst;
26+
27+
private static readonly ModInv32ModInfo _feConst = new ModInv32ModInfo(
28+
new ModInv32Signed30(-0x3D1, -4, 0, 0, 0, 0, 0, 0, 65536),
29+
0x2DDACACF);
30+
/// <summary>
31+
/// secp256k1_const_modinfo_fe
32+
/// </summary>
33+
internal static ref readonly ModInv32ModInfo FeConstant => ref _feConst;
2434
}
2535

2636
internal class ModInv32Trans2x2

Src/Autarkysoft.Bitcoin/Cryptography/EllipticCurve/Scalar8x32.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public Scalar8x32 Inverse()
555555
#endif
556556
ModInv32Signed30 s = new ModInv32Signed30(this);
557557
// secp256k1_modinv32(&s, &secp256k1_const_modinfo_scalar);
558-
ModInv32.Compute(ref s, ModInv32ModInfo.Constant);
558+
ModInv32.Compute(ref s, ModInv32ModInfo.ScalarConstant);
559559
Scalar8x32 r = s.ToScalar8x32();
560560
#if DEBUG
561561
Debug.Assert(r.Verify());
@@ -575,7 +575,7 @@ public Scalar8x32 InverseVar()
575575
bool zero_in = IsZero;
576576
#endif
577577
ModInv32Signed30 s = new ModInv32Signed30(this);
578-
ModInv32.ComputeVar(ref s, ModInv32ModInfo.Constant);
578+
ModInv32.ComputeVar(ref s, ModInv32ModInfo.ScalarConstant);
579579
Scalar8x32 r = s.ToScalar8x32();
580580

581581
#if DEBUG

0 commit comments

Comments
 (0)