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()))); }
/** * 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)); }
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()))); }