Exemple #1
0
 public BigInt ModInv(BigInt p, BigInt negP)
 {
     var u = this.Clone();
     var v = p.Clone();
     var x1 = new BigInt(1, p.Length);
     var x2 = new BigInt(0, p.Length);
     while (!u.IsOne() && !v.IsOne())
     {
         while (u.IsEven())
         {
             u.Div2Trunc();
             x1.Div2(p);
         }
         while (v.IsEven())
         {
             v.Div2Trunc();
             x2.Div2(p);
         }
         if (u >= v)
         {
             var uTmp = u;
             u = u.SubMod(v, p, negP);
             uTmp.Clear();
             var x1Tmp = x1;
             x1 = x1.SubMod(x2, p, negP);
             x1Tmp.Clear();
         }
         else
         {
             var vTmp = v;
             v = v.SubMod(u, p, negP);
             vTmp.Clear();
             var x2Tmp = x2;
             x2 = x2.SubMod(x1, p, negP);
             x2Tmp.Clear();
         }
     }
     v.Clear();
     if (u.IsOne())
     {
         u.Clear();
         x2.Clear();
         return x1;
     }
     else
     {
         u.Clear();
         x1.Clear();
         return x2;
     }
 }
Exemple #2
0
        EllipticCurve(BigInt p, BigInteger b, BigInteger q, BigInt xg, BigInt yg, Func<BigInt, BigInt> modp, int curveLen, byte[] asnName)
        {
            this.p = p;
            this.b = b;
            this.q = q;
            this.xg = xg;
            this.yg = yg;
            this.modp = modp;
            this.curveLen = curveLen;
            this.asnName = asnName;

            negP = p.Clone();
            BigInt.TwosComplement(negP._bits, negP._bits);
        }