Exemplo n.º 1
0
            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())));
            }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
            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())));
            }
Exemplo n.º 4
0
 /**
  * Formally we have to do this check but in our domain it's not necessary, thus always return
  * true
  */
 private static bool IsGroupMember(BN128 <Fp> p)
 {
     return(true);
 }
Exemplo n.º 5
0
 public BN128G1(BN128 <Fp> p) : base(p.x, p.y, p.z)
 {
 }