예제 #1
0
        public ECC521Point Multiply(BigInteger b)
        {
            if (b.Sign == -1)
            {
                throw new FormatException("The multiplicator cannot be negative");
            }
            if (b >= OrderN)
            {
                b %= OrderN;
            }
            BigInteger  exp      = (b * 3) ^ b;
            ECC521Point result   = ECC521Point.Infinity;
            ECC521Point affine   = this.Normalize();
            ECC521Point negative = affine.Negate();

            int        high = exp <= 0 ? 0 : (int)Math.Floor(BigInteger.Log(exp, 2));
            BigInteger bit  = BigInteger.One << high;

            for (int i = high; --i >= 0; bit >>= 1)
            {
                result = result.Twice();
                if (!(exp & bit).IsZero)
                {
                    result = result.Add(!(b & bit).IsZero ? negative : affine);
                }
            }

            result = result.Normalize();
            return(result);
        }
예제 #2
0
 public ECC521Point Subtract(ECC521Point b)
 {
     return(Add(b.Negate()));
 }