本文整理汇总了C#中Org.BouncyCastle.Math.EC.ECPoint.Multiply方法的典型用法代码示例。如果您正苦于以下问题:C# ECPoint.Multiply方法的具体用法?C# ECPoint.Multiply怎么用?C# ECPoint.Multiply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Math.EC.ECPoint
的用法示例。
在下文中一共展示了ECPoint.Multiply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SumOfTwoMultiplies
public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a, ECPoint Q, BigInteger b)
{
ECCurve cp = P.Curve;
Q = ImportPoint(cp, Q);
// Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick
if (cp is F2mCurve)
{
F2mCurve f2mCurve = (F2mCurve) cp;
if (f2mCurve.IsKoblitz)
{
return P.Multiply(a).Add(Q.Multiply(b));
}
}
return ImplShamirsTrickWNaf(P, a, Q, b);
}
示例2: SumOfTwoMultiplies
public static ECPoint SumOfTwoMultiplies(ECPoint p, IBigInteger a, ECPoint q, IBigInteger b)
{
var c = p.Curve;
if (!c.Equals(q.Curve))
throw new ArgumentException("P and Q must be on same curve");
// Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick
var f2MCurve = c as F2MCurve;
if (f2MCurve != null)
{
if (f2MCurve.IsKoblitz)
{
return p.Multiply(a).Add(q.Multiply(b));
}
}
return ImplShamirsTrick(p, a, q, b);
}
示例3: SumOfTwoMultiplies
public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a,
ECPoint Q, BigInteger b)
{
ECCurve c = P.Curve;
if (!c.Equals(Q.Curve))
throw new ArgumentException("P and Q must be on same curve");
// Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick
if (c is F2mCurve)
{
F2mCurve f2mCurve = (F2mCurve) c;
if (f2mCurve.IsKoblitz)
{
return P.Multiply(a).Add(Q.Multiply(b));
}
}
return ImplShamirsTrick(P, a, Q, b);
}
示例4: SumOfTwoMultiplies
public static ECPoint SumOfTwoMultiplies(ECPoint P, BigInteger a, ECPoint Q, BigInteger b)
{
ECCurve cp = P.Curve;
Q = ImportPoint(cp, Q);
// Point multiplication for Koblitz curves (using WTNAF) beats Shamir's trick
if (cp is F2mCurve)
{
F2mCurve f2mCurve = (F2mCurve) cp;
if (f2mCurve.IsKoblitz)
{
return P.Multiply(a).Add(Q.Multiply(b));
}
}
GlvEndomorphism glvEndomorphism = cp.GetEndomorphism() as GlvEndomorphism;
if (glvEndomorphism != null)
{
return ImplSumOfMultipliesGlv(new ECPoint[] { P, Q }, new BigInteger[] { a, b }, glvEndomorphism);
}
return ImplShamirsTrickWNaf(P, a, Q, b);
}
示例5: PrivHexToPubHex
public static string PrivHexToPubHex(string PrivHex, ECPoint point)
{
byte[] hex = ValidateAndGetHexPrivateKey(0x00, PrivHex, 33);
if (hex == null) throw new ApplicationException("Invalid private hex key");
Org.BouncyCastle.Math.BigInteger Db = new Org.BouncyCastle.Math.BigInteger(hex);
ECPoint dd = point.Multiply(Db);
byte[] pubaddr = PubKeyToByteArray(dd);
return ByteArrayToString(pubaddr);
}
示例6: ImplTestMultiplyAll
/**
* Checks, if the point multiplication algorithm of the given point yields
* the same result as point multiplication done by the reference
* implementation given in <code>multiply()</code>. This method tests
* multiplication of <code>p</code> by every number of bitlength
* <code>numBits</code> or less.
*
* @param p
* The point to be multiplied.
* @param numBits
* Try every multiplier up to this bitlength
*/
private void ImplTestMultiplyAll(ECPoint p, int numBits)
{
BigInteger bound = BigInteger.One.ShiftLeft(numBits);
BigInteger k = BigInteger.Zero;
do
{
ECPoint reff = Multiply(p, k);
ECPoint q = p.Multiply(k);
AssertPointsEqual("ECPoint.Multiply is incorrect", reff, q);
k = k.Add(BigInteger.One);
}
while (k.CompareTo(bound) < 0);
}
示例7: ImplTestMultiply
/**
* Checks, if the point multiplication algorithm of the given point yields
* the same result as point multiplication done by the reference
* implementation given in <code>multiply()</code>. This method chooses a
* random number by which the given point <code>p</code> is multiplied.
*
* @param p
* The point to be multiplied.
* @param numBits
* The bitlength of the random number by which <code>p</code>
* is multiplied.
*/
private void ImplTestMultiply(ECPoint p, int numBits)
{
BigInteger k = new BigInteger(numBits, secRand);
ECPoint reff = Multiply(p, k);
ECPoint q = p.Multiply(k);
AssertPointsEqual("ECPoint.Multiply is incorrect", reff, q);
}
示例8: ImplTestAllPoints
/**
* Goes through all points on an elliptic curve and checks, if adding a
* point <code>k</code>-times is the same as multiplying the point by
* <code>k</code>, for all <code>k</code>. Should be called for points
* on very small elliptic curves only.
*
* @param p
* The base point on the elliptic curve.
* @param infinity
* The point at infinity on the elliptic curve.
*/
private void ImplTestAllPoints(ECPoint p, ECPoint infinity)
{
ECPoint adder = infinity;
ECPoint multiplier = infinity;
BigInteger i = BigInteger.One;
do
{
adder = adder.Add(p);
multiplier = p.Multiply(i);
AssertPointsEqual("Results of Add() and Multiply() are inconsistent " + i, adder, multiplier);
i = i.Add(BigInteger.One);
}
while (!(adder.Equals(infinity)));
}
示例9: CalculateAgreement
internal static BigInteger CalculateAgreement (ECPoint q, BigInteger d)
{
ECPoint p = q.Multiply (d);
// if ( p.IsInfinity ) throw new Exception("d*Q == infinity");
return p.X.ToBigInteger();
}
示例10: RandMult
private double RandMult(SecureRandom random, ECPoint g, BigInteger n)
{
BigInteger[] ks = new BigInteger[128];
for (int i = 0; i < ks.Length; ++i)
{
ks[i] = new BigInteger(n.BitLength - 1, random);
}
int ki = 0;
ECPoint p = g;
for (int i = 1; i <= PRE_ROUNDS; i++)
{
for (int j = 0; j < MULTS_PER_ROUND; ++j)
{
BigInteger k = ks[ki];
p = g.Multiply(k);
if ((ki & 1) != 0)
{
g = p;
}
if (++ki == ks.Length)
{
ki = 0;
}
}
}
double minElapsed = Double.MaxValue, maxElapsed = Double.MinValue, totalElapsed = 0.0;
for (int i = 1; i <= NUM_ROUNDS; i++)
{
long startTime = DateTimeUtilities.CurrentUnixMs();
for (int j = 0; j < MULTS_PER_ROUND; ++j)
{
BigInteger k = ks[ki];
p = g.Multiply(k);
if ((ki & 1) != 0)
{
g = p;
}
if (++ki == ks.Length)
{
ki = 0;
}
}
long endTime = DateTimeUtilities.CurrentUnixMs();
double roundElapsed = (double)(endTime - startTime);
minElapsed = System.Math.Min(minElapsed, roundElapsed);
maxElapsed = System.Math.Max(maxElapsed, roundElapsed);
totalElapsed += roundElapsed;
}
return (totalElapsed - minElapsed - maxElapsed) / (NUM_ROUNDS - 2) / MULTS_PER_ROUND;
}
示例11: RandMult
private double RandMult(SecureRandom random, ECPoint g, BigInteger n)
{
BigInteger[] ks = new BigInteger[128];
for (int i = 0; i < ks.Length; ++i)
{
ks[i] = new BigInteger(n.BitLength - 1, random);
}
int ki = 0;
ECPoint p = g;
{
long startTime = DateTimeUtilities.CurrentUnixMs();
long goalTime = startTime + MILLIS_WARMUP;
do
{
BigInteger k = ks[ki];
p = g.Multiply(k);
if ((ki & 1) != 0)
{
g = p;
}
if (++ki == ks.Length)
{
ki = 0;
}
}
while (DateTimeUtilities.CurrentUnixMs() < goalTime);
}
double minRate = Double.MaxValue, maxRate = Double.MinValue, totalRate = 0.0;
for (int i = 1; i <= NUM_ROUNDS; i++)
{
long startTime = DateTimeUtilities.CurrentUnixMs();
long goalTime = startTime + MILLIS_PER_ROUND;
long count = 0, endTime;
do
{
++count;
for (int j = 0; j < MULTS_PER_CHECK; ++j)
{
BigInteger k = ks[ki];
p = g.Multiply(k);
if ((ki & 1) != 0)
{
g = p;
}
if (++ki == ks.Length)
{
ki = 0;
}
}
endTime = DateTimeUtilities.CurrentUnixMs();
}
while (endTime < goalTime);
double roundElapsed = (double)(endTime - startTime);
double roundRate = count * MULTS_PER_CHECK * 1000L / roundElapsed;
minRate = System.Math.Min(minRate, roundRate);
maxRate = System.Math.Max(maxRate, roundRate);
totalRate += roundRate;
}
return (totalRate - minRate - maxRate) / (NUM_ROUNDS - 2);
}
示例12: implTestMultiplyAll
/**
* Checks, if the point multiplication algorithm of the given point yields
* the same result as point multiplication done by the reference
* implementation given in <code>multiply()</code>. This method tests
* multiplication of <code>p</code> by every number of bitlength
* <code>numBits</code> or less.
*
* @param p
* The point to be multiplied.
* @param numBits
* Try every multiplier up to this bitlength
*/
private void implTestMultiplyAll(ECPoint p, int numBits)
{
BigInteger bound = BigInteger.Two.Pow(numBits);
BigInteger k = BigInteger.Zero;
do
{
ECPoint reff = multiply(p, k);
ECPoint q = p.Multiply(k);
Assert.AreEqual(reff, q, "ECPoint.multiply is incorrect");
k = k.Add(BigInteger.One);
}
while (k.CompareTo(bound) < 0);
}
示例13: implTestMultiply
/**
* Checks, if the point multiplication algorithm of the given point yields
* the same result as point multiplication done by the reference
* implementation given in <code>multiply()</code>. This method chooses a
* random number by which the given point <code>p</code> is multiplied.
*
* @param p
* The point to be multiplied.
* @param numBits
* The bitlength of the random number by which <code>p</code>
* is multiplied.
*/
private void implTestMultiply(ECPoint p, int numBits)
{
BigInteger k = new BigInteger(numBits, secRand);
ECPoint reff = multiply(p, k);
ECPoint q = p.Multiply(k);
Assert.AreEqual(reff, q, "ECPoint.multiply is incorrect");
}
示例14: implTestAllPoints
/**
* Goes through all points on an elliptic curve and checks, if adding a
* point <code>k</code>-times is the same as multiplying the point by
* <code>k</code>, for all <code>k</code>. Should be called for points
* on very small elliptic curves only.
*
* @param p
* The base point on the elliptic curve.
* @param infinity
* The point at infinity on the elliptic curve.
*/
private void implTestAllPoints(ECPoint p, ECPoint infinity)
{
ECPoint adder = infinity;
ECPoint multiplier = infinity;
int i = 1;
do
{
adder = adder.Add(p);
multiplier = p.Multiply(new BigInteger(i.ToString()));
Assert.AreEqual(adder, multiplier,
"Results of add() and multiply() are inconsistent " + i);
i++;
}
while (!(adder.Equals(infinity)));
}
示例15: ExtractUsersPrivateKey
private BigInteger ExtractUsersPrivateKey(
ECPoint G, BigInteger N,
string message1,
string message2,
BigInteger r1, BigInteger s1,
BigInteger r2, BigInteger s2,
BigInteger attackersPrivate, ECPoint attackersPublic,
ECPoint usersPublic)
{
var m1 = new BigInteger(1, Hash(Encoding.UTF8.GetBytes(message1))); // hash of m1
var m2 = new BigInteger(1, Hash(Encoding.UTF8.GetBytes(message2))); // hash of m2
//calculate the result of verifying signature 1
var w = s1.ModInverse(N);
var u1 = m1.Multiply(w).Mod(N);
var u2 = r1.Multiply(w).Mod(N);
var verifyPoint = ECAlgorithms.SumOfTwoMultiplies(G, u1, usersPublic, u2).Normalize();
//reinit K calculator to reproduce a,b,h,e
var kCalc = new RandomDsaKCalculator();
kCalc.Init(N, new SecureRandom(new SeededGenerator(Hash(Encoding.UTF8.GetBytes(message2)))));
var a = kCalc.NextK();
var b = kCalc.NextK();
var h = kCalc.NextK();
var e = kCalc.NextK();
var Z1 = verifyPoint.Multiply(a).Add(verifyPoint.Multiply(attackersPrivate).Multiply(b));
//cycle through all possible j & u
for (int i = 0; i < 2; i++)
for (int l = 0; l < 2; l++)
{
var j = new BigInteger(i.ToString());
var u = new BigInteger(l.ToString());
var Z2 = Z1.Add(G.Multiply(j).Multiply(h)).Add(attackersPublic.Multiply(u).Multiply(e)).Normalize();
var zX = Z2.AffineXCoord.ToBigInteger().ToByteArray();
var hash = Hash(zX);
var kCandidate = new BigInteger(1, hash);
var verifyPointCandidate = G.Multiply(kCandidate).Normalize();
var rCandidate = verifyPointCandidate.AffineXCoord.ToBigInteger().Mod(N);
if (rCandidate.Equals(r2)) // Gotcha!
{
return s2.Multiply(kCandidate).Subtract(m2).Multiply(r2.ModInverse(N)).Mod(N);
}
}
return null;
}