本文整理汇总了C#中System.Numerics.BigInteger.ModInverse方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.ModInverse方法的具体用法?C# BigInteger.ModInverse怎么用?C# BigInteger.ModInverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.ModInverse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySignature
public bool VerifySignature(byte[] message, BigInteger r, BigInteger s)
{
if (r.Sign < 1 || s.Sign < 1 || r.CompareTo(curve.N) >= 0 || s.CompareTo(curve.N) >= 0)
return false;
BigInteger e = CalculateE(curve.N, message);
BigInteger c = s.ModInverse(curve.N);
BigInteger u1 = (e * c).Mod(curve.N);
BigInteger u2 = (r * c).Mod(curve.N);
ECPoint point = SumOfTwoMultiplies(curve.G, u1, publicKey, u2);
BigInteger v = point.X.Value.Mod(curve.N);
return v.Equals(r);
}
示例2: RecoverFromSignature
public ECPoint RecoverFromSignature(byte[] hash, BigInteger r, BigInteger s, int recId)
{
var x = r;
if (recId > 1 && recId < 4)
{
x += Secp256k1.N;
x = x % Secp256k1.P;
}
if (x >= Secp256k1.P)
{
return null;
}
byte[] xBytes = x.ToByteArrayUnsigned(true);
byte[] compressedPoint = new Byte[33];
compressedPoint[0] = (byte)(0x02 + (recId % 2));
Buffer.BlockCopy(xBytes, 0, compressedPoint, 33 - xBytes.Length, xBytes.Length);
ECPoint publicKey = ECPoint.DecodePoint(compressedPoint);
if (!publicKey.Multiply(Secp256k1.N).IsInfinity) return null;
var z = -hash.ToBigIntegerUnsigned(true) % Secp256k1.N;
if (z < 0)
{
z += Secp256k1.N;
}
var rr = r.ModInverse(Secp256k1.N);
var u1 = (z * rr) % Secp256k1.N;
var u2 = (s * rr) % Secp256k1.N;
var Q = Secp256k1.G.Multiply(u1).Add(publicKey.Multiply(u2));
return Q;
}
示例3: VerifySignature
public static bool VerifySignature(byte[] message, BigInteger r, BigInteger s, ECPoint publicPoint)
{
var n = Secp256k1.N;
if (r.Sign < 1 || s.Sign < 1 || r >= n || s >= n)
return false;
var z = CalculateZ(message);
var w = s.ModInverse(n);
var u1 = (z * w) % n;
var u2 = (r * w) % n;
var G = Secp256k1.G;
var Q = publicPoint;
var C = u1 * G + u2 * Q;
if(C.IsInfinity) return false;
var Cmodn = C.X % n;
return Cmodn == r;
}
示例4: VerifySignature
public bool VerifySignature(ECPoint publicKey, byte[] hash, BigInteger r, BigInteger s)
{
if (r >= Secp256k1.N || r.IsZero || s >= Secp256k1.N || s.IsZero)
{
return false;
}
var z = hash.ToBigIntegerUnsigned(true);
var w = s.ModInverse(Secp256k1.N);
var u1 = (z * w) % Secp256k1.N;
var u2 = (r * w) % Secp256k1.N;
var pt = Secp256k1.G.Multiply(u1).Add(publicKey.Multiply(u2));
var pmod = pt.X % Secp256k1.N;
return pmod == r;
}