[cs] add MulVec for G2

update-fork
MITSUNARI Shigeo 4 years ago
parent 9ee82069bf
commit 67cea40560
  1. 9
      ffi/cs/mcl/mcl.cs
  2. 14
      ffi/cs/test/test.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);

@ -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()
{

Loading…
Cancel
Save