本文整理汇总了C++中BigInteger::invm方法的典型用法代码示例。如果您正苦于以下问题:C++ BigInteger::invm方法的具体用法?C++ BigInteger::invm怎么用?C++ BigInteger::invm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigInteger
的用法示例。
在下文中一共展示了BigInteger::invm方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doublePoint
ECPoint ECCurve::doublePoint(ECPoint &p)
{
if (p.isPointAtInfinity()) {
return p;
}
BigInteger px = p.getX();
BigInteger py = p.getY();
BigInteger rx;
BigInteger ry;
// 1 / 2py
BigInteger yInv = (py + py) % _p;
yInv = yInv.invm(_p);
// 3 * px^2 + a
BigInteger s = ((((px * px) * 3) + _a) * yInv) % _p;
// rx = s^2 - 2px
rx = (s * s - px - px) % _p;
// ry = -py + s(px - rx)
ry = (s * (px - rx) - py) % _p;
return ECPoint(rx, ry);
}
示例2: toAffine
ECPoint ECCurve::toAffine(ECPointJacobian &p)
{
BigInteger z = p.getZ();
BigInteger zInv = z.invm(_p);
BigInteger z2Inv = (zInv * zInv) % _p;
BigInteger z3Inv = (z2Inv * zInv) % _p;
BigInteger x = p.getX();
BigInteger y = p.getY();
return ECPoint((x * z2Inv) % _p, (y * z3Inv) % _p);
}
示例3: addPoint
ECPoint ECCurve::addPoint(ECPoint &p, ECPoint &q)
{
BigInteger rx;
BigInteger ry;
BigInteger px = p.getX();
BigInteger py = p.getY();
BigInteger qx = q.getX();
BigInteger qy = q.getY();
// Px == Qx && Py == Qy
if (p == q) {
return doublePoint(p);
}
// Px == Qx && Py != Qy
if (px == qx) {
return ECPoint();
}
if (p.isPointAtInfinity()) {
return q;
}
if (q.isPointAtInfinity()) {
return p;
}
// s = (py - qy)/(px - qx)
BigInteger rise = (py - qy) % _p;
BigInteger run = (px - qx) % _p;
BigInteger s = (run.invm(_p) * rise) % _p;
// rx = s^2 - px - qx
rx = (s*s - px - qx) % _p;
// ry = -py + s(px - rx)
ry = (s * (px - rx) - py) % _p;
return ECPoint(rx, ry);
}