Skip to content

Commit

Permalink
Add a new modinv constant for field elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Dec 25, 2023
1 parent f54ce29 commit 2a3ab50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ public ModInv32ModInfo(in ModInv32Signed30 mod, uint modinv30)
public readonly ModInv32Signed30 modulus;
public readonly uint modulus_inv30;

private static readonly ModInv32ModInfo _const = new ModInv32ModInfo(
private static readonly ModInv32ModInfo _scConst = new ModInv32ModInfo(
new ModInv32Signed30(0x10364141, 0x3F497A33, 0x348A03BB, 0x2BB739AB, -0x146, 0, 0, 0, 65536),
0x2A774EC1U);
// secp256k1_const_modinfo_scalar
internal static ref readonly ModInv32ModInfo Constant => ref _const;
/// <summary>
/// secp256k1_const_modinfo_scalar
/// </summary>
internal static ref readonly ModInv32ModInfo ScalarConstant => ref _scConst;

private static readonly ModInv32ModInfo _feConst = new ModInv32ModInfo(
new ModInv32Signed30(-0x3D1, -4, 0, 0, 0, 0, 0, 0, 65536),
0x2DDACACF);
/// <summary>
/// secp256k1_const_modinfo_fe
/// </summary>
internal static ref readonly ModInv32ModInfo FeConstant => ref _feConst;
}

internal class ModInv32Trans2x2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public Scalar8x32 Inverse()
#endif
ModInv32Signed30 s = new ModInv32Signed30(this);
// secp256k1_modinv32(&s, &secp256k1_const_modinfo_scalar);
ModInv32.Compute(ref s, ModInv32ModInfo.Constant);
ModInv32.Compute(ref s, ModInv32ModInfo.ScalarConstant);
Scalar8x32 r = s.ToScalar8x32();
#if DEBUG
Debug.Assert(r.Verify());
Expand All @@ -575,7 +575,7 @@ public Scalar8x32 InverseVar()
bool zero_in = IsZero;
#endif
ModInv32Signed30 s = new ModInv32Signed30(this);
ModInv32.ComputeVar(ref s, ModInv32ModInfo.Constant);
ModInv32.ComputeVar(ref s, ModInv32ModInfo.ScalarConstant);
Scalar8x32 r = s.ToScalar8x32();

#if DEBUG
Expand Down

0 comments on commit 2a3ab50

Please sign in to comment.