public override KeyValuePair <bool, byte[]> Execute(byte[] data)
            {
                if (data == null)
                {
                    data = new byte[0];
                }

                byte[] x1 = ByteUtil.ParseWord(data, 0);
                byte[] y1 = ByteUtil.ParseWord(data, 1);

                byte[] x2 = ByteUtil.ParseWord(data, 2);
                byte[] y2 = ByteUtil.ParseWord(data, 3);

                BN128 <Fp> p1 = BN128Fp.Create(x1, y1);

                if (p1 == null)
                {
                    return(new KeyValuePair <bool, byte[]>(false, new byte[0]));
                }

                BN128 <Fp> p2 = BN128Fp.Create(x2, y2);

                if (p2 == null)
                {
                    return(new KeyValuePair <bool, byte[]>(false, new byte[0]));
                }

                BN128 <Fp> res = p1.Add(p2).ToEthNotation();

                return(new KeyValuePair <bool, byte[]>(true, EncodeRes(res.x.Bytes(), res.y.Bytes())));
            }
示例#2
0
        /**
         * Checks whether point is a member of subgroup, returns a point if check has been passed and null
         * otherwise
         */
        public static BN128G1 Create(byte[] x, byte[] y)
        {
            BN128 <Fp> p = BN128Fp.Create(x, y);

            if (p == null)
            {
                return(null);
            }

            if (!IsGroupMember(p))
            {
                return(null);
            }

            return(new BN128G1(p));
        }
示例#3
0
        /**
         * Checks whether x and y belong to Fp, then checks whether point with (x; y) coordinates lays on
         * the curve.
         *
         * Returns new point if all checks have been passed, otherwise returns null
         */
        public static BN128 <Fp> Create(byte[] xx, byte[] yy)
        {
            Fp x = Fp.Create(xx);
            Fp y = Fp.Create(yy);

            // check for point at infinity
            if (x.IsZero() && y.IsZero())
            {
                return(ZERO);
            }

            BN128 <Fp> p = new BN128Fp(x, y, Fp._1);

            // check whether point is a valid one
            if (p.IsValid())
            {
                return(p);
            }
            else
            {
                return(null);
            }
        }
            public override KeyValuePair <bool, byte[]> Execute(byte[] data)
            {
                if (data == null)
                {
                    data = new byte[0];
                }

                byte[] x = ByteUtil.ParseWord(data, 0);
                byte[] y = ByteUtil.ParseWord(data, 1);

                byte[] s = ByteUtil.ParseWord(data, 2);

                BN128 <Fp> p = BN128Fp.Create(x, y);

                if (p == null)
                {
                    return(new KeyValuePair <bool, byte[]>(false, new byte[0]));
                }

                BN128 <Fp> res = p.Mul(new Org.BouncyCastle.Math.BigInteger(1, s)).ToEthNotation();

                return(new KeyValuePair <bool, byte[]>(true, EncodeRes(res.x.Bytes(), res.y.Bytes())));
            }