Merge branch 'dev'

update-fork
MITSUNARI Shigeo 4 years ago
commit c76f208703
  1. 53
      ffi/cs/mcl/mcl.cs
  2. 8
      ffi/cs/test/test.cs

@ -312,10 +312,9 @@ namespace mcl {
private U128 v0, v1; private U128 v0, v1;
public static Fr One() public static Fr One()
{ {
var fr = new Fr(); var x = new Fr();
fr.SetInt(1); x.SetInt(1);
return x;
return fr;
} }
public static Fr Zero() => new Fr(); public static Fr Zero() => new Fr();
public void Clear() public void Clear()
@ -462,9 +461,9 @@ namespace mcl {
private U128 v0, v1, v2; private U128 v0, v1, v2;
public static Fp One() public static Fp One()
{ {
var fp = new Fp(); var x = new Fp();
fp.SetInt(1); x.SetInt(1);
return fp; return x;
} }
public static Fp Zero() => new Fp(); public static Fp Zero() => new Fp();
public void Clear() public void Clear()
@ -606,11 +605,16 @@ namespace mcl {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct G1 { public struct G1 {
public Fp x, y, z; public Fp x, y, z;
public static G1 Zero()
{
var g1 = new G1();
return g1;
}
public void Clear() public void Clear()
{ {
mclBnG1_clear(ref this); mclBnG1_clear(ref this);
} }
public void SetStr(String s, int ioMode) public void SetStr(string s, int ioMode)
{ {
if (mclBnG1_setStr(ref this, s, s.Length, ioMode) != 0) { if (mclBnG1_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mclBnG1_setStr:" + s); throw new ArgumentException("mclBnG1_setStr:" + s);
@ -711,11 +715,16 @@ namespace mcl {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct G2 { public struct G2 {
public Fp2 x, y, z; public Fp2 x, y, z;
public static G2 Zero()
{
var g2 = new G2();
return g2;
}
public void Clear() public void Clear()
{ {
mclBnG2_clear(ref this); mclBnG2_clear(ref this);
} }
public void SetStr(String s, int ioMode) public void SetStr(string s, int ioMode)
{ {
if (mclBnG2_setStr(ref this, s, s.Length, ioMode) != 0) { if (mclBnG2_setStr(ref this, s, s.Length, ioMode) != 0) {
throw new ArgumentException("mclBnG2_setStr:" + s); throw new ArgumentException("mclBnG2_setStr:" + s);
@ -788,6 +797,30 @@ namespace mcl {
{ {
MCL.Mul(ref this, x, y); MCL.Mul(ref this, x, y);
} }
public static G2 operator -(in G2 x)
{
var result = new G2();
result.Neg(x);
return result;
}
public static G2 operator +(in G2 x, in G2 y)
{
var z = new G2();
z.Add(x, y);
return z;
}
public static G2 operator -(in G2 x, in G2 y)
{
var z = new G2();
z.Sub(x, y);
return z;
}
public static G2 operator *(in G2 x, in Fr y)
{
var z = new G2();
z.Mul(x, y);
return z;
}
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct GT { public struct GT {
@ -816,7 +849,7 @@ namespace mcl {
} }
public string GetStr(int ioMode) public string GetStr(int ioMode)
{ {
StringBuilder sb = new StringBuilder(1024); StringBuilder sb = new StringBuilder(2048);
long size = mclBnGT_getStr(sb, sb.Capacity, this, ioMode); long size = mclBnGT_getStr(sb, sb.Capacity, this, ioMode);
if (size == 0) { if (size == 0) {
throw new InvalidOperationException("mclBnGT_getStr:"); throw new InvalidOperationException("mclBnGT_getStr:");

@ -47,6 +47,7 @@ namespace mcl {
{ {
Console.WriteLine("TestFr"); Console.WriteLine("TestFr");
Fr x = new Fr(); Fr x = new Fr();
assert("x.isZero", x.IsZero());
x.Clear(); x.Clear();
assert("0", x.GetStr(10) == "0"); assert("0", x.GetStr(10) == "0");
assert("0.IzZero", x.IsZero()); assert("0.IzZero", x.IsZero());
@ -92,6 +93,7 @@ namespace mcl {
{ {
Console.WriteLine("TestFp"); Console.WriteLine("TestFp");
Fp x = new Fp(); Fp x = new Fp();
assert("x.isZero", x.IsZero());
x.Clear(); x.Clear();
assert("0", x.GetStr(10) == "0"); assert("0", x.GetStr(10) == "0");
assert("0.IzZero", x.IsZero()); assert("0.IzZero", x.IsZero());
@ -137,6 +139,7 @@ namespace mcl {
{ {
Console.WriteLine("TestG1"); Console.WriteLine("TestG1");
G1 P = new G1(); G1 P = new G1();
assert("P.isZero", P.IsZero());
P.Clear(); P.Clear();
assert("P.IsValid", P.IsValid()); assert("P.IsValid", P.IsValid());
assert("P.IsZero", P.IsZero()); assert("P.IsZero", P.IsZero());
@ -178,11 +181,14 @@ namespace mcl {
MulVec(ref Q, xVec, yVec); MulVec(ref Q, xVec, yVec);
assert("mulVecG1", P.Equals(Q)); assert("mulVecG1", P.Equals(Q));
} }
G1 W = G1.Zero();
assert("W.IsZero", W.IsZero());
} }
static void TestG2() static void TestG2()
{ {
Console.WriteLine("TestG2"); Console.WriteLine("TestG2");
G2 P = new G2(); G2 P = new G2();
assert("P.isZero", P.IsZero());
P.Clear(); P.Clear();
assert("P is valid", P.IsValid()); assert("P is valid", P.IsValid());
assert("P is zero", P.IsZero()); assert("P is zero", P.IsZero());
@ -224,6 +230,8 @@ namespace mcl {
MulVec(ref Q, xVec, yVec); MulVec(ref Q, xVec, yVec);
assert("mulVecG2", P.Equals(Q)); assert("mulVecG2", P.Equals(Q));
} }
G2 W = G2.Zero();
assert("W.IsZero", W.IsZero());
} }
static void TestPairing() static void TestPairing()
{ {

Loading…
Cancel
Save