diff --git a/ffi/cs/mcl/mcl.cs b/ffi/cs/mcl/mcl.cs index 24fc55d..3897bd9 100644 --- a/ffi/cs/mcl/mcl.cs +++ b/ffi/cs/mcl/mcl.cs @@ -88,6 +88,7 @@ namespace mcl { [DllImport(dllName)] public static extern void mclBnG2_add(ref G2 z, in G2 x, in G2 y); [DllImport(dllName)] public static extern void mclBnG2_sub(ref G2 z, in G2 x, in G2 y); [DllImport(dllName)] public static extern void mclBnG2_mul(ref G2 z, in G2 x, in Fr y); + [DllImport(dllName)] public static extern void mclBnG2_mulVec(ref G2 z, [In] G2[] x, [In] Fr[] y, long n); [DllImport(dllName)] public static extern void mclBnGT_clear(ref GT x); [DllImport(dllName)] public static extern int mclBnGT_setStr(ref GT x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode); @@ -249,6 +250,14 @@ namespace mcl { { mclBnG2_normalize(ref y, x); } + public static void MulVec(ref G2 z, in G2[] x, in Fr[] y) + { + int n = x.Length; + if (n <= 0 || n != y.Length) { + throw new ArgumentException("bad length"); + } + mclBnG2_mulVec(ref z, x, y, (long)n); + } public static void Add(ref GT z, in GT x, in GT y) { mclBnGT_add(ref z, x, y); diff --git a/ffi/cs/test/test.cs b/ffi/cs/test/test.cs index 2972cc8..19b0e2f 100644 --- a/ffi/cs/test/test.cs +++ b/ffi/cs/test/test.cs @@ -210,6 +210,20 @@ namespace mcl { Q.Deserialize(buf); assert("P == Q", P.Equals(Q)); } + { + const int n = 5; + G2[] xVec = new G2[n]; + Fr[] yVec = new Fr[n]; + P.Clear(); + for (int i = 0; i < n; i++) { + xVec[i].HashAndMapTo(i.ToString()); + yVec[i].SetByCSPRNG(); + Q.Mul(xVec[i], yVec[i]); + P.Add(P, Q); + } + MulVec(ref Q, xVec, yVec); + assert("mulVecG2", P.Equals(Q)); + } } static void TestPairing() {