diff --git a/ffi/cs/mcl/mcl.cs b/ffi/cs/mcl/mcl.cs index 133186d..24fc55d 100644 --- a/ffi/cs/mcl/mcl.cs +++ b/ffi/cs/mcl/mcl.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using System.Runtime.InteropServices; @@ -73,7 +73,7 @@ namespace mcl { [DllImport(dllName)] public static extern void mclBnG1_add(ref G1 z, in G1 x, in G1 y); [DllImport(dllName)] public static extern void mclBnG1_sub(ref G1 z, in G1 x, in G1 y); [DllImport(dllName)] public static extern void mclBnG1_mul(ref G1 z, in G1 x, in Fr y); - [DllImport(dllName)] public static extern void mclBnG1_mulVec(ref G1 x, [In]G1[] vec1, [In]Fr[] vec2, long bufSize); + [DllImport(dllName)] public static extern void mclBnG1_mulVec(ref G1 z, [In]G1[] x, [In]Fr[] y, long n); [DllImport(dllName)] public static extern void mclBnG2_clear(ref G2 x); [DllImport(dllName)] public static extern int mclBnG2_setStr(ref G2 x, [In][MarshalAs(UnmanagedType.LPStr)] string buf, long bufSize, int ioMode); @@ -217,6 +217,14 @@ namespace mcl { { mclBnG1_normalize(ref y, x); } + public static void MulVec(ref G1 z, in G1[] x, in Fr[] y) + { + int n = x.Length; + if (n <= 0 || n != y.Length) { + throw new ArgumentException("bad length"); + } + mclBnG1_mulVec(ref z, x, y, (long)n); + } public static void Add(ref G2 z, in G2 x, in G2 y) { mclBnG2_add(ref z, x, y); diff --git a/ffi/cs/test/test.cs b/ffi/cs/test/test.cs index c9393e3..2972cc8 100644 --- a/ffi/cs/test/test.cs +++ b/ffi/cs/test/test.cs @@ -164,6 +164,20 @@ namespace mcl { Q.Deserialize(buf); assert("P == Q", P.Equals(Q)); } + { + const int n = 5; + G1[] xVec = new G1[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("mulVecG1", P.Equals(Q)); + } } static void TestG2() {